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
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
2023 年 2 月 6 日
you have to calculate the area of each blob or all the black blobs after their separation ?
採用された回答
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
https://in.mathworks.com/help/images/ref/imdilate.html and https://in.mathworks.com/help/images/ref/imerode.html
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 件のコメント
その他の回答 (0 件)
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!