how to draw boundary of an image

3 次查看(过去 30 天)
I want to draw a boundary for the image attached (input1). I've used the code written below. I'm getting the output as a file attached(output1). But I want to get only one boundary ( inside one). how can I get that? I just want inner boundary. don't want outer.
xt=imdilate(g2,s1); %%%dilating to get the edge region filled properly
binaryImage=xt;
boundaries = bwboundaries(binaryImage);
daries = size(boundaries, 1);
for k = 1 : numberOfBoundaries
thisBoundary = boundaries{k};
hold on;
fill(thisBoundary(:,2), thisBoundary(:,1),'w');
hold on;
plot(thisBoundary(:,2), thisBoundary(:,1), 'g', 'LineWidth', 1);
end
hold off

回答(1 个)

Arun Mathamkode
Arun Mathamkode 2018-4-20

The bwboundaries returns the possible boundaries in the input image as a cell array. Any specific boundary can be extracted by indexing the cell array. In your case boundaries{4} will return you the required inner boundary.

But if you want to perform the same task in different images, I think you can find boundaries with and without option 'noholes' and compare the extracted boundaries. The boundaries extracted with the default 'holes' option will contain all boundaries and the boundaries extracted with the default 'noholes' option will not contain the inner boundaries. You can refer doucumentation for bwboundaries for more details.

You can also try inverting the binary image and then find the boundaries with 'noholes' option.

类别

Help CenterFile Exchange 中查找有关 Computer Vision with Simulink 的更多信息

产品

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by