% Author: Dr. Joshua Morgan and Isabella Bagdasarian, TIME lab, UCR % Watershedding is a technique that can be used to seperate %clumps of objects by identifying local minima. This is especially useful %for nuclei segmentation. %PARAMETERS % im - 2D logical to segment. % threshold- threshold parameter, single value function [Dws] = NucWatershed_2D(im) %watershedding ED = -bwdist(~im); %create a euler distance map (the distance from any pixel to the nearest background) %the minus sign converts each nuclear "hill" (since the center is furthest from the edge) to a "valley" ED(~im) = Inf; ED = imhmin(ED,1); %sometimes you can have 2 barely different minimas, the hmin will suppress any small minima Dws = watershed(ED); %watershedding associates each point with its nearest minima. Think of it like a drop of water hitting each pixel, which drops flow together? Dws(~im) = 0; end