Find contour of 2D object in image in matlab

不想你离开。 提交于 2019-12-01 11:54:13

问题


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


回答1:


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;


来源:https://stackoverflow.com/questions/38788126/find-contour-of-2d-object-in-image-in-matlab

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!