Calculate Leaf Area in ImageJ

imagej

#1

Hey there, I am working on calculating leaf area using the macro plugin in ImageJ. The macro plugin has done most of the work for me but some scans are proving more difficult to black out than others. I’ve set these scans aside and have been adjusting the threshold, however this isn’t producing the desired output.

I am now trying to hand select each leaf using the wand tool, then calculate the area but the values are looking odd (units in pixels rather than cm). I’ve attempted to adjust the scale but am running into problems. Does anyone have advice or possibly another approach/protocol to calculate leaf area by hand selecting each image? Any and all help is GREATLY appreciated!


Manually Select Area for Leaf Area Calculation
#2

Good day,

please post some of the more difficult to process raw images in the original TIF- or PNG-format. No JPG-format though, because JPG introduces artifacts! You may also post images as Zip-archives.
(Converting a JPG-compressed image to TIFF- or PNG-format doesn’t make sense.)

Furthermore, please post the ImageJ-macro you are using.

Finally:
Setting thresholds by hand is not recommended for scientific work. Always use a suitable automatic threshold scheme and stay with it.

Regards

Herbie


#3

Hi Herbie,

Thank you for your response. I have uploaded one image.

I understand this approach is not ideal but it’s necessary. The area values for these scans need improvement, as they will be used to calculate leaf mass area. I plan to use the same approach for each species but this marsh marigold is presenting a challenge. Thank you for your response and help.

Best,
Katie


#4

Good day Katie,

you’ve asked this question in a different thread before
https://forum.image.sc/t/manually-select-area-for-leaf-area-calculation/20648?u=herbie
and you’ve received help.

So please tell us why the suggestions made are not really applicable and please show us the macro you are talking about.

Meanwhile I shall have a closer look at your sample image.

Regards

Herbie


#5

Katie,

as you may understand, your sample image suffers from several deficiencies:

  1. Image acquisition is suboptimum.
    Illumination is uneven and there are considerable shadows.
  2. There is a dark border at the top and left side of the image
  3. Two of the items are touching

A. Except for #3 the problems will be automatically solved by the following ImageJ-macro.
B. To cope with problem #3 you must draw separating lines by hand using the pencil tool set to black and to width two or greater. The macro tells you this and if you’ve finished drawing click OK and the macro will finish.
C. The macro will save the resulting binary image and the result table values to the directory from which you’ve opened the original image.

Here is the ImageJ-macro code:

// imagej-macro "leafAreas" (Herbie G., 09. Nov 2018)
requires( "1.52h" );
if (nImages>0)  {showMessage("All open images will be closed!"); close("*");}
pth=File.openDialog("Open Image");
setBatchMode(true);
open(pth);
run("Set Measurements...", "area redirect=None decimal=0");
nme = split(getTitle(),".");
run("Duplicate...", "title=temp");
w=getWidth()-16; h=getHeight()-16;
run("Canvas Size...", "width="+w+" height="+h+" position=Center zero");
run("Subtract Background...", "rolling=50 light sliding");
run("Split Channels");
close("temp (green)"); close("temp (red)");
setAutoThreshold("Minimum");
setOption("BlackBackground", true);
run("Convert to Mask");
run("Fill Holes");
setForegroundColor(0, 0, 0);
setBatchMode(false);
waitForUser("Separate by hand", "Separate items with black pencil of width 2.");
run("Analyze Particles...", "size=1000-Infinity show=Overlay display clear");
run("Overlay Options...", "stroke=none width=0 fill=green apply");
saveAs("tiff", File.getParent(pth)+File.separator+nme[0]+"_binary.tif");
saveAs("results", File.getParent(pth)+File.separator+nme[0]+"_results.txt");
close("Results");
exit();
// imagej-macro "leafAreas" (Herbie G., 09. Nov 2018)

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

Here is what I get for the provided sample image:


MC_CalLep-LMA_results

The areas are given in pixel^2. If you need them in square-millimeters or square-centimeters, you need to know how many pixels go into a millimeter or centimeter. A ruler that is imaged with the leafs may help with doing this.

Please reportt back if this is of any help.

Regards

Herbie


#6

Hello there,
You just need to set the measurement scale by drawing a straight line across any of the leaves, going to analyze > set measurements and equate the length of the line (given in the banner ) to the number of the pixels. You only have to know the actual length of the leaf line.
Bob


#7

Hi Herbie,

This is the macro I’ve been working with.

I understand the complications with my images and am kindly asking for help. Ideally, I want one area output in cm^2 and have achieved this using the macro above. I am trying to “black out” the leaf area, which when successfully done, looks like this:

The more difficult scans (like the marsh marigold) produce an image in which entire leaf area is not calculated. The yellow portions indicate areas not included in the leaf area calculation. See below.

This is what I am trying to fix. Does this provide a better understanding of what I am trying to accomplish?


#8

Thanks Katie!

How are the images acquired?

Did you try my macro?

I still gives the area in pixel^2 but otherwise does, with a little hand intertvention, what you want.

If possible please use this macro and in case, confirm my result.

Regards

Herbie


#9

Katie,

here is my updated macro that uses the same scale-factor as the macro you’ve provided.

Revised: 10. Nov. 2018

macro "Leaf area [a]" {
// imagej-macro "leafAreas" (Herbie G., 09./10. Nov. 2018)
requires( "1.52h" );
if (nImages>0) {showMessageWithCancel("All open images will be closed!"); close("*");}
pth=File.openDialog("Open Image");
setBatchMode(true);
open(pth);
run("Set Measurements...", "area redirect=None decimal=2");
nme=split(getTitle(),".");
run("Duplicate...", "title=temp");
run("Set Scale...", "distance=300 known=2.54 unit=cm");
w=getWidth(); h=getHeight();
run("Canvas Size...", "width="+(w-16)+" height="+(h-16)+" position=Center zero");
run("Subtract Background...", "rolling=50 light sliding");
run("Split Channels");
close("temp (green)"); close("temp (red)");
setAutoThreshold("Minimum");
setOption("BlackBackground", true);
run("Convert to Mask");
run("Fill Holes");
setForegroundColor(0, 0, 0);
setBatchMode(false);
waitForUser("Separate by hand", "Separate touching items with black pencil of width 2.");
run("Analyze Particles...", "size=0.01-Infinity show=Overlay display clear");
n=nResults;
run("Summarize");
sum=n*getResult("Area", nResults-4);
setResult("Area", nResults, sum);
setResult("Label", nResults-1, "Sum");
run("Canvas Size...", "width="+w+" height="+h+" position=Center zero");
run("Overlay Options...", "stroke=none width=0 fill=green apply");
saveAs("tiff", File.getParent(pth)+File.separator+nme[0]+"_binary.tif");
saveAs("results", File.getParent(pth)+File.separator+nme[0]+"_results.txt");
exit();
// imagej-macro "leafAreas" (Herbie G., 09./10. Nov. 2018)
}

For the provided sample image I get 16 numerical areas in cm^2:
results
(Due to touching items and without manual intervention one gets 14 areas.)

You may either run this macro in the way described in my previous post or by substituting your macro by this one.

I guess the images are captured with a flat-bed scanner. Is this right?

Please report back!

Regards

Herbie