


close all; clear all; I=imread('corner2.gif'); [posX,posY]=susan(I,3); figure; imshow(I);hold on; plot(posX,posY,'g*');
function [posX,posY]=susan(I,radius) %SUSAN角點檢測 %I:輸入圖像 %radius:圓形模板的半徑 %(posX,posY):角點坐標 [r,c]=size(I); mask=generatemask(radius); th1=20;%閾值越小,提取的角點越多 th2=sum(mask(:))/2;%閾值越大,提取的角點越多 R=zeros(r,c);%角點響應值 res=zeros(r,c);%是否是角點 for i=radius+1:r-radius for j=radius+1:c-radius B=I(i-radius:i+radius,j-radius:j+radius); usan=(abs(B-I(i,j))<th1).*mask;%USAN區域 N=sum(usan(:)); if(N<th2) R(i,j)=th2-N; end end end %非極大值抑制 tr=radius+2; for i=tr+1:r-tr for j=tr+1:c-tr tmp=R(i-tr:i+tr,j-tr:j+tr); tmp(tr+1,tr+1)=0; if(R(i,j)>max(tmp(:))) res(i,j)=1; end end end [posY,posX]=find(res); function mask=generatemask(radius) %生成半徑為radius的掩模 mask=zeros(2*radius+1,2*radius+1); [row,col]=size(mask); cenr=(row+1)/2; cenc=(col+1)/2; for i=1:row for j=1:col if((i-cenr)^2+(j-cenc)^2<=radius^2) mask(i,j)=1; end end end
結果:

