How to get the inside shape within my segmented image?

Hello hi MATLAB community, i have a query with regards to image segmentation using image processing toolbox.
So i have this image, and i just want the inside of the segmented image which is the black almost circular shape inside the white region. Can you guys provide me with proper tools to help me segment the black part out of the image?
Thanks!

 Accepted Answer

If "mask" is your binary image, you can get the interior holes by inverting the image. Then call imclearborder to get rid of the surround:
mask = imclearborder(~mask);
% Now extract the largest blob only
mask = bwareafilt(mask, 1);

2 Comments

thanks! it works. i totally forgot about imclearborder, but can i ask one more thing? on gui app designer, how to plot centroid on our output image? (note the image generated is being displayed on axes)
Try this:
props = regionprops(mask, 'Centroid');
xy = vertcat(props.Centroid);
axis('on', 'image');
hold on;
% Plot red crosshairs at each centroid.
for k = 1 : numel(props)
plot(xy(k, 1), xy(k, 2), 'r+', 'LineWidth', 2, 'MarkerSize', 50);
end
hold off;

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!