# imedge
查找二维灰度图像中的边缘
函数库: TyImages
# 语法
BW = imedge(I)
BW = imedge(I,method)
BW = imedge(I,method; kwargs...)
# 说明
BW = imedge(I) 返回二值图像 BW,其中的值 1 对应于灰度或二值图像 I 中函数找到边缘的位置,值 0 对应于其他位置。 默认情况下,imedge 使用 Sobel 边缘检测方法。 目前支持的方法有 "Sobel"、"Prewitt"、"Roberts" 和 "Canny"。
BW = imedge(I,method) 使用 method 指定的边缘检测算法检测图像 I 中的边缘。
BW = imedge(I,method; kwargs...) kwargs为关键字参数,支持的关键字参数有:
- thinning:是否对边缘进行细化。默认为 true;
- direction:检测边缘的方向,可选值为
:both、:horizontal、:vertical,默认为:both; - thresh:边缘检测的阈值,如果不填,则根据图像的平均梯度自动计算阈值; 若为 canny 方法,则为两个阈值的数组,第一个为低阈值,第二个为高阈值。
- sigma:高斯滤波的标准差,仅对 canny 方法有效。默认为 sqrt(2)。
# 示例
比较使用 Canny 和 Prewitt 方法的边缘检测结果
将图像读入工作区并显示它。
using TyImages
pkg_dir = pkgdir(TyImages)
source_path = pkg_dir * "/examples/resources/brick_wall_he_512.tiff"
I = imread(source_path);
imshow(I)
使用 Canny 方法检测图像中的边缘。
BW1 = imedge(I, "Canny");
imshow(BW1)
使用 Prewitt 方法查找边缘。
BW2 = imedge(I, "Prewitt", thresh=0.6);
imshow(BW2)

# 输入参数
I - 图像数组
灰度或二值图像。
method - 边缘检测算法字符串
method 为使用指定的边缘检测方法检测图像的边缘。目前支持的方法有 "Sobel"、"Prewitt"、"Roberts" 和 "Canny"。
默认情况下,imedge 使用 Sobel 边缘检测方法。
# 名称-值对组参数
指定可选的、以逗号分隔的 Key=Value 对组参数。Key 为参数名称,Value 为对应的值。您可采用任意顺序指定多个名称-值对组参数,如 Key1=Value1,...,KeyN=ValueN 所示。
thinning - 是否对边缘进行细化true
是否对边缘进行细化。 默认为 true。
direction - 检测边缘的方向:both
检测边缘的方向,可选值为 :both、:horizontal、:vertical,默认为 :both。
thresh - 边缘检测的阈值
边缘检测的阈值,如果不填,则根据图像的平均梯度自动计算阈值。
若为 canny 方法,则为两个阈值的数组,第一个为低阈值,第二个为高阈值。
thresh - 边缘检测的阈值sqrt(2)
高斯滤波的标准差,仅对 canny 方法有效。 默认为 sqrt(2)。