在网上看到一段代码,贴了下来,怎么都不出图,是代码有问题还是怎么的,求大神!Harris角点检测程序如下:
clear;clc;close all;
filename='28107342.jpg';
X=imread(filename);
X=rgb2gray(X);
%X=double(X);
Info=imfinfo(filename);
% if Info.BitDepth>8
% f=rgb2gray(X);
f=X;
%end
% fx = [5 0 -5;8 0 -8;5 0 -5];
ori_im=double(f)/255;
fx = [-2 -1 0 1 2];
Ix = filter2(fx,ori_im);
% fy = [5 8 5;0 0 0;-5 -8 -5];
fy = [-2;-1;0;1;2];
Iy = filter2(fy,ori_im);
Ix2 = Ix.^2;
Iy2 = Iy.^2;
Ixy = Ix.*Iy;
clear Ix;
clear Iy;
h= fspecial('gaussian',[7 7],2);
Ix2 = filter2(h,Ix2);
Iy2 = filter2(h,Iy2);
Ixy = filter2(h,Ixy);
height = size(ori_im,1);
width = size(ori_im,2);
result = zeros(height,width);
R = zeros(height,width);
Rmax = 0;
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)-0.06*(trace(M))^2;
if R(i,j) > Rmax
Rmax = R(i,j);
end;
end;
end;
cnt = 0;
for i = 2:height-1
for j = 2:width-1
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;
i=1;
for j=1:height
for k=1:width
if result(j,k)==1;
corners1(i,1)=j;
corners1(i,2)=k;
i=i+1;
end;
end;
end;
[posc, posr] = find(result == 1);
cnt
imshow(ori_im)
hold on;
plot(posr,posc,'r+');
clear;clc;close all;
filename='28107342.jpg';
X=imread(filename);
X=rgb2gray(X);
%X=double(X);
Info=imfinfo(filename);
% if Info.BitDepth>8
% f=rgb2gray(X);
f=X;
%end
% fx = [5 0 -5;8 0 -8;5 0 -5];
ori_im=double(f)/255;
fx = [-2 -1 0 1 2];
Ix = filter2(fx,ori_im);
% fy = [5 8 5;0 0 0;-5 -8 -5];
fy = [-2;-1;0;1;2];
Iy = filter2(fy,ori_im);
Ix2 = Ix.^2;
Iy2 = Iy.^2;
Ixy = Ix.*Iy;
clear Ix;
clear Iy;
h= fspecial('gaussian',[7 7],2);
Ix2 = filter2(h,Ix2);
Iy2 = filter2(h,Iy2);
Ixy = filter2(h,Ixy);
height = size(ori_im,1);
width = size(ori_im,2);
result = zeros(height,width);
R = zeros(height,width);
Rmax = 0;
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)-0.06*(trace(M))^2;
if R(i,j) > Rmax
Rmax = R(i,j);
end;
end;
end;
cnt = 0;
for i = 2:height-1
for j = 2:width-1
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;
i=1;
for j=1:height
for k=1:width
if result(j,k)==1;
corners1(i,1)=j;
corners1(i,2)=k;
i=i+1;
end;
end;
end;
[posc, posr] = find(result == 1);
cnt
imshow(ori_im)
hold on;
plot(posr,posc,'r+');