How do I separate connected objects on a binary image?

조회 수: 15 (최근 30일)
Katarina Djurovic
Katarina Djurovic 2023년 2월 5일
답변: Sarvesh Kale 2023년 2월 6일
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