pliman
(plant image analysis) is designed to analyze plant images, especially related to leaf analysis. You provide color palettes, tell pliman
what each one represents, and it takes care of the details. The package will help you to:
leaf_area()
.symptomatic_area()
.count_lesions()
.count_objects()
.objects_rgb()
.get_measures()
.plot_measures()
.The function leaf_area()
can be used to computes the leaf area using an image with leaves and a template with a known area. A general linear model (binomial family) fitted to the RGB values is used to first separate the leaves and template from the background and then the leaves from the template. The leaf area is then calculated for each leaf based on the pixel area.
In the following example, the area of five three leaves will be computed using a reference template with a known area of 4 cm\(^2\).
library(pliman)
# |========================================================|
# | Tools for Plant Image Analysis (pliman 0.2.0) |
# | Author: Tiago Olivoto |
# | Type 'vignette('pliman_start')' for a short tutorial |
# | Visit 'https://bit.ly/3eL0dF3' for a complete tutorial |
# |========================================================|
<- image_import(image_pliman("la_pattern.JPG"))
img <- image_import(image_pliman("la_leaf.jpg"))
leaf <- image_import(image_pliman("la_temp.jpg"))
tmpl <- image_import(image_pliman("la_back.jpg"))
background image_combine(img, leaf, tmpl, background)
# Computes the leaf area
<-
area leaf_area(img = img,
img_leaf = leaf,
img_template = tmpl,
img_background = background,
area_template = 4,
text_col = "white")
get_measures(area)
# -----------------------------------------
# Total leaf area : 142.931
# Average leaf area: 23.822
# -----------------------------------------
# id x y area perimeter radius_mean radius_min radius_max
# 1 1 510.8398 194.8310 33.675574 750 130.93825 112.84830 174.98737
# 2 2 206.7294 201.3974 27.063816 707 119.27683 93.26143 170.78366
# 3 3 123.4206 557.3541 30.701037 787 128.71937 95.70023 189.29542
# 4 4 622.9502 585.3997 39.408991 864 143.38098 108.58618 203.37775
# 5 5 364.7605 508.5782 8.081735 376 64.26213 51.24084 86.01652
Here, we will count the grains in the image soybean_touch.png
. This image has a cyan background and contains 30 soybean grains that touch with each other.
<- image_import(image_pliman("soybean_touch.jpg"))
soy image_show(soy)
# Count the objects in the image
<- count_objects(soy)
grains #
# --------------------------------------------
# Number of objects: 30
# --------------------------------------------
# statistics area perimeter
# min 1366.0000 117.000000
# mean 2057.3667 146.600000
# max 2445.0000 158.000000
# sd 230.5574 8.406073
# sum 61721.0000 4398.000000
# Draws the object id (by default)
plot_measures(grains)
The function symptomatic_area()
is used to compute the percentage of symptomatic leaf area in a sample or entire leaf based on provided color palettes samples. A general linear model (binomial family) fitted to the RGB values is used to segment the lesions from the healthy leaf. If a pallet of background is provided, the function takes care of the details to isolate it before computing the number and area of lesions.
The next example computes the symptomatic area of a soybean leaf. The proportion of the healthy and symptomatic areas is given as the proportion of the total leaf area, after segmenting the leaf from the background (blue).
<- image_import(image_pliman("sev_leaf.jpg"))
img <- image_import(image_pliman("sev_healthy.jpg"))
healthy <- image_import(image_pliman("sev_sympt.jpg"))
symptoms <- image_import(image_pliman("sev_back.jpg"))
background image_combine(img, healthy, symptoms,background)
# Computes the symptomatic area
symptomatic_area(img = img,
img_healthy = healthy,
img_symptoms = symptoms,
img_background = background,
show_image = TRUE)
# healthy symptomatic
# 1 89.11082 10.88918
The function objects_rgb()
can be used to get the Red Green and Blue (RGB) for objects in an image. Here, the RGB for
<- image_import(image_pliman("soy_green.jpg"))
img # Segment the foreground (grains) using the normalized blue index
# Shows the average value of the blue index in each object
<- objects_rgb(img, marker = "index") rgb
# Draw the object id
image_show(img)
plot_measures(rgb)
# plot the distribution of RGB values of each object
plot(rgb)
If you encounter a clear bug, please file a minimal reproducible example on github
Suggestions and criticisms to improve the quality and usability of the package are welcome!