MATLAB Answers

how to draw boundary of an image

19 views (last 30 days)
rohith bharadwaj
rohith bharadwaj on 9 Apr 2018
Answered: Arun Mathamkode on 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
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);
hold off

  1 Comment

rohith bharadwaj
rohith bharadwaj on 10 Apr 2018
Help please. Input image is xt

Sign in to comment.

Answers (1)

Arun Mathamkode
Arun Mathamkode on 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.


Sign in to comment.