Title: | Rapid Digital Image Analysis of Leaf Area |
---|---|
Description: | An interface for the image processing program 'ImageJ', which allows a rapid digital image analysis for particle sizes. This package includes function to write an 'ImageJ' macro which is optimized for a leaf area analysis by default. |
Authors: | Masatoshi Katabuchi <[email protected]> |
Maintainer: | Masatoshi Katabuchi <[email protected]> |
License: | GPL-2 |
Version: | 0.1.8.9001 |
Built: | 2025-02-06 05:11:16 UTC |
Source: | https://github.com/mattocci27/leafarea |
Exports sample image files to R temporary directory and returns a path to the sample image files. This function is only used in the example of run.ij
.
eximg()
eximg()
Jpeg files to the R temporary directory and a path to the sample image files.
Masatoshi Katabuchi [email protected]
run.ij
which this function wraps
Check if ImageJ is installed in the correct directory.
find.ij(ostype = .Platform$OS.type)
find.ij(ostype = .Platform$OS.type)
ostype |
the Operating system types. |
When ImageJ, including ij.jar and Java, is not installed in the common location, users need to specify the path to ImageJ in run.ij
.
A path for ImageJ application. On unix this will always be "/Applications/ImageJ/". On Windows this will always be "C:\Program Files\ImageJ\".
Masatoshi Katabuchi [email protected]
Analyzed leaf area data for example
leafdata
leafdata
A list with six data frames, A1-01.jpeg.txt, A1-02.jpeg.txt, A123-01.jpeg.txt, A123-02.jpeg.txt, A2.jpeg.txt and A300-1.jpeg.txt. The first column is the identity of image, the second column is the area of the image (cm2) and the thrid column is the perimeter of the image (cm).
Read multiple tab-delimited text files with a leaf area and perimeter value (one text file for each original JPEG image file) generated by ImageJ.
readtext.ij(path)
readtext.ij(path)
path |
Path to the target directory |
A list of data frame of leaf area for each image
area |
Leaf area of the image (cm2) |
Masatoshi Katabuchi [email protected]
#prepare example files data(leafdata) tf <- paste(tempdir(), "/", sep = "") for (i in 1:7){ write.table(leafdata[[i]],paste(tf,names(leafdata)[i],sep=""),sep="\t") } #list of files list.files(tf) readtext.ij(tf) unlink(list.files(tf))
#prepare example files data(leafdata) tf <- paste(tempdir(), "/", sep = "") for (i in 1:7){ write.table(leafdata[[i]],paste(tf,names(leafdata)[i],sep=""),sep="\t") } #list of files list.files(tf) readtext.ij(tf) unlink(list.files(tf))
File management function. The output file contains sample names in the first column and total leaf area (cm2) of the sample (e.g., one individual plant or one ramet) in the second column.
resmerge.ij(path, prefix = "\\.|-")
resmerge.ij(path, prefix = "\\.|-")
path |
Path to the target directory |
prefix |
Regular expression to manage file names |
A data frame of total leaf area for each sample
sample |
Name of sample |
total.leaf.area |
Total leaf area of the sample (cm2) |
Masatoshi Katabuchi [email protected]
#prepare example files data(leafdata) tf <- paste(tempdir(),"/",sep="") for (i in 1:7){ write.table(leafdata[[i]],paste(tf,names(leafdata)[i],sep=""),sep="\t") } #list of files list.files(tf) #combine multiple tab-delimited text files with a leaf area value #(one text file for each original JPEG image file) that share the same #filename 'prefix', defined as the part of the filename preceding the first #hyphen (-) or period (.). resmerge.ij(tf) #combine multiple tab-delimited text files with a leaf area value #(one text file for each original JPEG image file) that share the same #filename 'prefix', defined as the part of the filename preceding the first #'.txt'. resmerge.ij(tf, prefix = ".txt") unlink(list.files(tf))
#prepare example files data(leafdata) tf <- paste(tempdir(),"/",sep="") for (i in 1:7){ write.table(leafdata[[i]],paste(tf,names(leafdata)[i],sep=""),sep="\t") } #list of files list.files(tf) #combine multiple tab-delimited text files with a leaf area value #(one text file for each original JPEG image file) that share the same #filename 'prefix', defined as the part of the filename preceding the first #hyphen (-) or period (.). resmerge.ij(tf) #combine multiple tab-delimited text files with a leaf area value #(one text file for each original JPEG image file) that share the same #filename 'prefix', defined as the part of the filename preceding the first #'.txt'. resmerge.ij(tf, prefix = ".txt") unlink(list.files(tf))
Analyzes leaf area in the target directory automatically, and returns a data frame that contains sample names in the first column and total leaf area (cm2) of the sample (e.g., one individual plant or one ramet) in the second column. Note that 'run.ij' does not count the number of leaves in each image; therefore if the user requires the number of leaves per image, the user must record these values.
run.ij( path.imagej = NULL, set.memory = 4, set.directory, distance.pixel = 826, known.distance = 21, trim.pixel = 20, low.circ = 0, upper.circ = 1, low.size = 0.7, upper.size = "Infinity", prefix = "\\.|-", log = F, check.image = F, save.image = F )
run.ij( path.imagej = NULL, set.memory = 4, set.directory, distance.pixel = 826, known.distance = 21, trim.pixel = 20, low.circ = 0, upper.circ = 1, low.size = 0.7, upper.size = "Infinity", prefix = "\\.|-", log = F, check.image = F, save.image = F )
path.imagej |
Path to ImageJ. Default uses C:/Program Files/ImageJ for Windows, and /Applications/ImageJ for Mac. Linux always needs to specify the path to ImageJ |
set.memory |
Set memory (GB) for image analysis (default = 4). |
set.directory |
Set directory that contains leaf images. For example, when the directory named 'leaf_data' is on desktop of Mac, the path can be specified as: set.directory = '~/Desktop/leaf_data'. For Windows: set.directory = 'C:/Users/<users name>/Desktop/leaf_data'. No default. The path to the target directory that contains leaf images should always be specified. Note that spaces in file or directory names are not allowed. |
distance.pixel |
Number of pixels for the known distance. When leaf images were captured in A4 image size with 100 ppi, the pixel density is roughly equal to 826 pixels per 21 cm. In this case, the calibration scale can be specified as distance.pixel = 826, known.distance = 21. |
known.distance |
Known distance (cm). See distance.pixel. |
trim.pixel |
Number of pixels removed from edges in the analysis. The edges of images are often shaded, which can affect image analysis (i.e., ImageJ may recognize the shaded area as leaf area). The edges of images can be removed by specifying the number of pixels (default = 20). |
low.circ |
Lower limit for circularity for the image analysis. When the user wants to remove angular objects (e.g., cut petioles, square papers for scale) from the images, the analyzed lower limit of circularity can be increased (default = 0). |
upper.circ |
Upper limit for circularity for the image analysis (default = 1). See low.circ. |
low.size |
Lower limit for size for the image analysis. Leaf images often contain dirt and dust. To prevent dust from affecting the image analysis, the lower limit of analyzed size can be increased (default = 0.7). |
upper.size |
Upper limit for size for the image analysis (default = Infinity'). |
prefix |
Regular expression to manage file names. The 'run.ij' combines 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 (.) that may occur (no hyphen or period is required). 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 (A123). This feature allows the user to treat multiple images as belonging to a single sample, if desired (default = '\\.|-'). |
log |
Should mean leaf areas of each single image kept? (default = FALSE) |
check.image |
Whether to display analyzed images by using ImageJ software (default = FALSE). When you choose check.image = TRUE, press any keys to close ImageJ. Note that when check.image = TRUE, the analysis would take considerable time. Note this option may only work on R console. |
save.image |
Whether to save analyzed images (default = FALSE). |
A data frame of total leaf area for each sample.
sample |
Name of sample |
total.leaf.area |
Total leaf area of the sample (cm2) |
If you choose log= T, the 'run.ij' function also returns a list of data frames of leaf area for each image.
area |
Area of the sample (cm2) |
Masatoshi Katabuchi [email protected]
resmerge.ij
, readtext.ij
, eximg
# As long as ImageJ application, including `ij.jar` and java, is installed # in the following directory, # you do not have to specify the path to ImageJ # /Applications/ImageJ <Mac> # C:/Program Files/ImageJ <Windows> # Linux always needs to specify the path to the directory that contains `ij.jar`. # For example, path = "~/ImageJ" # prepare the target directory that contains example image files ex.dir <- eximg() list.files(ex.dir) #run automated images analysis run.ij(set.directory = ex.dir, save.image = TRUE) # note: in this example, analyzed images are exported to a temporary # directory, which will be eventually deleted. # If you choose your home directory as the target directory, # analyzed images will be exported to it.
# As long as ImageJ application, including `ij.jar` and java, is installed # in the following directory, # you do not have to specify the path to ImageJ # /Applications/ImageJ <Mac> # C:/Program Files/ImageJ <Windows> # Linux always needs to specify the path to the directory that contains `ij.jar`. # For example, path = "~/ImageJ" # prepare the target directory that contains example image files ex.dir <- eximg() list.files(ex.dir) #run automated images analysis run.ij(set.directory = ex.dir, save.image = TRUE) # note: in this example, analyzed images are exported to a temporary # directory, which will be eventually deleted. # If you choose your home directory as the target directory, # analyzed images will be exported to it.