Ratio between two lengths

Hi guys,

Is there a straightforward way to calculate the ratio between two distances (ratio = length1/length2) using the line tool in ImageJ/Fiji? I could not find any info on that matter here or elsewhere.

Best regards,

Christophe

Good day Christophe,

you may use some lines of ImageJ-macro code but first you need to tell us how you measure which lengths .

Regards

Herbie

Hi Herbie,

The two lengths are simply measured on a random image (here, the skull of theropod dinosaurs) with the straight line tool using the option ‘measurement’ (Ctrl+M). Once I have the two lengths, I just wish to know the ratio between length1 (e.g., skull lenght) and length2 (e.g., snout length). No need to know the actual distance given that this is just a ratio between two distances on the same image.

Thanks!

Regards,

Christophe

Christophe,

it’s essentially a one-liner:

``````print(getResult("Length",0)/getResult("Length",1));
``````

Paste the above macro code to an empty macro window (Plugins >> New >> Macro) and run it.
The code assumes that the Results table contains only two rows.

You could add a second code line

``````run("Clear Results");
``````

which clears the results table after the computation of the ratio.

In any case the ratio is output to the Log-window.

HTH

Herbie

Yes, that works. I now just need to know how to write a script which would ask me to trace two lengths with the straight line tool, and calculate the ratio between those two distances. If any one knows how to do that, feel free to help me! Otherwise, I’ll try to do that by myself.

Thanks again Herbie, very nice of you!

Regards,

C.

I now just need to know how to write a script which would ask me to trace two lengths with the straight line tool, and calculate the ratio between those two distances.

Christophe,

why didn’t you tell us before …

Now it is double work!

Here it is:

``````requires( "1.52i" );
setTool("line");
waitForUser( "User action required", "Draw the first line, then click OK.");
List.setMeasurements;
l1=List.getValue("Length");
run("Select None");
waitForUser( "User action required", "Draw the second line, then click OK.");
List.setMeasurements;
l2=List.getValue("Length");
run("Select None");
print(l1/l2);
exit();
``````

Herbie

Thanks a lot Herbie, that’s great!!! It does work when I install the macro and have it display in the Macro menu. However, every time I restart Fiji, the macro has disappeared. I can also download it as a plugin but it never appears in the list of plugins. Just don’t know what I’m doing wrong, really!!

Thanks again for your precious help!

Christophe

Christophe,

I encounter no problems installing the macro.

1. Copy the macro-code to the Editor window as explained before
2. Save it from there somewhere on your computer and name it “length_ratio.ijm” (the underrscore is essential)
3. In the FIji-installation there is a folder “plugins” and in this folder there is a folder named “Macros”
4. Put the macro code in this folder (do not put it in the folder named “macros”)
5. The macro should now and repeatedly appear as the last entry in “Plugins >> Macros”-menu

There should be a detailed description somewhere on the Fiji-website.
Personally I don’t use Fiji, so I can’t help you further but the above should work!

Good luck

Herbie

Yeap, that did work indeed! You’re awesome!!! Very surprised this option was not available in ImageJ or Fiji before. I often use distance ratio and this tool will definitely be helpful.