Search code examples
imagej

ImageJ Angle Measurement Tool: get the lengths of the two lines


I apologize if this is a rudimentary question, but I am unable to find an answer in the ImageJ documentation and am a new user. In ImageJ, the angle measurement tool outputs the angle between the two lines, but is there a way to get the lengths of those two lines?

I analyze > set measurements, but do not see an option for length.


Solution

  • Below please find an ImageJ-macro that should do what you want:

    //imagej-macro "anglePlus" (Herbie G., 07. Jan. 2025)
    requires("1.54m");
    if (selectionType!=8) exit("Angle-selection required");
    run("Set Measurements...","display redirect=None decimal=3");
    ttl=split(getTitle(),".");
    getSelectionCoordinates(x,y);
    setResult("Label",nResults,ttl[0]);
    setResult("Angle",nResults-1,getValue("Angle"));
    setResult("Length-1",nResults-1,pyth(x[1]-x[0],y[1]-y[0]));
    setResult("Length-2",nResults-1,pyth(x[1]-x[2],y[1]-y[2]));
    exit();
    function pyth(x,y) { return sqrt(x*x+y*y); }
    //imagej-macro "anglePlus" (Herbie G., 07. Jan. 2025)
    

    Length-1 is that of the first drawn line. Both lengths are in pixels.