Supporting information

This document includes:

ESM 1. A detailed tutorial for LeafArea

Contents

1 Prerequisites 1

2 Image capture and file naming 2

3 How to run LeafArea 2

3.1 Setting path to ImageJ 2

3.2 Setting path to leaf images 2

3.3 Example 2

4 Automated leaf area analysis 3

4.1 Spatial calibration 3

4.2 Memory setting 3

4.3 Trimming images 3

4.4 Size and circularity 4

4.5 File naming 5

4.6 Result log 5

4.7 Saving analyzed images 6

4.8 Displaying analyzed images 7

5 Manual leaf area analysis 7

6 Figure legends 7

1 Prerequisites

From within R (for version numbers 3.0.0 and greater), the latest version of LeafArea can be installed by typing install.packages(“LeafArea”).

The package LeafArea requires the ImageJ software, which is available from http://imagej.nih.gov/ij/. Details on how to install ImageJ on Linux, Mac OS X and Windows are available at http://imagej.nih.gov/ij/docs/install/. For Mac, the default install directory of ImageJ is “/Applications/ImageJ”, and for Windows, "C:/Program Files/ImageJ”. Otherwise, one must specify the path to ImageJ to be able to use LeafArea in R (see §3.1 Setting path to ImageJ). In Linux systems, ImageJ should be installed from the above URL instead of via the command line. Java is also required, which is available at https://java.com/en/.

2 Image capture and file naming

Capture the leaf images using a scanner and save them in JPEG or TIFF format. Image size and resolution should be consistent across all image files because the LeafArea functions estimate leaf area from leaf pixel counts and the image size. Therefore, the LeafArea package does not support images from digital cameras, where the scale of images depends on the distance of the camera to the object.

LeafArea sums the leaf area of all images that share the same filename prefix, defined (by default) as the part of the filename preceding the first hyphen (-) or period (.). For example, the areas of leaf images named A123-1.jpeg, A123-2.jpeg and A123-3.jpeg would be combined into a single total leaf area with sample name A123. This feature allows the user to break a sample into multiple images, if desired. Note that the functions in the package do not count the number of leaves in each image. If the user requires the number of leaves per image, the user must record these values.

3 How to run LeafArea

3.1 Setting path to ImageJ

When ImageJ is not installed in the common install directory, the path to ImageJ must be specified in run.ij. This depends on the platform (Windows, Linux or Mac). For example, when ImageJ is installed in a directory named “ImageJ” on the desktop of a Mac or Linux system, the path can be specified by typing run.ij (path.imagej = "~/Desktop/ImageJ"); the equivalent in Windows is run.ij (path.imagej = ”C:/Users/<username>/Desktop/Imagej”).

3.2 Setting path to leaf images

To analyze leaf images, the path to their directory needs to be specified; the commands are depend on the platform (Windows, Linux or Mac). For example, when the target directory “leaf data” is on the desktop of a Mac or Linux system, the path can be specified by typing run.ij (set.directory = "~/Desktop/leaf data/"). In Windows the equivalent is run.ij (set.directory = "C:/Users/<username>/Desktop/leaf data").

3.3 Example

This example is in the R help. First, we use eximg function to specify the path to example leaf images in the R temporary directory. Next, we run the run.ij function, which will analyze leaf area autonomously:

ex.dir <- eximg()

res <- run.ij(set.direcotry = ex.dir)

The object ex.dir is the path to the R temporary directory that contains sample leaf images. This temporary directory will be deleted after the analysis. The object res, returned from LeafArea, is a data frame object, which contains name of the samples in the first column and their total leaf areas (cm2) in the second column.

res

##

## sample total.leaf.area

## 1 A1 350.340

## 2 A123 418.473

## 3 A2 177.188

## 4 A300 384.919

4 Automated leaf area analysis

The following settings can be changed according to the images.

4.1 Spatial calibration

LeafArea needs to be told the physical size represented by a pixel. When leaf images are captured at 100 ppi in A4 size, the pixel density is approximately 826 pixels per 21 cm. For this case, the calibration scale is specified by run.ij (distance.pixel = 826, known.distance =21).

4.2 Memory setting

The amount of memory available can be increased. By default, LeafArea uses 4 GB. Typing run.ij (set.memory = 8) will allocate 8 GB of memory to LeafArea.

4.3 Trimming images

The edges of images may have shadowing, which can cause ImageJ to recognize the shaded area as leaf area, affecting the image analysis. The edges of images can be removed by specifying the number of pixels (default = 20). For example, run.ij (trim.pixel = 20) will remove a 20-pixel border from each image.

