FIJI ImageJ - Calculate neighbours for every connected object in an image

Hi all,

I am importing a uint16 TIFF into FIJI ImageJ.

The TIFF contains several objects. Each object (i.e. defined as a set of connected pixels segmented as an instance) has its own unique intensity value in the image.

No two objects have the same intensity value.

I would like to calculate the number of neighbours for each of these objects.

Specifically, to be assigned as neighbours, I would like the minimum spanning distance between any two points on the edges of two objects to be below (or equal to) a certain pixel distance. (e.g. 10 pixels)

Could anyone please advise on the appropriate ImageJ modules I can use for a task like this?

Many thanks
Emma

Hi @Emma_Imaging,

A clarifying question on this part:

So two objects are neighbours if any pixel assigned to object A is within some distance of any other pixel assigned to object B. Is that right? (The point is that they don’t have to be “touching”, right?)

John

1 Like

Please clarify:
Is there a “background” colour and the regions are separated by some small space?
OR
Are the different regions adjacent/touching other regions? (no background colour)

Depending on this, the procedures to tell which regions are adjacent to a given region are different.
Maybe you can post a small image as an example.

1 Like

Hi @Emma_Imaging,

You can have a look to the distances measurements in 3DManager, you can import the image into 3DManager using add image, select two or more objects and compute distances and closest neighbors.

Alternatively, there is, in the intermediate release of 3DSuite, in Fiji, a new plugin called 3D interactions that may correspond to your need.

Best,

Thomas

2 Likes

That is correct.

There is also a background colour of 0 intensity. i.e. there are spaces between some objects (but not all).

There is also a background ‘colour’ of 0 intensity. i.e. there are spaces between some objects (but not all).

A pair of ideas:
If you have background between regions and each region has a unique label, like a voronoi diagram with the dams as background (that is the distance to a neighbour is <= sqrt(8)), then the nearest neighbours of a cell c can be found by the overlap of the double dilation of c and the original image (that is dilate twice c with a 3x3 kernel, then look at the histogram the number of different entries in the histogram of the dilated c gives you the neighbours).

If there is no background between the regions (truly adjacent labels) the same is true, but use a single dilation.

But for something in between, you need a better definition of what you would consider to be a “neighbour”.

Hi @Emma_Imaging and @gabriel,

Yes I think having a voronoi around your objects and then compute the interactions is a great idea. Here an illustration of this with the blobs image.


After thresholding and labeling I used 3D Watershed Voronoi (with max radius 20) and 3D Interactions, both part of the 3D ImageJ Suite. With this plugin you get for each object (here highlighted object 27) the objects interacting and the number of pixels at the interface between them.

Best,

Thomas

3 Likes

Hi @ThomasBoudier

Where can I find 3D Interactions ?
It sounds like extremely useful tool.
I’m using 3.94 and can’t find it on the 3D menu or through search

Thanks
Ofra

Hi @Ofra_Golani,
If you are using Fiji it should be available when you update Fiji and the 3D Suite, if you are using ImageJ it will be available with the next release. Please confirm you can find it, else I will check if I released it properly.

Best,

Thomas

1 Like

Hi @ThomasBoudier

It is working fine in Fiji. Thanks for adding this feature.It will be very useful for spatial analysis.

To close the loop: Previously I had problem using the update sites for 3D Suite and downloaded v3.94 directly. The problem appeared to be that mcib3d-core.jar is also distributed within EMBL-CBA update site and the versions were not compatible when I did the update. Now that I am aware of this I avoid this specific update, but I forgot checking again the 3D Suite update site.

Thanks
Ofra

Hi @Emma_Imaging

The macro below takes a labeled image and uses border-to-border distance from 3D Suite by @ThomasBoudier to calculate the number of neighbors for each object and color map the results using Assign Measure to Label from MorphoLibJ plugin .
Using the Blobs sample image you get the following

// Demonstrate Num Neighbors analysis on Blobs example
// Input should be labeled image (eg after threshold + 3D Object Counter)
DistToCheckNN = 20; // pixels 

run("3D Manager");
Ext.Manager3D_AddImage();
Ext.Manager3D_Count(nb_obj);

NumNeighbWithinDist = newArray(nb_obj);
Id = newArray(nb_obj);
for (n=0; n<nb_obj; n++)
{
	for (m=0; m<nb_obj; m++)
	{
		if (m != n)
		{
			Ext.Manager3D_Dist2(n,m,"bb",dist);
			if (dist < DistToCheckNN) 
				NumNeighbWithinDist[n] = NumNeighbWithinDist[n] + 1;
		}
	}
	Id[n] = n+1;
}
Array.show("Num_Neighbors", Id, NumNeighbWithinDist);

selectImage("LabeledObjects");
waitForUser("Select NumNeighbWithinDist and 0-8 in the next dialog");
run("Assign Measure to Label");
run("Fire");
run("Calibration Bar...", "location=[Upper Right] fill=White label=Black number=5 decimal=0 font=12 zoom=1 overlay");

Note that if you have a big image with many objects it may work slowly and you’ll need further tricks to calculate only distances to relevant objects

4 Likes

Hi @Ofra_Golani,

Glad to see it i working now, feedback is appreciated because plugin is in beta version.

Thanks for the information about the EMBL-CBA update site, I guess @Christian_Tischer should make 3D suite a dependency for their plugin, I will be happy to help.

Best,

Thomas

Hi @Emma_Imaging,

sorry, I have seen this post quite late.
You might also want to have a look at:

This gives you different options to analyze the neighbors in a 2D image.

hth

1 Like

@ThomasBoudier
Oh, good to know. I was not really aware… I will follow this up here: Release of 3D Suite 3.93

For the sake of completion, a colleague just found out this plugin listed on ImageJ website that computes the distance between centroids or edges
https://imagej.nih.gov/ij/plugins/graph/index.html

image

2 Likes

I saw your post on the Graph 3D plugin and added it to Image J. I need to calculate the distance between nearest neighbors from particles in a TEM image similar to what you have shown in your post. But when I tried using it and selected edges, I got something that looks like this. Any idea how to get the actual distance values in the table?

Hi @tdalavoy ,

You can also try the 3D Distances plugin, part of the 3D ImageJ Suite.

Best,

Thomas

1 Like

Hey @tdalavoy ,

you can also use CLIJ, to segment objects, and measure distances in 3D in Fiji.

From a binary image, you could use connected component labeling and centroidsOfLabels to determine positions of the objects. Then, you can use average_distance_of_n_closest_points with n==1 and pullToResultsTable to measure the distances to the closest neighbors.

Taking a look at a basics and some advanced tutorial might help as well.

Let me know if you need support. An example data set would be helpful in this case.

Cheers,
Robert

1 Like

Thanks for the suggestion, but unable to find it in the Image J website. Can you please send the link if possible?