How to get cell boundaries in the image?

img = Import["https://i.stack.imgur.com/YsIVf.png"];

img2 = Pruning @ Thinning @ Closing[#, 10]& @ DeleteSmallComponents[#, 25000]& @ 
 LocalAdaptiveBinarize[#, 50]& @ GaussianFilter[#, 10]& @ img

enter image description here

HighlightImage[img, img2]

enter image description here


I have somewhat mixed corey's and nikie's approach (check their posts) to arrive at a somewhat reasonable segmentation. Kudos to them.

img2 =  ImageAdjust@RidgeFilter[img, 5] // GaussianFilter[#, 8] & // 
   LocalAdaptiveBinarize[#, 50] & // 
  DeleteSmallComponents[#, 25000] & // Closing[#, 10] & // 
Thinning // Pruning;

HighlightImage[img, img2]

enter image description here


Your image contains thin, line-like structures, so a RidgeFilter seems like a good idea:

img = Import["https://i.stack.imgur.com/YsIVf.png"]
ridges = ImageAdjust[RidgeFilter[img, 5]]

enter image description here

Die ridges have large brightness variance, but MorphologicalBinarize works well enough:

bin = MorphologicalBinarize[ridges, {.1, .5}]

enter image description here

To segment the individual cells, I need markers for each cell center. The maxima of a distance transform usually give good markers:

dist = DistanceTransform[ColorNegate@bin];    
maxMarkers = MaxDetect[dist, 2];    
HighlightImage[bin, maxMarkers]

enter image description here

Now I can use those markers as starting points for a watershed segmentation:

watersheds = WatershedComponents[ridges, maxMarkers];
Colorize[watersheds]

enter image description here

These are segmentation borders highlighted in the original image:

HighlightImage[img, ColorNegate[Binarize[Image[watersheds]]]]

enter image description here