StarDist in QuPath Normalization issue

I found out there was a bit of a conceptual issue on how QuPath tiles images for StarDist segmentation.

It would appear that each tile that is sent for StarDist detection and segmentation is normalized independently, so in cases where there may for some reason be only background in a particular tile, the trained model detects a bunch of things that should not be there…

Would it be possible that when QuPath needs to tile the data, it computes the normalization values on a downsampled version of the image and then applies this to each tile, for consistency?

Otherwise, is there the possibility to provide fixed normalization values? Even if it means pre-computing them ourselves?

All the best,

Oli

See screenshot below.


Hi!

One thing that immediately comes to mind would be using the pixel classifier to generate an annotation that excluded areas/tiles like those where you are seeing background issues, then running StarDist only inside of that annotation. It may be nice to have more normalization options in the future, but I figured I would point that out as a quick short term solution.

@oburri yes, see Stardist extension
If you use a tissue annotation, empty regions will be excluded anyway.

In this post I show how to use precomputed values: Stardist extension

1 Like

Hi @Mike_Nelson yes absolutely, it is even easier to just draw it by hand :slight_smile: thanks for the very releavant remark!

It does not however change the fact that I could get different segmentation results depending on the region size I choose, which could hinder reproducibility.

I would then take this one step further and take the normalization values only inside the region that is annotated, no matter its shape, because another problem we have faced is that on most microscopes now, tiling is not necessarily square (Convex hull tiling for example) and some chunks of the image are completely black, thus skewing the quantile-based normalization.

Does Qupath compute the values for the normalization based on the region that is selected or on a squared tile, no matter the region?

1 Like

Currently the normalization is computed per square tile – not the entire selected region.

I realize better methods are probably needed in the future, but these need to handle the issue that computing normalization values for large regions may be very slow (particularly if the number of tiles requiring access would exceed the cache size, meaning that they need to be requested twice to run the detection once).

For this reason it is also possible to normalize in other ways, as I show in the previous post.

That’s also true with QuPath’s built-in cell segmentation… https://github.com/qupath/qupath/issues/80
Although reproducibility may still be claimed if one chooses the same region each time.

I’m uneasy about this too, but otherwise one is restricted to using algorithms that only rely on local features within a very limited window. While desirable, writing entirely shift-invariant algorithms can be very difficult, and to do so may require compromising in other areas…

Awesome! I had missed this post

We tried addressing this by using a downsampled version of the data to pre-compute the min and max values to apply to each tile. I know that this has issues of its own, but as @uschmidt83 said in the other post, so long as the objects are close to 1 and the background close to 0, this should be fine, so as long as I can still see cells in the downsampled version, this should work!

I think I will then get the percentiles from a downsampled image and apply that awesome Ops trick to get a more consistent result.

Loving this Ops thing!

2 Likes