Harris
角点检测代码
%%%Prewitt Operator Corner Detection.m
%%%
时间优化
--
相邻像素用取差的方法
%%
clear;
for nfigure=1:6
t=input('input your figure’s name(including its extern name):','s');
% t1 = tic;
%
测算时间
FileInfo = imfinfo(t);
%
保存图像的所有信息
Image = imread(t);
%
读取图像
%
转为灰度值图像
(Intensity Image)
if(strcmp('truecolor',FileInfo.ColorType) == 1) %
转为灰度值图像
Image = im2uint8(rgb2gray(Image));
end
dx = [-1 0 1;-1 0 1;-1 0 1];
%dx
:横向
Prewitt
差分模版
Ix2 = filter2(dx,Image).^2;
Iy2 = filter2(dx',Image).^2;
Ixy = filter2(dx,Image).*filter2(dx',Image);
%
生成
9*9
高斯窗口。窗口越大,探测到的角点越少。
h= fspecial('gaussian',9,2);
A = filter2(h,Ix2);
%
用高斯窗口差分
Ix2
得到
A
B = filter2(h,Iy2);
C = filter2(h,Ixy);
nrow = size(Image,1);
ncol = size(Image,2);
Corner = zeros(nrow,ncol); %
矩阵
Corner
用来保存候选角点位置
,
初值全零,
值为
1
的点是
角点
%
真正的角点在
137
和
138
行由
(row_ave,column_ave)
得到
%
参数
t:
点
(i,j)
八邻域的
“
相似度
”
参数,只有中心点与邻域其他八个点的像素值之差在
%
(
-t,+t
)之间,才确认它们为相似点,相似点不在候选角点之列