我已经实现了Harris特征检测算法,并且与使用Matlab的内置函数相比,结果不准确:corner(I,' Harris')。任何想法为什么这样?或者我错过了什么?
我的代码结果:
im=imread('D:\lena_256.pgm');
im=im2double(im);
% im = double(im(:,:,1));
sigma = 2;k = 0.04;
% derivative masks
s_D = 0.7*sigma;
x = -round(3*s_D):round(3*s_D);
dx = x .* exp(-x.*x/(2*s_D*s_D)) ./ (s_D*s_D*s_D*sqrt(2*pi));
dy = dx';
% image derivatives
Ix = conv2(im, dx, 'same');
Iy = conv2(im, dy, 'same');
% sum of the Auto-correlation matrix
s_I = sigma;
g = fspecial('gaussian',max(1,fix(6*s_I+1)), s_I);
Ix2 = conv2(Ix.^2, g, 'same'); % Smoothed squared image derivatives
Iy2 = conv2(Iy.^2, g, 'same');
Ixy = conv2(Ix.*Iy, g, 'same');
% interest point response
cim = (Ix2.*Iy2 - Ixy.^2) - k*(Ix2 + Iy2).^2; % Original Harris measure.
%cim=(Ix2.*Iy2 - Ixy.^2)./(Ix2 + Iy2); % harmonic mean
% find local maxima on 3x3 neighborgood
[r,c,max_local] = findLocalMaximum(cim,3*s_I);
% set threshold 1% of the maximum value
t = 0.005*max(max_local(:));
% find local maxima greater than threshold
[r,c] = find(max_local>=t);
% build interest points
points = [r,c];
figure, imshow(im),title('Harris Feature Points');
hold on
plot(points(:,1),points(:,2),'r*');
function [row,col,max_local] = findLocalMaximum(val,radius)
mask = fspecial('disk',radius)>0;
val2 = imdilate(val,mask);
index = val==val2;
[row,col] = find(index==1);
max_local = zeros(size(val));
max_local(index) = val(index);
end
使用内置corner()函数的结果: