在matlab中查找图像中2D对象的轮廓 [英] Find contour of 2D object in image in matlab

查看:153
本文介绍了在matlab中查找图像中2D对象的轮廓的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这个问题:我有这个2D二进制图像,我想在这个图像中提取对象的轮廓。
这是图像:



我希望拥有相同的矩阵图像但是只有在对象的轮廓和其他地方的零。
有解决方案吗?
如果是这样,是否有任何实现对3D对象也做同样的事情?



非常感谢

解决方案

如果您有图像处理工具箱,可以使用



最终它的作用是对原始图像执行卷积以侵蚀它,然后计算侵蚀版本和原始版本之间的差异。因此,如果您没有工具箱,则可以使用 conv2 (或3D中的 convn )执行此操作。

  eroded = ~conv2(double(~BW),ones(3),'same'); 
boundary = BW - 侵蚀;

或3D模式:

  eroded =〜convn(double(~BW_3D),ones(3,3,3),'same'); 
boundary = BW_3D - 被侵蚀;


I have this problem: I have this 2D binary image and I want to extract the contour of the object in this image. This is the image:

I want to have the same matrix image but with ones only in the contour of the object and zeros elsewhere. Is there a solution? If so, is there any implementation to do the same thing also for a 3D object?

Thank you very much

解决方案

If you have the Image Processing Toolbox you can use bwperim

BW = imread('http://i.stack.imgur.com/05T06.png');
BW = BW(:,:,1) == 255;

boundary = bwperim(BW);

imshow(boundary)

Ultimately what this does, is performs a convolution on the original image to erode it and then computes the difference between the eroded version and the original version. So if you don't have the toolbox you can do this with conv2 (or convn in 3D).

eroded = ~conv2(double(~BW), ones(3), 'same');
boundary = BW - eroded;

Or in 3D:

eroded = ~convn(double(~BW_3D), ones(3,3,3), 'same');
boundary = BW_3D - eroded;

这篇关于在matlab中查找图像中2D对象的轮廓的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