Skip to contents

Getting started

Single images

library(pliman)
#> The legacy packages maptools, rgdal, and rgeos, underpinning the sp package,
#> which was just loaded, will retire in October 2023.
#> Please refer to R-spatial evolution reports for details, especially
#> https://r-spatial.org/r/2023/05/15/evolution4.html.
#> It may be desirable to make the sf package available;
#> package maintainers should consider adding sf to Suggests:.
#> The sp package is now running under evolution status 2
#>      (status 2 uses the sf package in place of rgdal)
#> |==========================================================|
#> | Tools for Plant Image Analysis (pliman 2.0.1)            |
#> | Author: Tiago Olivoto                                    |
#> | Type `citation('pliman')` to know how to cite pliman     |
#> | Visit 'http://bit.ly/pkg_pliman' for a complete tutorial |
#> |==========================================================|
# set the path directory
path_soy <- "https://raw.githubusercontent.com/TiagoOlivoto/images/master/pliman"
# import images
img <- image_import("leaf.jpg", path = path_soy)
healthy <- image_import("healthy.jpg", path = path_soy)
symptoms <- image_import("sympt.jpg", path = path_soy)
background <- image_import("back.jpg", path = path_soy)
image_combine(img, healthy, symptoms, background, ncol = 4)

Image palettes

Sample palettes can be created by manually sampling small areas of representative images and producing a composite image that represents each of the desired classes (background, healthy, and symptomatic tissues). Another approach is to use the image_palette() function to generate sample color palettes.

pals <- image_palette(img, npal = 8)

image_combine(pals$palette_list)

# to extract the color palettes, use the object
plot(pals$palette_list[[1]])

# default settings
res <-
  measure_disease(img = img,
                  img_healthy = healthy,
                  img_symptoms = symptoms,
                  img_background = background)

res$severity
#>    healthy symptomatic
#> 1 88.82041    11.17959

Alternatively, users can create a mask instead of displaying the original image.


# create a personalized mask
res2 <- 
  measure_disease(img = img,
                  img_healthy = healthy,
                  img_symptoms = symptoms,
                  img_background = background,
                  show_original = FALSE, # create a mask
                  show_contour = FALSE, # hide the contour line
                  col_background = "white", # default
                  col_lesions = "red", # default
                  col_leaf = "green") # default



res2$severity
#>    healthy symptomatic
#> 1 89.54006    10.45994

Variations in image palettes

The results may vary depending on how the palettes are chosen and are subjective due to the researcher’s experience. In the following example, I present a second variation in the color palettes, where only the necrotic area is assumed to be the diseased tissue. Therefore, the symptomatic area will be smaller than in the previous example.


# import images
healthy2 <- image_import("healthy2.jpg", path = path_soy)
symptoms2 <- image_import("sympt2.jpg", path = path_soy)
background2 <- image_import("back2.jpg", path = path_soy)
image_combine(healthy2, symptoms2, background2, ncol = 3)


res3 <-
  measure_disease(img = img,
                  img_healthy = healthy2,
                  img_symptoms = symptoms2,
                  img_background = background2)

res3$severity
#>    healthy symptomatic
#> 1 93.52282    6.477178

Lesion features

res4 <-
  measure_disease(img = img,
                  img_healthy = healthy,
                  img_symptoms = symptoms,
                  img_background = background,
                  show_features = TRUE,
                  marker = "area")

