matlab边缘检测

来源:互联网 发布:软件的外部接口 编辑:程序博客网 时间:2024/06/02 19:13
f=imread('0.jpg');                           % 读入图像
f=rgb2gray(f);                                     % 将彩色图像转换为灰度图像
f=im2double(f);                                    % 转换为双精度,便于后面的计算
PE=edge(f,'sobel','horizontal');%sobel水平
figure, imshow(PE),title('sobel Image'),
figure, imshow(f),title('Original Image'),               
PF=edge(f,'prewitt');                               % 边缘探测,算子为prewitt
figure,imshow(PF),title('Prewitt Filter');               
RF=edge(f,'roberts');                              % 边缘探测,算子为roberts
figure,imshow(RF),title('Roberts Filter');              
LF=edge(f,'log');                                  % 边缘探测,算子为log
figure,imshow(LF),title('Laplacian of Gaussian (LoG) Filter'); 
CF=edge(f,'canny');                                 % 边缘探测,算子为canny

figure,imshow(CF),title('Canny Filter');      


MATLAB的图像处理工具箱中提供的edge函数可以实现检测边缘的功能,其语法格式如下:
BW = edge(I,'sobel')
BW = edge(I,'sobel',direction)
BW = edge(I,'roberts')
BW = edge(I,'log')
这里BW = edge(I,'sobel')采用Sobel算子进行边缘检测。BW = edge(I,'sobel',direction)可以指定算子方向,即:
direction=’horizontal’,为水平方向;
direction=’vertical’,为垂直方向;
direction=’both’,为水平和垂直两个方向。
BW = edge(I,'roberts')和BW = edge(I,'log')分别为用Roberts算子和拉普拉斯高斯算子进行边缘检测。  


        

1 0
原创粉丝点击