%%%Prewitt Operator Corner Detection.m
%%%时间优化--相邻像素用取差的方法
%%
clear;
for nfigure=1:6
switch nfigure %选择图片
case 1
t='z1.jpg';
case 2
t='z2.jpg';
case 3
t='z3.jpg';
case 4
t='z4.jpg';
case 5
t='z5.jpg';
case 6
t='z6.jpg';
end
% 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);