res4$shape
#>    id       mx       my area perimeter radius_mean radius_min radius_max
#> 1   1 221.2979 113.5842 1043 198.19596   22.528462  0.5382155  39.317832
#> 2   2 189.8006 129.4210 1337 255.55130   20.476874  1.8393851  38.940882
#> 3   3 177.9366 213.3191 3740 479.20310   50.115279  1.1130664  94.493378
#> 4   4 209.8309 193.3570 1838 256.48023   24.061647  0.7027602  42.539602
#> 5   5 263.3417 192.6246  142  45.48528    6.363385  4.2448924   8.510476
#> 6   6 119.4667 201.4647  103  37.97056    5.332571  3.2167920   7.037345
#> 8   8 145.0364 260.6303   74  30.55635    4.493400  2.9406568   5.867303
#> 9   9 210.8836 328.2157  931 149.46804   18.443562  7.4482266  30.835115
#> 11 11 280.2642 324.0308  273  65.52691    9.119452  5.3467341  13.132584
#> 12 12 347.0320 334.8117  296  67.11270    9.408209  5.4714532  12.740082
#> 15 15 183.7873 384.4777 1874 191.61017   24.952057 12.7563933  38.607157
#> 16 16 333.3174 369.2880  157  47.28427    6.740660  4.4181444   9.160786
#> 17 17 249.6458 376.2982  150  48.04163    6.685175  3.2985429   9.627560
#> 19 19 172.3394 449.2304 2257 280.17872   28.642655 12.4966606  47.520650
#> 23 23 109.3029 464.0800  270  73.87006    8.988493  3.1986297  14.066204
#> 24 24 122.7087 492.3405  944 135.22540   17.989528  9.6344341  28.477918
#> 25 25 149.0979 520.1983 1290 163.71068   21.111421 11.1121614  32.901488
#>     radius_sd diam_mean  diam_min  diam_max  maj_axis  min_axis    length
#> 1  11.1474417  45.05692  1.076431  78.63566 24.227220  6.643255  76.75307
#> 2   9.0162732  40.95375  3.678770  77.88176 19.614073 10.747983  66.40182
#> 3  25.4928036 100.23056  2.226133 188.98676 54.703297 12.938755 185.17085
#> 4  10.1958124  48.12329  1.405520  85.07920 22.449527 13.359497  74.39228
#> 5   1.2434193  12.72677  8.489785  17.02095  5.321827  3.698888  15.67651
#> 6   1.0637511  10.66514  6.433584  14.07469  4.252230  3.384249  12.99561
#> 8   0.8173853   8.98680  5.881314  11.73461  3.698139  2.675405  11.06827
#> 9   6.4438543  36.88712 14.896453  61.67023 17.898543  7.811107  60.30167
#> 11  2.1261027  18.23890 10.693468  26.26517  7.992634  4.870648  25.13821
#> 12  2.0652271  18.81642 10.942906  25.48016  8.101090  5.203807  24.99819
#> 15  7.4642452  49.90411 25.512787  77.21431 22.990122 12.224757  73.66377
#> 16  1.3562801  13.48132  8.836289  18.32157  5.654228  3.906368  17.23651
#> 17  1.7034990  13.37035  6.597086  19.25512  5.934647  3.507754  18.37485
#> 19  9.9375248  57.28531 24.993321  95.04130 26.434992 14.830291  87.43821
#> 23  2.9371608  17.97699  6.397259  28.13241  8.204816  4.687446  26.08266
#> 24  5.6564284  35.97906 19.268868  56.95584 16.961083  8.226107  54.39177
#> 25  6.0355596  42.22284 22.224323  65.80298 19.277879 10.499071  62.92578
#>        width
#> 1  22.623467
#> 2  37.671607
#> 3  46.068949
#> 4  46.469070
#> 5  10.706598
#> 6   9.918685
#> 8   7.973940
#> 9  23.658170
#> 11 14.869865
#> 12 15.182034
#> 15 34.943737
#> 16 11.594961
#> 17 10.717044
#> 19 54.127599
#> 23 13.996525
#> 24 22.453211
#> 25 32.819235
res4$statistics
#>        stat      value
#> 1         n    17.0000
#> 2  min_area    74.0000
#> 3 mean_area   983.4706
#> 4  max_area  3740.0000
#> 5   sd_area  1004.5205
#> 6  sum_area 16719.0000

Interactive disease measurements

An alternative approach to measuring disease percentage is available through the measure_disease_iter() function. This function offers an interactive interface that empowers users to manually select sample colors directly from the image. By doing so, it provides a highly customizable analysis method.

One advantage of using measure_disease_iter() is the ability to utilize the “mapview” viewer, which enhances the analysis process by offering zoom-in options. This feature allows users to closely examine specific areas of the image, enabling detailed inspection and accurate disease measurement.

img <- image_pliman("sev_leaf.jpg", plot = TRUE)
measure_disease_iter(img, viewer = "mapview")

A little bit more!

At this link you will find more examples on how to use {pliman} to analyze plant images. Source code and images can be downloaded here. You can also find a talk (Portuguese language) about {pliman} here. Lights, camera, {pliman}!