How to separate Object's merged Boundaries in Image?

7 views (last 30 days)
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 Comments
Benjamin Thompson
Benjamin Thompson on 1 Aug 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 on 2 Aug 2022
But how do I seperate the merged boundries when strawerries are overlapping ? Any ideas for that?

Sign in to comment.

Accepted Answer

Image Analyst
Image Analyst on 2 Aug 2022
  4 Comments
Image Analyst
Image Analyst on 4 Aug 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.

Sign in to comment.

More Answers (0)

Categories

Find more on Image Processing Toolbox in Help Center and File Exchange

Products


Release

R2021a

Community Treasure Hunt

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

Start Hunting!