How to separate Object's merged Boundaries in Image?

5 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
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

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!

Translated by