hi all, i'm Trying to use bwboundaries function to draw a boundary line around two object in binary image, but it applies only on the big one. how do i apply it on BOTH?

1 view (last 30 days)
here's the code:
boundary2=bwboundaries(final);
cell_test = boundary2{1,1};
% plot and show boundary
figure(1);subplot(3,3,9), imshow(final); title('boundary2');
hold on; plot(cell_test(:,2),cell_test(:,1),'r','LineWidth',2); hold off;
as you can see, the boundary line circles only the left object, but not the right.
how do i apply this function on multpile object?
thanks all!

Answers (1)

Simon Chan
Simon Chan on 15 Feb 2022
Edited: Simon Chan on 15 Feb 2022
Modify as follows:
boundary2=bwboundaries(final);
% plot and show boundary
figure(1);subplot(3,3,9), imshow(final); title('boundary2');
hold on;
cell_test = boundary2{1,1};
plot(cell_test(:,2),cell_test(:,1),'r','LineWidth',2);
cell_test2 = boundary2{2,1}; % Add the 2nd one
plot(cell_test2(:,2),cell_test2(:,1),'b','LineWidth',2);
hold off;

Tags

Community Treasure Hunt

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

Start Hunting!