【图像处理】Sobel算子实现水平边缘检测、垂直边缘检测;45度、135度角边缘检测

%File Discription:
%45°和135°角边缘检测;用于那些边界不明显的图片
%不太适用于复杂图,复杂图用水平和垂直边缘检测
%Author:Zhang Ruiqing
%CreateTime:2011.8.8(What a good day!(*^__^*) )
 
SourcePic=imread('lena.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');%功能:对任意类型数组或多维图像进行滤波。
level = graythresh(SFST45);
Threshold = level;

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;
SFST45
subplot(223);
imshow(SFST45),title('135度角图像边缘检测') ;




%File Discription:
%水平、垂直边缘检测;
%Author:Zhang Ruiqing
%CreateTime:2011.8.8
 
SourcePic=imread('lena.jpg');
subplot(221);
imshow(SourcePic),title('原图');
 
grayPic=rgb2gray(SourcePic);
grayPic=im2double(grayPic);
[Vertical Threshold]=edge(grayPic,'sobel','vertical');%edge detect
subplot(222);
imshow(Vertical),title('垂直方向边缘检测');
 
[Horizontal Threshold]=edge(grayPic,'sobel','horizontal');%edge detect
subplot(223);
imshow(Horizontal),title('水平方向边缘检测');
 
H_V=edge(grayPic,'sobel',Threshold);
subplot(224);
imshow(H_V),title('水平和垂直边缘检测');




转载来源     https://blog.csdn.net/abcjennifer/article/details/6668141

猜你喜欢

转载自blog.csdn.net/hellozex/article/details/80854112
今日推荐