Matlab 中的边界和轮廓
我有一个二值图像,其上有 1 像素宽度的非闭合曲线。我想将这条曲线作为点列表(按正确的顺序)。我发现 bwboundaries
函数尝试包装所有非零像素,因此在这种情况下返回重复点:
>> A = [0 0 0; 1 1 1; 0 0 0];
>> b = bwboundaries(A)
ans =
[5x2 double]
>> b{1}
ans =
2 1
2 2
2 3
2 2
2 1
bwtraceboundary
做同样的事情
>> bwtraceboundary(A, [2 1], 'E')
ans =
2 1
2 2
2 3
2 2
2 1
是否有任何标准方法来获取像 [ 2 1; 2 2; 2 3] 立即?
I have a binary image with non closed curves of 1-pixel width on it. I want to grab this curves as a list of points (in proper order). I found bwboundaries
function which tries to wrap all non-zero pixels and thus in this case returns duplicate points:
>> A = [0 0 0; 1 1 1; 0 0 0];
>> b = bwboundaries(A)
ans =
[5x2 double]
>> b{1}
ans =
2 1
2 2
2 3
2 2
2 1
bwtraceboundary
do the same
>> bwtraceboundary(A, [2 1], 'E')
ans =
2 1
2 2
2 3
2 2
2 1
Is there any standard method to get matrix like [2 1; 2 2; 2 3] immediately?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
它会产生双条目,因为您的区域只有一个像素宽。我认为没有一个标准方法可以直接处理您的特殊问题。但是,您可以简单地使用 unique() 函数来消除重复条目结果。
要保持点的原始顺序,只需执行以下操作:
It produces double entries because your region is only one pixel wide. I don't think there's a standard method that handles your special problem directly. However, you can simply use the unique() function to eliminate double entries of the result.
To keep the original order of the points, just do: