Last year when I was working at the University of Exeter I was involved in a project that was measuring hydraulic properties of leaves from Amazonian trees that had been droughted or not droughted, as part of the long running DRYFLOR experiment in the Baia de Caxiuana in Brazil.
I had ~1800 leaves that we scanned to measure their leaf area. The method I’ve used in the past uses imageJ to threshold the image, then analyse contiguous blocks of black and white to get the area, so I wanted to continue using the program I was comfortable with. However, I wasn’t looking forward to the prospect of measuring the leaf area of that many leaves so I looked into using the macro language for imageJ to automate the process.
You can find the macro I used saved as a
.ijm file here
, and I have another macro that also counts the number of leaf objects in each image here
Tips for scanning leaves for use in imageJ
- One Scan per sample unit - normally a leaf or a branch of leaves - aids automation
- Decide on a standard DPI for all scans - 300DPI is fine
- Try to get the leaf as close to the middle of the page as possible
- Make sure to add a ruler or something of known size in the scan area, so you can set your scale
- Make sure to clean the scanner glass and cover frequently to stop bits of sap sticking to it
- Name all scans with the sample number and
_3etc. if multiple scans per sampling unit
- Label each scan with a written label on the image just in case the image names go weird
- Once the images are scanned, open them up in paint and manually remove any elements connected to your leaf that you don’t want to include in your analysis by painting them white, e.g. petioles, dead leaf areas.
Manual imageJ leaf area
- Open image
- Convert to 8 bit [Image > Type > 8-bit]
- Preserve only the leaf using the Threshold [Image > Adjust > Threshold > Move sliders > Apply]
- Draw a line of known length over the image scale bar then set the scale [Analyze > Set Scale… > Change “Known Distance” and “Unit of length”] Set Global if all images from then on will have the same scale
- Get the area [Analyze > Analyze Particles… > Check Display Results]
- There might be lots of small particles but if the thresholding was done correctly then the leaf should be the largest by far. Can also choose “Show outlines” to get an image with the numbers written on it in red, which correspond to those on the table.
Preparing images for imageJ automated macro
- To automate leaf area calculation, all images must have the same resolution. Resolution can be changed in Adobe Photoshop using an
- Open an image in Photoshop
- Select Windows -> Actions
- Select “Create New Action”
- Give the Action an appropriate name and select “Record”
- Select Image -> Image Size…
- Change “Resolution” to 300
- Select “OK”
- Select File -> Save As…
- Select an appropriate location
- Change “Format:” to JPEG
- Go back to the Actions panel and select the Stop button
- Select File -> Automate -> Batch…
- Select the recently created Action from the dropdown menu
- Under “Source:” choose where your images are stored
- Under “Destination:” choose where your new images will be stored
- Check the box labelled “Override Action “Save As” Commands”
- Create an appropriate File Naming system, e.g. “document name” + “extension”
- Select “OK”
- Check that new images are the desired resolution by opening some and selecting Image -> Image Size…
Analyzing in imageJ using automated macro
- Open ImageJ
- Select Process -> Batch -> Macro…
- Select the appropriate input and output files
- Input should be where your images are
- Output should be where you want any files generated by the macro to go
- Insert the following code into the large box, can also be loaded from
// Calculate area of dark objects (leaves) against white background. // 79.7619px/cm a4-200dpi. // 120.006px/cm a4-300dpi. // Change `size min` to analyse smaller objects, but increase noise run("8-bit"); setAutoThreshold("Default"); //run("Threshold..."); //setThreshold(0, 146); setOption("BlackBackground", false); run("Convert to Mask"); run("Set Scale...", "distance=120.006 known=1 pixel=1 unit=cm global"); run("Analyze Particles...", "size=0.70-Infinity show=Outlines display add"); setOption(“Display Label”, true)
- Under “Output Format” selecgt “8 bit TIFF” to generate a file for each image containing outlines of all objects analysed. Use these to check that the macro worked properly.
- Select “Process” and wait for the macro to finish.
- A window should open containing a list of objects, their areas, and the file in which the objects were found. The results in this window can be copied and pasted into an excel file for analysis.
Customising the ImageJ automated leaf area macro
setThreshold(...is the minimum and maximum grey values to be selected for the image analysis. These values can be generated by doing a manual threshold and moving the sliders until only the leaves are highlighted.
distance=...is a distance given in pixels used to set the scale of the image. 120 is for 1 cm in a 300dpi a4 image. This value can be generated by manually setting the scale in ImageJ.
known=...is the real distance that the “distance” value inhabits in the image.
size=...-...is the minimum and maximum object size that will be analyzed by ImageJ with units of the scale specified by “distance” and “known”.
circularity=...-...is the minimum and maximum object circularity that will be analyzed, with 0 being a straight line and 1 being a perfect circle, useful for excluding rulers in the analysis. Could also be used to measure features on the leaves such as smut fungi, tar spots etc.