# how to repeat watershed transform to improve separation

1 view (last 30 days)
Tugce Irem on 25 Aug 2022
Hello,
I have small circle touching objects which need to be separated and analyzed. I've read Watershed transform question from tech support by Mr. Eddins. In the information he said if it's needed repeat the steps. I'm not sure how to repeat the steps. I wrote repeating steps but it still not working accurately. Here is my code. If anyone can help me to figure out where I made a mistake or how I can improve separation, I'll be really appreciate it. Thank you
%watershed
bw2b = ~bwareaopen(~BWsegmentationb,10);
figure(); imshow(bw2b)
Db = -bwdist(~BWsegmentationb);
figure(); imshow(Db,[])
Ldb = watershed(Db);
figure(); imshow(label2rgb(Ldb))
bw2b = BWsegmentationb;
bw2b(Ldb == 0) = 0;
figure(); imshow(bw2b)
% Home stretch, now. Modify the distance transform so it only has minima at the desired locations, and then repeat the watershed steps above.
%watershed2
firstwatershed= firstwatershedpriim.CData;
firstwatershedbw= imbinarize(firstwatershed);
firstwatershedbw2 = ~bwareaopen(~firstwatershedbw,10);
figure(); imshow(firstwatershedbw2)
Db2 = -bwdist(~firstwatershedbw);
figure(); imshow(Db2,[])
Ldb2 = watershed(Db2);
figure(); imshow(label2rgb(Ldb2))
firstwatershedbw2 = firstwatershedbw;
firstwatershedbw2(Ldb2 == 0) = 0;
figure(); imshow(firstwatershedbw2)
Ld2b = watershed(D2b);
bw3b = BWsegmentationb;
bw3b(Ld2b == 0) = 0;
figure(); imshow(bw3b)

### Categories

Find more on Blocked Images in Help Center and File Exchange

R2022a

### Community Treasure Hunt

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

Start Hunting!