SUSAN角点检测算子的MATLAB实现
[filename,pathname,~]=uigetfile('*.jpg','选择JPG格式图片');
if ~ischar(filename) return end
str=[pathname filename]; pic=imread(str);
if length(size(pic))==3 img=rgb2gray(pic); end
[M,N]=size(img);
timg=zeros(M+6,N+6);
timg(4:end-3,4:end-3)=img; %扩展图像边缘3个像素 img=timg; t=45; %阈值
USAN=[]; %用于存放USAN for i= 4:M+3 for j=4:N+3
tmp=img(i-3:i+3,j-3:j+3); cnt=0; %计数专用,统计圆形邻域内满足条件的像素点个数 for p=1:7
for q=1:7 if
(p-4)^2+(q-4)^2<=12 %半径一般在3~4之间
if abs(img(i,j)-tmp(p,q))end endend end
USAN=[USAN cnt]; end end
g=max(USAN)/2; %给定的阈值
for k=1:length(USAN) if USAN(k)USAN(k)=g-USAN(k); %反向相减,使得USAN取局部最大 elseUSAN(k)=0; end end
imgn=reshape(USAN,M,N); %USAN向量张成二维图像
imgn=fliplr(imrotate(imgn,-90)); %调整图像
loc=[];
for i=2:M-1 for j=2:N-1
sq=imgn(i-1:i+1,j-1:j+1); sq=reshape(sq,1,9); sq=[sq(1:4),sq(6:9)]; if
imgn(i,j)>sq %局部非极大值抑制
loc=[loc;[j,i]];
end end end
imshowpair(pic,pic,'montage');
运行结果图如下:
hold on
plot(loc(:,1)+size(pic,2),loc(:,2),'*'); hold off