How to measure leaf area in ImageJ

We scanned the leaves in colour as per instructions in the New handbook for standardised measurement of plant functional traits worldwide (Pérez-Harguindeguy et al. 2013).

Please note: these instructions broadly follow those provided in the Prometheus Wiki here [updated link], which also has heaps of other really useful information about plant measurements. The ImageJ user guide is also super useful. See near the end of post for information about how to accurately measure hairy leaves, leaves with shadow or pale leaves.

Open ImageJ

Download here

Select the image you want to measure

File > Open

Measure a known length to set the scale

Select the Straight line tool [insert image] and measure an area of known distance in your image.

For me, this is the circle sticker we attached to the scanning paper for every leaf scan. I zoomed in as far as possible (using a combination of Magnifying glass and Scrolling tool insert image) to find the further pixels on either side of the circle. Then I selected the Straight line tool and held down Shift to force the line to be horizontal. Once I am happy that the line captures the diameter of the circle (which I measured to be 11 mm on paper)

Set the scale

Analyze > Set Scale…

In Known distance enter the known length of the line (11 for me) and in Unit of length enter the known unit (mm for me). The other info will be entered automatically by the software. Select Global to make the scale apply to all images opened during the current session (yes please! – also see p. 139 of user guide for more information on Set Scale).

Something else to keep in mind is that once you exit ImageJ, you will need to reset the scale upon re-opening.

Convert to 8-bit

Image > Type > 8-bit Color

Adjust the threshold

Image > Adjust > Threshold…

This is where it starts to get a bit complicated. The software does a pretty good job of picking up the leaf but there are still white pixels in the middle of the leaf that should be black, and therefore won’t be included in the leaf area calculation. If you manually increase the threshold by adjusting the lower arrow bar, it gradually fills in those white pixels but also increases the perimeter of the leaf.

There is an Auto button that lets the software set the threshold levels (that is the level it automatically sets it at when you first open Threshold). Additionally, there are a range of threshold methods to choose from (using the drop-down box) as described here. That is a little dense so I just use the Default method. In an effort to avoid me needing to manually adjust the threshold levels (and introduce bias?), I also decided to apply the Auto setting (see pp. 79-80 in the ImageJ user guide for more in-depth explanation of Threshold).

Once you have selected your Threshold settings, click Apply.

That leaves me (lol) with an image that looks like this


If you zoom in you will see the interior white pixels


Note: the Auto function will overestimate the area of leaves with shadow or hairs and underestimate the area of pale leaves. A method of dealing with this is suggested near end of post.

Fill in these white pixels

Select the Wand (tracing) tool and click on the leaf – this puts a yellow highlight around the leaf. Then select Edit > Fill (or Ctrl+F) to fill in everything inside the leaf outline as black.

I tested the difference in area is using fill vs no fill. For one leaf there was a 1.1 mm2 difference, and for another species there was a 4 mm2 difference. So it seems worthwhile to fill in the leaf. That said, what you’re aiming for when setting the threshold is to get an accurate estimate of the leaf perimeter, since the Fill tool will fill in everything inside that perimeter.

Choose the measurements you want to receive

Analyze > Set Measurements…

Make sure the ones you want are ticked.

Select the leaf/leaves you want to measure in your image

Select the Rectangular tool [insert image] and draw a square around the leaf/leaves you with to measure. You can also use the Polygon or Freehand selections tools to do this.

Alternatively, you can use the Wand (tracing) tool to select the leaf itself.

Measure leaf area

Analyze > Analyze Particles…

In Size enter a single value and any value smaller than that will be ignored. I enter “1”. This is useful to make the software ignore any of the small black pixels in the image adjacent to but not part of the leaf you’re measuring. Play around with this to see what works for you. If you use the Wand (tracing) tool to select the leaf to measure then you don’t need to change the Size (i.e. can leave it at zero as Wand dictates what you measure).

For me it reads Size (mm^2) which indicates I have set my scale and it will provide an area in mm2. Leave pixel units unchecked unless you want to receive the area in pixels and not mm2 (or your relevant scale).

In Show I select Outlines so that, after measuring, it shows me an outline of what was measured with a small red number of the measured particle that relates to the Results Table. This is useful to test whether your Size setting is suitable or not. Mask is also useful if you want to save a version of what you measured.

I also have Display results ticked so that the measurements will be provided in the Results Table. Click OK.

Note: You can also use Analyze > Measure  to get results for whatever you selected in the Set Measurements section, but it will not give you an outline or mask.

Highly recommended: see pp. 132-135 of user manual for more information on Analyze Particles and to select the appropriate settings for your work.

See measurement results

The Results Table opens with the area of my leaf (365.037 mm2)

Another file opens showing the Outlines I requested – note the small red “1” that relates to the Results Table.

Note: I don’t think you actually *need* to select the leaf (if there is only one in the image) using the wand tool or set a size before selecting Analyze Particle.

How to measure hairy leaves, leaves with shadow or pale leaves

The method described above does not work very well for scans of leaves that contain shadow or hair (as the Auto Threshold function will overestimate leaf area) or leaves that have pale parts (as the Auto Threshold function will underestimate leaf area).

I tried a number of ways to solve this.

If the edits required are only very minor, you can try using the white Paintbrush Tool to remove shadow and/or the black Paintbrush Tool to fill in pale parts of leaves. Double click the Paintbrush Tool to adjust the thickness or colour.

Personally, I decided to use the black Paintbrush Tool to trace the outline of the entire leaf (as accurately as possible) on a Surface Pro using a stylus pen and fill the leaf in black. Then I convert the image to 8-bit, adjust the lower sliding bar of Threshold to zero (to keep the outline), click Apply and save it as a jpeg. I then import this image into ImageJ on my computer. Before you can analyse particles you need to set the threshold. So I click Adjust > Threshold… and use the Auto setting. I’ve found that this does not add or remove any black pixels to my image. I then use the Wand (tracing) tool to select the leaf and measure the area. (I used a computer for this last step because it’s quicker to use the mouse than on the Surface Pro).

The Prometheus Wiki suggests “in worst case scenario” you can print out the leaf images and colour them in. This might be useful if you only have a few leaves to measure.

You can measure all sorts of things with ImageJ, and the user manual is your best friend in getting to know the program – so have fun with it and enjoy!

How to work out the size of cells in a raster and convert COUNT to ha to use in a graph

I am using a raster showing different vegetation types across Australia, and I want to display the area (ha) they cover in a simple column graph.

The raster includes “COUNT” in the attribute table. As explained here, “COUNT” represents the number of cells in the raster dataset with the cell value in the VALUE column.” Note: ‘cells’ are the same as ‘pixels’.

I need to work out the size of the cells and convert “COUNT” to ha so that it makes sense in the real world.

To do this, I need to find out the spatial resolution of the raster I’m using, which is 30 m (I got this off the website I downloaded the data from). As explained here, if the resolution of my data is 30 m, then the area of a cell is 30 x 30 m. Therefore, the area of one cell in my raster is 900 m2.

To get the area of one cell in ha:

  • COUNT * 900 = x m2
  • x m2 / 10,000 or x m2 * 0.0001 = x ha

In an edit session in ArcMap I create a new field in the raster’s attribute table called “area_ha”. Using the field calculator, I create this formula to fill “area_ha”:

  • ( [COUNT] * 900 ) * 0.0001

(which is the same formula I wrote above).

And voila! “Area_ha” is populated with the area of each vegetation type in ha.

Note: I found this document very useful to read before using the field calculator. For example, I needed to make the data type “double” so that it would accept numbers with decimal places (needed when converting to ha) and how to set the precision and scale.