且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

在matlab中查找图像中2D对象的轮廓

更新时间:2023-02-26 14:36:37

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



最终它的作用是对原始图像执行卷积以侵蚀它,然后计算侵蚀版本和原始版本之间的差异。因此,如果您没有工具箱,则可以使用 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;