函数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')
效果图如下:


本文介绍了如何使用Matlab的edge函数进行强度图像边缘检测,包括Sobel算法的基本原理、不同阈值设置的应用以及实战演练。通过实例展示了如何调整方向和阈值来获取精确的边缘信息。
2462

被折叠的 条评论
为什么被折叠?



