1. 程式人生 > >Sobel運算元實現水平邊緣檢測 垂直邊緣檢測 45度 135度角邊緣檢測

Sobel運算元實現水平邊緣檢測 垂直邊緣檢測 45度 135度角邊緣檢測

               
%File Discription:%45°和135°角邊緣檢測;用於那些邊界不明顯的圖片%不太適用於複雜圖,複雜圖用水平和垂直邊緣檢測%Author:Zhang Ruiqing%CreateTime:2011.8.8(What a good day!(*^__^*) )SourcePic=imread('D:\Images\pic_loc\1870378220205041520.jpg');subplot(221);imshow(SourcePic),title('原圖');grayPic=rgb2gray(SourcePic);grayPic=im2double(grayPic);%使用指定45度角Sobel運算元濾波器,指定閡值a45=[-2 -1 0;-1 0 1;0 1 2];SFST45=imfilter(grayPic,a45,'replicate');%功能:對任意型別陣列或多維影象進行濾波。SFST45=SFST45>=Threshold;subplot(222);imshow(SFST45),title('45度角影象邊緣檢測') ;b45=[0 -1 -2;1 0 -1;2 1 0];SFST45=imfilter(grayPic,b45,'replicate');%功能:對任意型別陣列或多維影象進行濾波。SFST45=SFST45>=Threshold;SFST45subplot(223);imshow(SFST45),title('135度角影象邊緣檢測') ;

%File Discription:%水平、垂直邊緣檢測;%Author:Zhang Ruiqing%CreateTime:2011.8.8SourcePic=imread('D:\畢業設計\Images\pic_loc\1870399350205061354.jpg');subplot(221);imshow(SourcePic),title('原圖');grayPic=rgb2gray(SourcePic);grayPic=im2double(grayPic);[Vertical Threshold]=edge(grayPic,'sobel','vertical');%edge detectsubplot(222);imshow(Vertical),title('垂直方向邊緣檢測');[Horizontal Threshold]=edge(grayPic,'sobel','horizontal');%edge detectsubplot(223);imshow(Horizontal),title('水平方向邊緣檢測');H_V=edge(grayPic,'sobel',Threshold);subplot(224);imshow(H_V),title('水平和垂直邊緣檢測');