📄 harris1.m
字号:
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% la methode d'Harris à détecter le point d'interet (1) %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
clc;
close all;
clear all;
ori_im1=rgb2gray(imread('sanstitre.bmp'));
% ori_im1=imread('image26.bmp');
% ori_im1=imresize(ori_im1',0.70,'bicubic');
% fx = [5 0 -5;8 0 -8;5 0 -5]; % la gaussienne,ver axe x
% fx = [-2 -1 0 1 2];
% fx = [-1 0 1;-2 0 2;-1 0 1]; % le Sobel vers axe x
fx = [1 0;0 -1]; % le Roberts vers x
Ix = filter2(fx,ori_im1); % la convolution vers axe x
% fy = [5 8 5;0 0 0;-5 -8 -5]; % la gaussienne,ver axe y
% fy = [-2;-1;0;1;2];
% fy = [-1 2 1;0 0 0;-1 -2 1]; % le Sobel vers axe y
fy = [0 1;-1 0]; % le Roberts vers y
Iy = filter2(fy,ori_im1); % la convolution vers axe y
Ix2 = Ix.^2;
Iy2 = Iy.^2;
Ixy = Ix.*Iy;
clear Ix;
clear Iy;
h = fspecial('gaussian',[7 7],2); % générer une fonction gaussienne,sigma=2
Ix2 = filter2(h,Ix2);
Iy2 = filter2(h,Iy2);
Ixy = filter2(h,Ixy);
height = size(ori_im1,1);
width = size(ori_im1,2);
result = zeros(height,width); % enregistrer la position du coin
R = zeros(height,width);
K=0.04
Rmax = 0; % chercher la valeur maximale de R
for i = 1:height
for j = 1:width
M = [Ix2(i,j) Ixy(i,j);Ixy(i,j) Iy2(i,j)];
R(i,j) = det(M)-K*(trace(M))^2; % calcule R
if R(i,j) > Rmax
Rmax = R(i,j);
end;
end;
end;
cnt=0;
for i = 2:height-1
for j = 2:width-1
% réduire des valuers minimales ,la taille de fenetre 3*3
if R(i,j) > 0.01*Rmax && R(i,j) > R(i-1,j-1) && R(i,j) > R(i-1,j) && R(i,j) > R(i-1,j+1) && R(i,j) > R(i,j-1) && R(i,j) > R(i,j+1) && R(i,j) > R(i+1,j-1) && R(i,j) > R(i+1,j) && R(i,j) > R(i+1,j+1)
result(i,j) = 1;
cnt=cnt+1;
end;
end;
end;
[posr1,posc1] = find(result == 1);
% p=size(posr1,1);
%
%
% im_R=rgb2gray(imread('reference.bmp')); %le programme du masque
% im_R=imresize(im_R',0.70,'bicubic');
%
% nombre1=0;
% result=zeros(nombre1,nombre1);
% for m=1:p
% if im_R(posr1(m),posc1(m))==255
% result(posr1(m),posc1(m))=255;
% nombre1=nombre1+1;
% end
% end
%
% [posr1,posc1] = find(result==255);
% cnt
% nombre1
figure
imshow(ori_im1);
hold on;
plot(posc1,posr1,'r+');
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -