Shi-Tomasi算子的运用 ,用于检测角点
生活随笔
收集整理的這篇文章主要介紹了
Shi-Tomasi算子的运用 ,用于检测角点
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
角點檢測
當一個窗口在圖像上移動,在平滑區域如圖(a),窗口在各個方向上沒有變化。在邊緣上如圖(b),窗口在邊緣的方向上沒有變化。在角點處如圖(c),窗口在各個方向上具有變化。Harris角點檢測正是利用了這個直觀的物理現象,通過窗口在各個方向上的變化程度,決定是否為角點。
將圖像窗口平移[u,v]產生灰度變化E(u,v)
由:, 得到:
對于局部微小的移動量 [u,v],近似表達為:
其中M是 2*2 矩陣,可由圖像的導數求得:
E(u,v)的橢圓形式如下圖:
?
定義角點響應函數?R?為:
Harris角點檢測算法就是對角點響應函數R進行閾值處理:R > threshold,即提取R的局部極大值。
?
Shi--Tomasi角點檢測法,如果像素點的最小特征值大于周圍像素的特征值,則該點是角點。
代碼:
<span style="font-size:18px;"><strong>im=imread('lena.jpg'); tau=100; im=double(im); keyXs=[]; keyYs=[]; win=3; [height,width] = size(im); result = zeros(height,width); %Then I will get the gradients of the image along the x and y axises. sobel_x=1/4*[-1 0 1;-2 0 2;-1 0 1]; sobel_y=1/4*[-1 0 1;-2 0 2;-1 0 1]'; diffx=imfilter(im,sobel_x); %對圖像x方向進行梯度 diffy=imfilter(im,sobel_y); %對圖像y方向的梯度進行計算 %For smoothing the differentiation of the image along the x and y %direction, the gauss filter of the diffx and diffy is must. gauss_win=win; sigma=1; [x,y]=meshgrid(-gauss_win:gauss_win,-gauss_win:gauss_win); gauss2D=exp(-(x.^2+y.^2)/(2*sigma.^2)); %產生高斯算子 gauss2D=gauss2D/(sum(sum(gauss2D))); %對高斯算子進行歸一化 %Then calculate the M matrix. A=imfilter(diffx.*diffx,gauss2D); %二階x方向梯度進行高斯濾波 B=imfilter(diffy.*diffy,gauss2D); %二階y方向梯度進行高斯濾波 C=imfilter(diffx.*diffy,gauss2D); %對圖像x y方向的梯度進行高斯濾波 supress_win=2;threshold=100;points_count=0;bigger=zeros(height,width);smaller=zeros(height,width);for x=1:widthfor y=1:heightM=[A(y,x) C(y,x);C(y,x) B(y,x)];%It is too time-consuming.%eigenvalue=eig(M);%bigger(y,x)=max(eigenvalue);%smaller(y,x)=min(eigenvalue);temp1=M(1,1)+M(2,2);temp2=sqrt((M(1,1)-M(2,2))^2+4*M(1,2)^2);bigger(y,x)=(temp1+temp2)/2;smaller(y,x)=(temp1-temp2)/2;endendfor x=supress_win+1:width-supress_winfor y=supress_win+1:height-supress_win temp=smaller(y,x);if(temp>threshold)%Then I will make the non-maximumu suppression to the%samller matrix after the threholding.flag=0;for i=-supress_win:supress_winfor j=-supress_win:supress_winif(temp>=smaller(y+j,x+i))flag=flag+1;endendendif(flag==((2*supress_win+1)*(2*supress_win+1)))result(y,x)=1;points_count=points_count+1;keyXs(points_count)=x;keyYs(points_count)=y;endendendend end </strong></span>
總結
以上是生活随笔為你收集整理的Shi-Tomasi算子的运用 ,用于检测角点的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Harris算子的运用 用于图像配准
- 下一篇: 最小二乘问题