I have an image which has stained cells and I have to segment all the cells.

But the problem is that the cell boundary is not very distinguished where there is staining done because of the stain.

Can someone kindly help me with segmenting the image and getting cell boundary?

please find the image here:


enter image description here

I tried various filters like RidgeFilter, DerivativeFilter, GaussianFilter and combination of them.

I am using Mathematica 12.

  • $\begingroup$ Hi Ved, welcome to Mma.SE. Start by taking the tour now and learning about asking and what's on-topic. Always edit if improvable, show due diligence, give brief context, include minimal working example of code you have tried in formatted form. By doing all this you help us to help you and likely you will inspire great answers. The site depends on participation, as you receive give back: vote and answer questions, keep the site useful, be kind, correct mistakes and share what you have learned. $\endgroup$
    – rhermans
    Jul 12, 2019 at 11:06
  • $\begingroup$ @rhermans Thank you so much for correcting my question. Next time onwards, I will be carefull. $\endgroup$ Jul 12, 2019 at 11:44

1 Answer 1


As discussed here, there are public codes to do ridge detection. If I apply it to your image, I get this

Mathematica graphics

which seems to do the job.

  • $\begingroup$ Thank you @chris for your answer. But I am sorry this won't help me as WatershedComponents does not give accurate segmentation as you can see that there are a lot of small cells which are not there in the original image, especially in the white regions. $\endgroup$ Jul 12, 2019 at 12:30
  • $\begingroup$ accurate in the sense that there are a lot of extra cells in the colourise image which are actually not there in the original image. $\endgroup$ Jul 12, 2019 at 12:32
  • $\begingroup$ No. It also gives extra boundaries. I have to perform force inference on that image of cells which is extremely sensitive toward cell boundaries. Hence, I want the boundaries to be precise. $\endgroup$ Jul 12, 2019 at 12:40
  • $\begingroup$ You can tune the level of persistence to get a good match to what you consider to be the best match (which is currently unspecified!) $\endgroup$
    – chris
    Jul 13, 2019 at 6:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.