harris.m
来自「这是<<Matlab在图像处理中的应用>>这本书的源码」· M 代码 · 共 28 行
M
28 行
%程序13-1
function [cornerness, r, c] = harris(im, sigma, thresh, radius, disp)
% cornerness = Corner values
% r = rows (x coordinate of feature point)
% c = columns (y coordinate of feature points)
im=double(im);
% Derivative masks
dy = [-1 0 1; -1 0 1; -1 0 1];
dx = dy'; %dx is the transpose matrix of dy
% Ix and Iy are the horizontal and vertical edges of image
Ix = double(conv2(im, dx, 'same'));
Iy = conv2(im, dy, 'same');
% Calculating the gradient of the image Ix and Iy
g = fspecial('gaussian',max(1,fix(6*sigma)), sigma);
Ix2 = conv2(Ix.^2, g, 'same'); % Smoothed squared image derivatives
Iy2 = conv2(Iy.^2, g, 'same');
Ixy = conv2(Ix.*Iy, g, 'same');
cornerness = (Ix2.*Iy2 - Ixy.^2)./(Ix2 + Iy2 + eps);
% We should perform nonmaximal suppression and threshold
if nargin > 2
sze = 2*radius+1; % Size of mask
mx = ordfilt2(cornerness,sze^2,ones(sze)); % Grey-scale dilate
cornerness = (cornerness==mx)&(cornerness>thresh); % Find maxima
[r,c] = find(cornerness); % Find row,col coords.
else
r = []; c = [];
end
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?