function [cornor] = cornerDetect( filename)
% cornerDetect solves the problem of detect corner
% filename--the name of the file you want to detect, for
% example img
% K,t--parameters
K=0.06;
t=0.02;
img=im2double(filename);
m=size(img,1);
n=size(img,2);
[Ix Iy]=gradient(img);
cornor=zeros(m,n);
tmep=zeros(2,2);
for i=2:m-1
for j=2:n-1
temp(1,1)=Ix(i-1,j-1)^2+Ix(i-1,j)^2+Ix(i-1,j+1)^2+Ix(i,j-1)^2+Ix(i,j)^2+Ix(i,j+1)^2+Ix(i+1,j-1)^2+Ix(i+1,j)^2+Ix(i+1,j+1)^2;
temp(1,2)=Ix(i-1,j-1)*Iy(i-1,j-1)+Ix(i-1,j)*Iy(i-1,j)+Ix(i-1,j+1)*Iy(i-1,j+1)+Ix(i,j-1)*Iy(i,j-1)+Ix(i,j)*Iy(i,j)+Ix(i,j+1)*Iy(i,j+1)+Ix(i+1,j-1)*Iy(i+1,j-1)+Ix(i+1,j)*Iy(i+1,j)+Ix(i+1,j+1)*Iy(i+1,j+1);
tmep(2,1)=temp(1,2);
temp(2,2)=Iy(i-1,j-1)^2+Iy(i-1,j)^2+Iy(i-1,j+1)^2+Iy(i,j-1)^2+Iy(i,j)^2+Iy(i,j+1)^2+Iy(i+1,j-1)^2+Iy(i+1,j)^2+Iy(i+1,j+1)^2;
s=svd(temp);
if s(1)*s(2)-K*(sum(s)^2)>t
cornor(i,j)=1;
end
end
end
end
评论0