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

조회 수: 1 (최근 30일)
Hsu Htet Aung
Hsu Htet Aung 2018년 9월 5일
댓글: Matt J 2018년 9월 5일
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.

채택된 답변

Matt J
Matt J 2018년 9월 5일
편집: Matt J 2018년 9월 5일
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
Matt J
Matt J 2018년 9월 5일
You're welcome, but please Accept-click the answer to certify that it solved your problem.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

Community Treasure Hunt

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

Start Hunting!

Translated by