Distance between points across a stack

Hi guys,

I know it is a quite simple task to do if you do know well how to code…but I don’t :blush:

I have a Result table with the X and Y coordinates of the center of mass of an object for each slice in a stack.
I would like to measure the distance as: sqrt (XM2-XM1)(XM2-XM1)+(YM2-YM1)(YM2-YM1) for slice 2 vs 1. Then, I would like to do the same for slice 3 vs 2 and so on, until the end of the stack. Lastly, I would like to add the distance measurements to the Results table.

How I do that?

Many thanks guys for helping such a cheeky incompetent!

Cheers

Nobody is willing to help me?

Well…thank you guys anyway.

Not sure where your problem is.
getResultString(“Column”, row) gets you your Ms from the results table.
Maybe you need to throw in a parseFloat(string) or a parseInt(string).
sqrt() needs a pair of extra parenthesis:

distance= sqrt( (XM2-XM1) (XM2-XM1)+(YM2-YM1) (YM2-YM1));

Your formula only calculates the distance correctly if M1 and M2 represent the same object, but at different time points.
If you want to measure the 3D-distance between your points, make sure you factor in the MZ1, MZ2 and the inter-slice distance (e.g. run(“Properties…”,“voxel_depth=3.7”)).

Help is often not more than 24 hours away.

Thanks Eljonco for your help.

What I want to do is the following:

  • From the same object imaged at different time points (I have a stack of images) I want to measure the center of mass of it and evaluate if it moves during time.
    -I have a Result table with the XM and YM coordinates for each slice.
    -Using sqrt( (XM2-XM1) (XM2-XM1)+(YM2-YM1) (YM2-YM1)) I have the distance from slice 1 to slice 2.
    -How do I measure the distance from slice 2 to 3…from 3 to 4 and so on (nSlices)?
    -Lastly, I want the distances in a column in the Result table.

It is a quite trivial thing to get, but I am not very familiar yet with looping…

Cheers

I gather that you are familiar with the functions and language pages?
Seems that a for loop is appropriate. Certainly do run(“Set Measurements…”, “center redirect=None decimal=2”); to get XM and YM in the Results table.

for(step = 0; step < (nResults -1);step++){
	x1=parseFloat(getResultString("XM",step));
	y1=parseFloat(getResultString("YM",step));
	x2=parseFloat(getResultString("XM",step+1));
	y2=parseFloat(getResultString("YM",step+1));
	distance = sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));
}
1 Like

Many thanks!

Last question: how do I get the distance measurements in the Results window?

That, my dear @MIKEIII, is trivial and left as an exercise to the student. Hint: RTFM :sunglasses:

1 Like

Many Thanks! Solved!