函数edge():查找强度图像的边缘
常用函数说明:
BW = edge(I)
返回二值图像 BW
,其中的值 1
对应于输入图像 I
中函数找到边缘的位置,值 0
对应于其他位置。默认情况下,edge
使用 Sobel 边缘检测方法。
BW = edge(I,method)
使用 method
指定的边缘检测算法检测图像 I
中的边缘。
BW = edge(I,method,threshold)
返回强度高于 threshold
的所有边缘。
BW = edge(I,method,threshold,direction)
指定要检测的边缘的方向。Sobel 和 Prewitt 方法可以检测垂直方向和/或水平方向的边缘。Roberts 方法可以检测与水平方向成 45 度角和/或 135 度角的边缘。仅当 method
是 'Sobel'
、'Prewitt'
或 'Roberts'
时,此语法才有效。
边缘检测所涉及的method如下:
学习后变成实现的小练习:
clear all
clc
I=imread('cameraman.tif');
figure(1)
subplot(1,2,1)
imshow(I);
title('原始图像');
BW=edge(I,'sobel');
subplot(1,2,2)
imshow(BW);
title('边缘检测')
[BW,thresh]=edge(I,'sobel');
disp('Sobel算法自动选择的阈值为:')
disp(thresh);
figure(2)
BW1=edge(I,'sobel',0.02,'horizontal');
subplot(2,2,1)
imshow(BW1);
title('水平方向阈值为0.02')
BW2=edge(I,'sobel',0.02,'vertical');
subplot(2,2,2)
imshow(BW2)
title('垂直方向阈值为0.02')
BW3=edge(I,'sobel',0.05,'horizontal');
subplot(2,2,3)
imshow(BW3)
title('水平方向阈值为0.05')
BW4=edge(I,'sobel',0.05,'vertical');
subplot(2,2,4)
imshow(BW4)
title('垂直方向阈值为0.05')
效果图如下: