David Alonso
David Alonso

Reputation: 21

How to obtain the scale of an image automatically in imageJ

I need to measure leaf area in a large set of leaves. The problem is that each image has a different scale since they were made with a camera at different heights. Next to each sheet I put a graph paper as a scale.

Is there any method / macro of ImageJ to obtain the scale of each image automatically?

On the other hand, can the area of ​​the sheets be calculated automatically?

https://i.sstatic.net/lWiHM.jpg

https://i.sstatic.net/wH0TD.jpg

Thank you!

I know how to do it manually: select for example 10 squares that equals 1 cm, then apply "set scale". Then I apply the treshold and measure the area. But I have 1200 images to analize...

Upvotes: 2

Views: 1007

Answers (1)

J. Kovacs
J. Kovacs

Reputation: 177

In principle one could analyze them automatically, but I think it would still require manual tracing of some kind in the end. Maybe this will help speed things up. When I haven't messed anything up, this should open every image in your folder one after the other, prompt you to draw a line, then set the scale and save the resulting scaled image in an output folder. Still manual, but markedly faster I should think.

input = getDirectory("");
output = input + "output" + File.separator;
    File.makeDirectory("");
list = getFileList(input);

for (i=0; i<list.length; i++) {

    open(input+list[i]);
    waitForUser("Draw Scale Line");
    getLine(x1, y1, x2, y2, lineWidth)
    distX = pow(x1-x2, 2);
    distY = pow(y1-y2, 2);
    distSUM = distX + distY + distZ;
    lengthScale = pow(distSUM, 0.5);
    run("Set Scale...", "distance="+lengthScale+" known=10 pixel=1 unit=cm");
    saveAs("Tiff", output+list[i]);
    close();
}

Upvotes: 1

Related Questions