 # Distance map with several centers

Hello everyone,
I’m new to Fiji and to this forum, which has already helped me a lot, but I’m still having huge troubles to analyze my images…
Here is what I’d like to do: I’d like to analyze the localization and distribution of the green-positive cells regarding to the red-positive regions. The tissue labelling was quite challenging so I have to define the red-regions and the green-positive cells manually.
Picture1-roi.tif (1.9 MB)
I was thinking of defining a line centered to my red regions (as they have an unusual form, I cannot use the centroid point, but is it possible to calculate the equivalent of a ‘centroid line’ or ‘centroid shape’?). Then run an Euclidean distance map originating from those lines/shapes and finally measure the distance of each green-positive cells from a red center thanks to this map.
I’d also like to have a distribution of the distances between my green-positive cells to possibly evidence clustering.

Could you help me achieve that?

Louise
NB: the picture quality is very bad, sorry, I’m currenty homeworking and don’t have access to the original images…

When you convert the red regions into a binary image you can run a Skeletonization algorithm which gives you a sort of ‘centroid line’ which you can use to compute a distance map.

Here is an IJ macro showing the idea:

``````newImage("Untitled", "8-bit black", 100, 100, 1);
makePolygon(32,56,35,38,54,31,68,27,70,40,63,40,62,64,55,74,55,50,39,73,25,74);
setForegroundColor(255, 255, 255);
run("Fill", "slice");
run("Select None");
setOption("BlackBackground", true);

run("Skeletonize");

// below two lines are necessary because in ImageJ binary images are 0 and 255 (and not 0 and 1)
// ...and the distance map is computed on the foreground pixels
run("Multiply...", "value=255");
run("Invert");

run("Distance Map");
``````

Hi @Louise28
Welcome to the forum.

Since you are new to Fiji/ImageJ I don’t want to go into details of macro’s and scripting in the first place. (But it should be one of your next steps because you need a basic understanding of scripting to solve your task.)

Here some general hints:

You can use the ‘principal axis’ as a defined reference line for your distance measurement.
The ‘principal axis’ is running through the center of mass and in a certain direction (direction of the highest variance ~ direction of the largest object extent).
These values (center of mass and angle of principal axis) can be measured for each of your Roi’s.
(In Analyze>Set Measurements select the options ‘Center of mass’ and ‘Fit ellipse’. Then in the RoiManager select your Rois in the list and click ‘Measure’. Now you should have the all necessary data to define the reference lines mathematically in the ResultsTable.)

Assuming that the cells are measured already and that the positions of the cells are available (in groups according to your Roi’s) then the distance between cells and reference line can easily be calculated (https://en.wikipedia.org/wiki/Distance_from_a_point_to_a_line).

You need to know how to measure the cells and how to access values in the ResultsTable per macro language.

This is where I would start.
Try to detect and measure your cells and try to measure the distance of the cell in relation to the origin (x/y = 0/0).
If you have accomplished this it will be not a huge step to include the reference line into your script.

Thank you very much for your help!!
I was able to create the distance map as I wanted, and therefore to measure the distance to center of my green-positive cells.

I am still struggling to calculate the nearest neighbor distance for each of my green-positive cells (in order to evidence clustering; I’d like to make a distribution of the distances to maybe evidence a shift according to the conditions).
I’m able to run a Delaunay triangulation based on my multipoints (each multipoint corresponding to a green-positive cell), and it gives me “an average distance between my points”. I can also extract each point coordinates. Based on these coordinates, I should be able to determine which point is the closest neighbor of every given point, and to calculate the distance between those two points. But I don’t know how to proceed…
And I didn’t find an answer in the delaunay-related posts…

I hope you’ll be able to help me for this one too!