Granular watershed parameters

Is there a way to further configure watershed parameters besides “Mean filter radius” and “Sigma” in the Cell Detection function?

I am trying to count nuclei that are rather clumped and I have not managed to satisfactorily separate clumps.

When adjusting “Sigma”, I find that decreasing its value will split larger clumps (as described here) but also results in more polygonal nuclei (not circular). This will kind of throw off any detection classifier that rely on shape in downstream analyses.

I have tried to offset this by increasing “Mean filter radius” to smooth out the texture but this results in big clumps again or just not picked up at all.

I’m thinking along the lines of a way to specify watershed segmentation by desired diameter, i.e. “I would like this clump of nuclei to be broken into circular detections with 8 µm diameter”. Is this possible?

Many thanks,
Yau

PS. Hi Pete! It was nice meeting you last week at the Digital Pathology and AI Congress!

Hi @ym.lim, good to meet you last week too!

I describe all the parameters you can adjust in the second YouTube tutorial: https://www.youtube.com/c/qupath

But it’s not uncommon to find images where QuPath’s cell detection doesn’t perform well enough; it’s very generic and works ok across a wide range of images (both brightfield and fluorescence), but the cost for the generality is that it isn’t really optimized for any of them. There are areas where it struggles, especially with clumped nuclei.

It’s possible to add scripts and extensions to QuPath, and my intention is that more optimized methods of cell segmentation will be added for different applications. For now, the main options are:

  • try adjusting the parameters for the existing cell segmentation (maybe with help from the youtube descriptions)
  • try an alternative detection method in QuPath; some other others under the Analyze menu might be useful (e.g. superpixels)
  • use QuPath + ImageJ to try to solve the problem
  • try to develop your own cell segmentation algorithm by writing the code, and then try to get it running through QuPath

The last option is of course rather a lot more work and coding…

Ideally I’d love to go for option 4 but I’m nowhere close to being that proficient… I’ll see what I can do with QuPath + ImageJ. I’ll post an update if I manage to figure it out. Thanks, Pete!

Couple of potentially useless morning thoughts :slight_smile:

If reducing the sigma is resulting in more polygonal structures, and the polygon-ness of the stuctures isn’t a result of your actual pixel values, I would recommend checking whether the estimated pixel size is the same as you actual base pixel size. For some high resolution imaging (confocal data), the default 0.5 um per pixel can be turned way down. In the end you can’t both blur the nuclei into roundness and no blur the nulcei into overlapping if they are too close. Blur is blur, and other options like deep learning algorithms might be more effective if your data set is large enough.

At some point, though, you just can’t split the overlapping cell nuclei well enough at a given resolution in default QuPath. In my experience, tonsil and other lymphoid tissue in particular have usually needed to be 40x or above (objective), confocal, and with no compression in order to separate clumps well within the program.

If you want to split existing objects (large clumps of nuclei), that might be possible with a script that extracts large ROIs and processes them. Getting the initial objects would be easy, but figuring out how to split them “correctly?” Not sure how that would work right off the top of my head.

As you rightly guessed, the polygonal structures is likely due to the haematoxylin-stained nuclei having texture (these images are from mouse cerebellum):

Haematoxylin deconvoluted


OD sum

That’s why I thought of using Median Filter Radius to blur and smooth out the variation in pixel values within each nuclei, hopefully resulting in rounder nuclei. My experience with median filters so far has been that it is useful to smooth out pixel value variation while preserving edges. This did not help as I mentioned in the original post.

The base pixel size of the WSI I’m using is 0.2305 µm/pixel (40x). I have played with changing the Estimated Pixel Size to use the original resolution (value = 0) and anywhere in between 0 to 2 µm, but it also did not help. I thought using the original resolution in combination with some median filtering would achieve the best smoothing while preserving the edges of nuclei.

My WSI are JPEG compressed by to ~60% quality (sadly, for storage reasons…) but I think with the textures I’m getting within the nuclei, no compression would exacerbate the issue. No compression would certainly improve nuclei edge detection though.

Trying to split very clumped objects like in the images above is definitely very tricky. Thank you for putting your thoughts down here in my post though, it did let me think about some potential solutions (that on further thinking, doesn’t work).

I will still try exporting clumped nuclei into ImageJ and play with the greyscale watershedding function there, as @petebankhead suggested. My workflow will look something like this:

  1. Cell detection in QuPath using relaxed sigma values.
  2. Identify detection of clumps by area larger than 1 average nucleus size.
  3. Export greyscale haematoxylin/OD sum images to ImageJ.
  4. Median filter to smooth pixel values and preserve edges.
  5. Threshold and create ROI around clump.
  6. Greyscale watershedding (fingers crossed).
  7. Send split ROI back to QuPath.

Seems like this will be deathly slow to process, but I’ll find out soon enough…

1 Like

Yep. If you want to see what some of the filters end up doing to your image, it is certainly worth a look. Either within ImageJ using the median filter, or for the gaussian blur you can use the Pixel Classifier preview window. You will probably see the blur eliminating those thin lines between your nuclei.

In some cases around the center, there are no real dividing lines, so that would require a different approach anyway.