How to trace the boundary of each object in a binary image?

1 view (last 30 days)
I have a binary image like the following image. I want to plot the border of each object with different color. As far as I know, I need to use bwtraceboundary. But, I don't know how to choose the starting point that has to be parsed in the second input argument of bwtraceboundary. Any help is appreciated. Thanks.

Accepted Answer

Matt J
Matt J on 5 Sep 2018
Edited: Matt J on 5 Sep 2018
If your shapes are all solid blobs with no holes or narrow necks, then there are simpler ways than bwtraceboundary:
B=A-imerode(A,ones(3))>0;
reg=regionprops(B,'PixelList');
colors={'g','r','m','y','c'};
imagesc(A); colormap(gray(256));
hold on
for i=1:numel(reg)
plot(reg(i).PixelList(:,1), reg(i).PixelList(:,2),['.' colors{i}]);
end
hold off
  4 Comments
Matt J
Matt J on 5 Sep 2018
You're welcome, but please Accept-click the answer to certify that it solved your problem.

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!