Custom measuring tool

Dear all, I am totally new to ImageJ so I apologise in advance if the question seems trivial to most. I am interested to measure pixel length and width of objects, actually seals, on a picture taken by a drone. I can measure separately the length and/or the width of my objects but I was curious to see if there is a way to create a custom tool that I can recall each time I use ImageJ. The tool I need should be similar to the one described here https://journals.plos.org/plosone/article?id=10.1371/journal.pone.0187465 . It is basically a line, Identifying the total length of the object, and a series of perpendicular intersecting lines crossing the main line at regular intervals. Once deployed, this tool should be editable to match the length of my object in each picture, and each intersecting perpendicular line shall be editable as well to match the width of the object at the different positions. Once all the edits have been done, the tool should give me the total length and the separate widths, one for each intersecting perpendicular line. Any suggestion is more than welcome. Regards, N

@nino Welcome to the forum! :smile:

What you describe is a form of image segmentation. In general, it is ideal for many reasons if the measurements can be done automatically, rather than drawing everything by hand. Could you please post a sample image? Then we can comment on the feasibility of automating the segmentation—or failing that, what the best workflow would be for manual segmentation + measurement.

Did you have a look at Suppl. Fig. S1 of that paper? It contains some ImageJ macro code that is supposed to be that tool you’re looking for:

// The macro "Ten Widths"color codesanddraws dots
// at 10 equally spaced points along a selectedline.
// Written by D.J.Krause, E. Keen and H. Fearnbach.

macro "ten widths [k]" {
getLine(x0,y0,x11,y11,width);
dx = x11 -x0;
dy = y11 -y0;
xstep = dx/11;
ystep = dy/11;

// Interpolate segment pts
x1 = x0 + 1*xstep;
x2 = x0 + 2*xstep;
x3 = x0 + 3*xstep;
x4 = x0 + 4*xstep;
x5 = x0 + 5*xstep;
x6 = x0 + 6*xstep;
x7 = x0 + 7*xstep;
x8 = x0 + 8*xstep;
x9 = x0 + 9*xstep;
x10 = x0 + 10*xstep;
y1 = y0 + 1*ystep;
y2 = y0 + 2*ystep;
y3 = y0 + 3*ystep;
y4 = y0 + 4*ystep;
y5 = y0 + 5*ystep;
y6 = y0 + 6*ystep;
y7 = y0 + 7*ystep;
y8 = y0 + 8*ystep;
y9 = y0 + 9*ystep;
y10 = y0 + 10*ystep;

//Color code each line section
setTool("brush");
setColor("blue");
setLineWidth(4);
drawLine(x0,y0,x1,y1);
setColor("red");
drawLine(x1,y1,x2,y2);
setColor("blue");
drawLine(x2,y2,x3,y3);
setColor("red");
drawLine(x3,y3,x4,y4);
setColor("blue");
drawLine(x4,y4,x5,y5);
setColor("red");
drawLine(x5,y5,x6,y6);
setColor("blue");
drawLine(x6,y6,x7,y7);
setColor("red");
drawLine(x7,y7,x8,y8);
setColor("blue");
drawLine(x8,y8,x9,y9);
setColor("red");
drawLine(x9,y9,x10,y10);
setColor("blue");
drawLine(x10,y10,x11,y11);

//Color code each oval
setTool("brush");
setColor("blue");
setLineWidth(4);
fillOval(x0,y0,15,15);
setColor("red");
fillOval(x1,y1,15,15);
setColor("blue");
fillOval(x2,y2,15,15);
setColor("red");
fillOval(x3,y3,15,15);
setColor("blue");
fillOval(x4,y4,15,15);
setColor("red");
fillOval(x5,y5,15,15);
setColor("blue");
fillOval(x6,y6,15,15);
setColor("red");
fillOval(x7,y7,15,15);
setColor("blue");
fillOval(x8,y8,15,15);
setColor("red");
fillOval(x9,y9,15,15);
setColor("blue");
fillOval(x10,y10,15,15);
setColor("red");
fillOval(x11,y11,15,15);
}

// Macro to save all measurements and data from a measuredimage.
// Saves JPEG with “draw” lines, and results table as .csv into thefolder 
// theimage was selected from.
// Written by D.J.Krause
macro "photosave[f]" {
//store filename and datetime
filename = getInfo("image.filename");
getDateAndTime(year,month,dayOfWeek,dayOfMonth,hour,minute,second,msec);
newfilename = "IMGJ-Measured-"+filename;
tt = filename + "-Measured.csv"
mfile = getInfo("image.directory") + newfilename;
rfile = getInfo("image.directory") + tt
saveAs("Jpeg",mfile);
saveAs("Results",rfile);
print(year + "-" + month + "-" + dayOfMonth + " " + hour + ":" + minute + ":" + second  + "--Measured leopard seal image and Results saved to" + mfile + "!");
}

Hi and thank you for your answers. I have of course looked at the supplementary information and I have seen the code. As I said in my original message I am totally new to ImageJ (and associated programming) so the code above is totally gibberish to me. Could you please elaborate more and guide me through on how to use the code in ImageJ. Again, all your help is very much appreciated.
N