how to draw boundary of an image

3 visualizzazioni (ultimi 30 giorni)
rohith bharadwaj
rohith bharadwaj il 9 Apr 2018
Risposto: Arun Mathamkode il 20 Apr 2018
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

Risposte (1)

Arun Mathamkode
Arun Mathamkode il 20 Apr 2018

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.

Prodotti

Community Treasure Hunt

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

Start Hunting!

Translated by