How to separate Object's merged Boundaries in Image?

12 vues (au cours des 30 derniers jours)
Mohsin Zubair
Mohsin Zubair le 1 Août 2022
Commenté : Mohsin Zubair le 8 Août 2022
I have some strawerries photos, What I am trying to do is to segment them and then count the total number of strawberries. I tried different methods like thresholding and edge detection but results were not as I wanted, now currently I am using graph cut method to segment strawberries which seem to work (better than thresholding or edge detection) but the boundaries of strawberries in binary image are merged together, I want to separate these boundaries using watershed transform but I can't seem to work it out. Any ideas or suggestion would be appreciated (even if there's idea about another method or approach to segment images I would love that as well). Following is my current code:
rgb=imread('1.jpeg');
imshow(rgb);
L=superpixels(rgb,1500);
h1=drawpolygon();
roiPoints=h1.Position;
roi=poly2mask(roiPoints(:,1),roiPoints(:,2),size(L,1),size(L,2));
BW=grabcut(rgb,L,roi);
imshow(BW);
imshowpair(rgb,imoverlay(rgb,BW,'r'),'montage');
imageData=BW;
D=-bwdist(~imageData);
D(~imageData)=-inf;
watermask=imextendedmin(D,0.2);
D2=imimposemin(D,watermask);
Ld=watershed(D2);
imageData(Ld==0)=0;
watershedImage=imageData;
imshow(watershedImage)
few results and original images are attached.
Would really appreciate any help
  2 commentaires
Benjamin Thompson
Benjamin Thompson le 1 Août 2022
The colorThresholder tool can let you quickly develop and export code for color space changing and mask development. Use imfill to improve the resulting mask for a given image. You may need multiple masks for ripe and unripe strawberries.
Then, maybe some further processing on the resulting shape if you have strawberries next to or occluding one another. Ideally you try to control that by arranging the strawberries better.
Mohsin Zubair
Mohsin Zubair le 2 Août 2022
But how do I seperate the merged boundries when strawerries are overlapping ? Any ideas for that?

Connectez-vous pour commenter.

Réponse acceptée

Image Analyst
Image Analyst le 2 Août 2022
  4 commentaires
Image Analyst
Image Analyst le 4 Août 2022
Well the best approach is to avoid the problem in the first place and have non-overlapping items. If they do overlap the usual way is to use morphological methods such as erosion and watershed to separate them. Of course at some point that won't work. If a berry is 90% obscured by another one, it will be virtually impossible to split them apart and if you could you'd only have a fraction of one of them. You might try some deep learning approach but you'd have to have thousands of images along with ground truth labels for them to train the network.
Another approach is to not worry about separating them at all. Maybe some sort of statistical bulk characterization is fine, like area fraction of strawberries in the whole image or something like that.
Mohsin Zubair
Mohsin Zubair le 8 Août 2022
thanks for the tips

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Image Processing Toolbox dans Help Center et File Exchange

Produits


Version

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by