Fig. S1

4.4 Size and circularity

Leaf images often contain dirt and dust. To prevent these artifacts from affecting the image analysis, the lower size limit to be analyzed can be specified. For example, the command run.ij (low.size = 0.7) will remove objects smaller than 0.7 cm2 from the analysis.

Fig. S2

To remove angular objects (e.g., cut petioles, square papers for scale) from the images, the lower limit of circularity can be increased (default = 0). For example, run.ij (low.circ = 0.3) will ignore cut petioles in the analysis.

Fig. S3

4.5 File naming

By default, LeafArea sums the leaf area of all images that share the same filename prefix, defined as the part of the filename preceding the first hyphen (-) or period (.); see §2 Image Capture and file naming and Fig. 2 in the main text. This setting can be changed using regular expressions. For example, typing run.ij (prefix = ‘\\.|-|_’) will sum the areas of the leaf images A123-1.jpeg, A123-2_1.jpeg and A123-2_1.jpeg into a single total leaf area with sample name A123.

4.6 Result log

A list object of data frames containing the area (cm2) of each object in each image can be returned by typing run.ij (log = T):

ex.dir <- eximg()

run.ij(set.directory = ex.dir, log = T)

##$summary

## sample total.leaf.area

##1 A1 350.340

##2 A123 418.473

##3 A2 177.188

##4 A300 384.919

##

##$each.image

##$each.image$`A1-01.jpeg.txt`

## Area

##1 116.799

##2 124.069

##

##$each.image$`A1-02.jpeg.txt`

## Area

##1 109.472

##

##$each.image$`A123-01.jpeg.txt`

## Area

##1 184.773

##

##$each.image$`A123-02.jpeg.txt`

## Area

##1 123.151

##2 110.549

##

##$each.image$A2.jpeg.txt

## Area

##1 43.328

##2 47.558

##3 41.427

##4 44.875

##

##$each.image$`A300-1.jpeg.txt`

## Area

##1 158.065

##

##$each.image$`A300-2.jpeg.txt`

## Area

##1 124.784

##2 102.070

By default, run.ij returns a single data frame object, which contains the names of the samples in the first column and their total leaf areas (cm2) in the second column (see §3.0).

4.7 Saving analyzed images

Analyzed images can be exported to the same directory as set.directory for error checking; type run.ij (save.image = TRUE). If the eximg function is used to set the target directory, the analyzed images will be exported to a temporary directory, which will subsequently be deleted, unless the home directory is chosen as the target directory.

4.7 Displaying analyzed images

Analyzed images can be displayed using the ImageJ software (defalt = FALSE). When run.ij (check.image = TRUE) is executed, pressing any key will close ImageJ. Note that when check.image = TRUE, the analysis will take considerable time. This option may only work on the R console.

5 Manual leaf area analysis

This step can be omitted if ImageJ succeeds in analyzing the leaf images. If ImageJ fails to recognize the leaf images (Fig. S4), however, the image analysis can be guided manually for particular images through the ImageJ graphical user interface (see ImageJ user guide 30.1 Measure...[m], http://imagej.nih.gov/ij/docs/guide/user-guide.pdf). The results for these manually analyzed images will still be handled by the file management function resmerge.ij in run.ij. Multiple tab-delimited text files containing leaf area values (one text file for each original JPEG image file) generated by ImageJ can be merged into a single data frame. The names of text files should have the same prefix as the image files (e.g., A123-1.txt, A123-2.txt, A123-3.txt). For example, when the text files are on the desktop of a Mac system, the files can be merged using:

resmerge.ij(“~/Desktop”):

## sample total.leaf.area

## 1 A123 418.473

The output and the option prefix are same as run.ij. Run command ?resmerge.ij in R for a more detailed description.

6 Figure legends

Fig. S1. The edges of images may have shadowing, which can cause ImageJ to recognize the shaded area as leaf area, affecting the image analysis. The edges of images can be removed by specifying the number of pixels (default = 20). For example, run.ij (trim.pixel = 20) will remove a 20-pixel border from each image.

Fig. S2. Leaf images often contain dirt and dust. To prevent these artifacts from affecting the image analysis, the lower size limit to be analyzed can be specified. For example, the command run.ij (low.size = 0.7) will remove objects smaller than 0.7 cm2 from the analysis.

Fig. S3. To remove angular objects (e.g., cut petioles, square papers for scale) from the images, the lower limit of circularity can be increased (default = 0). For example, run.ij (low.circ = 0.3) will ignore cut petioles in the analysis.

1