I want to measure the distribution of all nearest neighbors of ROIs drawn over a micrograph. The micrograph is of a neural network and the ROIs are from Ca imaging. My goal is to get the distribution of the distances between active cells. Some are immediate neighbors, but others are far apart.

I can get from a map of the ImageJ ROIs (I create an overlay with the ROIs filled in black) to an x,y map (in Excel) of points using Analyze->Measure->Center of Mass>copy XM, YM to Excel:

Now that I have a map of all the points in an x,y plot, how can I get the distances of the nearest neighbor for each point in this x,y plot?

I created several methods Bio7 ImageJ/R interface methods to easily transfer selection and image data to R and vice versa. For some methods I had the Spatstat package in mind.

However with the condensed tutorial I hope it should’nt be a problem to feed in your data in a custom R script to measure and plot nearest neighbour distances even without Bio7.

The scripts can be found here:

The nearest neighbour distances can be easily obtained with (please adapt):

X <- ppp(x, y, c(0,1), c(0,1))
nndist(X)

from a point pattern object.

Distances from a marked point pattern could also be interesting for calculations (active cells, inactive cells)

@sroper your post title is a bit misleading. You don’t want do get all the distances between all ROIs (with the shortest distance being the shortest line between point on the periphery of each object), do you? If the centroid distances is all that you want, @tibuch’s workflow is just right.

@tibuch the way you’re calculating the nearest distance is quite complex. I’ve used the Similarity Search node (with a neighbor count of 2 and followed by a Row Filter for nearest neighbor index=1) in the past for similar tasks.

Thanks to all those above for the help! I think I found my answer and will now plow through the various possibilities to see what works best, fastest, and easiest.