Cell Density Map

Hi,

I’m looking for a way to compute cell density map, based on already segmented cells (in 2D). My goal is to visually display the density map and quantify the location in the tissue with high concentration of the specific cells, eg based on distances from other objects.

@ThomasBoudier: How does 3D Density of 3D ImageJ Suite works? What exactly is it calculating? What do the different parameters control: Radius, NbNeighbors?
Should I use it with labeled image OR binary image of objects OR with an image of cell-centers (generated by ultimate points)?

Is there another Fiji plugin that calculates local density of objects?
@petebankhead: Is there a way to do it in QuPath?

@haesleinhuepf: any way to do this in CLIJ?

Thanks
Ofra

1 Like

Hey @Ofra_Golani,

would you mind sharing an example image? I’m asking because I wonder if you have a label map, a binary image and/or centroid positions in a table…
I would define density as number of cells per area or rather number of center pixels per area… How would you define it based on distances? Average distance to touching neighbors or average distance of the closest 5 for example? If so, I’m happy to help in case you try #clij This notebook could be a starting point. All shown operations also do their job in 2D :wink:

Cheers,
Robert

2 Likes

Hi @Ofra_Golani, here’s a QuPath script that will generate an ImageJ image as a starting point:

Basically, after defining the resolution of the map, each pixel in the map should give the number of centroids falling within that pixel. You can then proceed with filtering it (e.g. with Mean or Gaussian filters) depending upon how you want to define the density.

(The entire map could also be generated in a slightly longer script… but I’ve written such scripts a few times now, losing them each time, which suggests it really ought to be integrated directly into QuPath sooner rather than later.)

3 Likes

Hi @Ofra_Golani,

The details of the computation are here. Basically, for each pixel we look for the NbNeighbors closest neighbors and sum their Gaussian contribution based on their distance.

Best,

Thomas

2 Likes

Thanks @haesleinhuepf,

Indeed I would define the density as the number of cells per area or number of center pixels per area, so Count Non Zero Pixels in a Sphere is a good solution, maybe with additional smoothing step. I did encounter strange edge effect when using Count Non zero Pixels in a sphere (2D).

Here is a cropped labeled image after removing label boundaries LabelImage_nottouching.tif (6.0 MB), the related ultimate points image LabelImage_UltimatePoints.tif (3.0 MB) . The output of Count Non Zero Pixels (radius=100 pixels) is: count_non_zero_pixels.tif (3.0 MB)

Thanks
Ofra

1 Like

Hey @Ofra_Golani,

I’d say the edge effect comes from labels touching the image border.

Could you use excludeLabelsOnEdges before analysing the dataset?

Cheers,
Robert

1 Like

Thanks @ThomasBoudier

So for my case I should use it with Radius that reflect the desired size of local environment and with high number of NbNeighbors (>maximal cell count per local environment), right ?

Ofra

Hi @haesleinhuepf

excludeLabelsOnEdges solved the edge effect !

Thanks
Ofra

1 Like

Hi @Ofra_Golani,

Yes you are perfectly right :slight_smile: . To elaborate on the solution by @haesleinhuepf, counting non-zero pixels in an area seems like a linear version of the density map, density map will weight the counting by the distances of these non-zero pixels. But I guess in your case you should get similar results.

Best,

Thomas

2 Likes

Thanks @petebankhead

I’ll try it. Still hesitating which platform to use for this project: Fiji/QuPath or some integration :thinking:
Integrating this into QuPath would be great :slight_smile:

Ofra

2 Likes