This function calls measure_disease()
in each image polygon of a shapefile
object generated with image_shp()
and bind the results into read-ready data
frames.
Usage
measure_disease_shp(
img,
nrow = 1,
ncol = 1,
buffer_x = 0,
buffer_y = 0,
prepare = FALSE,
viewer = "mapview",
index_lb = "HUE2",
index_dh = "NGRDI",
pattern = NULL,
threshold = NULL,
invert = FALSE,
dir_original = NULL,
show_features = FALSE,
interactive = FALSE,
plot = TRUE,
parallel = FALSE,
workers = NULL,
verbose = TRUE,
...
)
Arguments
- img
The image to be analyzed. Either an image of class
Image
or a character string containing the image name. In the last, the image will be searched in the root directory. Declare dir_original to inform a subfolder that contains the images to be processed.- nrow, ncol
The number of rows and columns to generate the shapefile. Defaults to
1
.- buffer_x, buffer_y
Buffering factor for the width and height, respectively, of each individual shape's side. A value between 0 and 0.5 where 0 means no buffering and 0.5 means complete buffering (default: 0). A value of 0.25 will buffer the shape by 25% on each side.
- prepare
Logical value indicating whether to prepare the image for analysis using
image_prepare()
function. This allows to align and crop the image before processing. Defaults toFALSE
.- viewer
The viewer option. If not provided, the value is retrieved using
get_pliman_viewer()
. This option controls the type of viewer to use for interactive plotting. The available options are "base" and "mapview". If set to "base", the base R graphics system is used for interactive plotting. If set to "mapview", the mapview package is used. To set this argument globally for all functions in the package, you can use theset_pliman_viewer()
function. For example, you can runset_pliman_viewer("mapview")
to set the viewer option to "mapview" for all functions.- index_lb
The index used to segment the foreground (e.g., leaf) from the background. If not declared, the entire image area (pixels) will be considered in the computation of the severity.
- index_dh
The index used to segment diseased from healthy tissues when
img_healthy
andimg_symptoms
are not declared. Defaults to"GLI"
. Seeimage_index()
for more details.- pattern
A pattern of file name used to identify images to be processed. For example, if
pattern = "im"
all images that the name matches the pattern (e.g., img1.-, image1.-, im2.-) will be analyzed. Providing any number as pattern (e.g.,pattern = "1"
) will select images that are named as 1.-, 2.-, and so on.- threshold
By default (
threshold = NULL
), a threshold value based on Otsu's method is used to reduce the grayscale image to a binary image. If a numeric value is informed, this value will be used as a threshold. Inform any non-numeric value different than "Otsu" to iteratively choose the threshold based on a raster plot showing pixel intensity of the index. Must be a vector of length 2 to indicate the threshold forindex_lb
andindex_dh
, respectively.- invert
Inverts the binary image if desired. This is useful to process images with black background. Defaults to
FALSE
.- dir_original
The directory containing the original and processed images. Defaults to
NULL
. In this case, the function will search for the imageimg
in the current working directory.- show_features
If
TRUE
returnS the lesion features such as number, area, perimeter, and radius. Defaults toFALSE
.- interactive
If
FALSE
(default) the grid is created automatically based on the image dimension and number of rows/columns. Ifinteractive = TRUE
, users must draw points at the diagonal of the desired bounding box that will contain the grid.- plot
Show image after processing? Defaults to
TRUE
.- parallel
Processes the images asynchronously (in parallel) in separate R sessions running in the background on the same machine. It may speed up the processing time, especially when
pattern
is used is informed. The number of sections is set up to 30% of available cores.- workers
A positive numeric scalar or a function specifying the maximum number of parallel processes that can be active at the same time.
- verbose
If
TRUE
(default) a summary is shown in the console.- ...
Aditional arguments passed on to measure_disease.
Value
An object of class plm_disease_byl
. See more details in the Value
section of measure_disease()
.
Examples
if (interactive() && requireNamespace("EBImage")) {
# severity for the three leaflets (from left to right)
img <- image_pliman("mult_leaves.jpg", plot = TRUE)
sev <-
measure_disease_shp(img = img,
nrow = 1,
ncol = 3,
index_lb = "B",
index_dh = "NGRDI")
sev$severity
}
#> img x y healthy symptomatic
#> plot_1 shp1 158.5 224 80.65540 19.34460
#> plot_2 shp2 475.5 224 84.82250 15.17750
#> plot_3 shp3 792.5 224 68.38966 31.61034