How do I separate connected objects on a binary image?

15 vues (au cours des 30 derniers jours)
Katarina Djurovic
Katarina Djurovic le 5 Fév 2023
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 commentaires
Rik
Rik le 6 Fév 2023
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 le 6 Fév 2023
you have to calculate the area of each blob or all the black blobs after their separation ?

Connectez-vous pour commenter.

Réponse acceptée

Sarvesh Kale
Sarvesh Kale le 6 Fév 2023
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

Plus de réponses (0)

Produits


Version

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by