Drawing vertical lines inside a polygon selection [ImageJ]

imagej2

#21

Both start at the same position but don’t necessarily have the same length.


#22

This ImageJ-macro shoudl do what you want (streamlined 08. Feb. 2019):

// imagej-macro "vertDistances" (Herbie G., 07./08. Feb. 2019)
requires( "1.52k" );
setTool("line");
waitForUser("Draw the 1st line from left to right.\nIf done, click OK.");
getSelectionCoordinates(x1, y1);
run("Add Selection...");
waitForUser("Draw the 2nd line from left to right.\nIf done, click OK.");
getSelectionCoordinates(x2, y2);
run("Add Selection...");
run("Select None");
vert0=abs(y1[0]-y2[0]);
b=slp(x2,y2);
a=off(b,x2[0],y2[0]);
vert1=abs(y1[1]-(a+b*x1[1]));
mean=(vert0+vert1)*0.5;
print("left-y: "+vert0+";  right-y: "+vert1+";  mean-y: "+mean);
exit();
function slp(x,y) {return (y[1]-y[0])/(x[1]-x[0]);}
function off(c,x,y) {return y-c*x;}
// imagej-macro "vertDistances" (Herbie G., 07./08. Feb. 2019)

Paste the above macro code to an empty macro window (Plugins >> New >> Macro) and run it.

HTH

Herbie