获取逻辑图像中区域的外部索引

时间:2013-01-13 14:49:23

标签: matlab image-processing region indices

如果我有任何m x n白色区域的逻辑图像,如下所示:

Logical image of a region

如何获取白色和黑色区域之间的边界线的索引?

2 个答案:

答案 0 :(得分:2)

这简单地归结为检测给定图像的边缘。 MATLAB已经在edge命令中具有内置实现。以下是使用Canny过滤器检测图像I边界的示例:

A = edge(I, 'canny');

结果图像A中的非零元素就是您所追求的。然后,您可以使用find获取其索引。

答案 1 :(得分:1)

由于您的输入是清晰的二进制图像,因此无需使用@EitanT建议的edge

使用形态学操作imdilateimeroderegionprops获取周界:

% let input image be bw
we = bw & ~imerode( bw, strel('disk', 1) ); % get a binary image with only the boundary pixels set
st = regionprops(we, 'PixelIdxList'); % get the linear indices of the boundary

% get a binary image with pixels on the outer side of the shape set
be = ~bw & imdilate( bw, strel('disk', 1) );
st = regionprops(be, 'PixelList'); % get the row-col indices of the boundary
相关问题