How do I separate connected objects on a binary image?

11 次查看(过去 30 天)
My task is to separate the black objects in this photo and calculate their surfice area. I have tried applying erosion and watersheds, but I didn't get to an adequate solution.
  2 个评论
Rik
Rik 2023-2-6
You need to somehow make use of the property that all objects are convex, although I don't have a ready-made solution for you.
Sarvesh Kale
Sarvesh Kale 2023-2-6
you have to calculate the area of each blob or all the black blobs after their separation ?

请先登录,再进行评论。

采纳的回答

Sarvesh Kale
Sarvesh Kale 2023-2-6
Here is my attempt at doing the separation of black blobs and calculating their surface area, I have used erosion followed by dilation by two different structuring elements, this operation is also known as opening in image morphology but the structuring element is kept the same in most cases, following is my code snippet
clear ;
i=imread('image.jpeg');
i = i >150 ; % threshold image ;
subplot 121
imshow(i) % show thresholded image
i = ~ i ; % invert image for morphological op
se1 = strel('disk',9);
ie=imerode(i,se1); % do image erosion with se1
subplot 122
se2 = strel('disk',5);
io=imdilate(ie,se2); % do image dilation with se2
blobs = regionprops(io);
io=~io; % invert again to bring back to original
imshow(io);
b1=blobs(1) % ouptut info of blob 1
rectangle('Position',b1.BoundingBox,'EdgeColor','r','LineWidth',1.5); % draw rectangle on the first blob
you can get help on imdilate and imerode by heading to the following documentation page
you can get additional imformation on regionprops by heading to the following documentation page
You can also try to experiment with different structuring elements to see which combination gives the best separation and do your own experiments.
I hope this answers all your queries, please accept the answer if queries answered. Thank you

更多回答(0 个)

产品


版本

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by