Perpendicular distance between a line and the center of a particle

Hello guys,

I need to automatic measure the perpendicular distance of each particle (or the centroid) and the pink line.
The image provided was binarized and segmented (watershed method), and then particles were analyzed with Fiji. I’ve tried to use bioVoxxel and BoneJ but i have not succed to measure the perpendiular distance after getting the particle count.

Hi @Marcos_Adrian_Villam ,

Welcome to the forum.

The “Distance transform” is helpful here, try this imagej macro

run("Create Mask");
run("Distance Map");
run("Invert LUT");

to get an image like this:

Then measuring the “min” gray value of the distance transform for each of your ROIs will give you the perpendicular distance to the line. (i.e. the distance from the line to the closest point of each roi).

Edit: The title says you want the distance to the center. In that case, measure the center points, and find the value of the distance transform at each of those.

Hope that helps,


Make sure the line goes all the way to the end. If the line is too short, you won’t get "perpendicular distance for regions that are past the end points.


Hi @Marcos_Adrian_Villam

I really like @bogovicj 's elegant distance transform solution but this question can also be considered as a purely trigonometric question.

You can pull the start and end coordinates of the line and output the XY coordinates of the structures then it’s just a case of using a cosine to calculate the perpendicular distance per object.

Hope that helps!


Thank you both of you guys! both answers solved my problem @dnmason was more accurate for my purpose.

1 Like

Well that is not the shortest distance. The shortest distance is really the closest from the cell boundary to the line.
What I would do is to do the distance transform, then compute the AND operation between the binarised cell set and the distance transform image.
That should result in the binary cells now having the pixels labelled in “distance” values (you might have to convert the images to a different bit depth. That way the minimum pixel value inc each cell would correspond to the shortest distance to the line.

1 Like