Skip to contents

Analyzes objects using shapefiles

Usage

analyze_objects_shp(
  img,
  nrow = 1,
  ncol = 1,
  buffer_x = 0,
  buffer_y = 0,
  prepare = FALSE,
  segment_objects = TRUE,
  viewer = get_pliman_viewer(),
  index = "R",
  r = 1,
  g = 2,
  b = 3,
  re = 4,
  nir = 5,
  shapefile = NULL,
  interactive = FALSE,
  plot = FALSE,
  parallel = FALSE,
  workers = NULL,
  watershed = TRUE,
  filter = FALSE,
  object_size = "medium",
  efourier = FALSE,
  object_index = NULL,
  veins = FALSE,
  width_at = FALSE,
  verbose = TRUE,
  invert = FALSE,
  ...
)

Arguments

img

An Image object

nrow, ncol

The number of rows and columns to generate the shapefile when shapefile is not declared. 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. Defaults to FALSE. Set to TRUE to interactively align and crop the image before processing.

segment_objects

Segment objects in the image? Defaults to TRUE. In this case, objects are segmented using the index defined in the index argument, and each object is analyzed individually. If segment_objects = FALSE is used, the objects are not segmented and the entire image is analyzed. This is useful, for example, when analyzing an image without background, where an object_index could be computed for the entire image, like the index of a crop canopy.

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 the set_pliman_viewer() function. For example, you can run set_pliman_viewer("mapview") to set the viewer option to "mapview" for all functions.

index

A character value specifying the target mode for conversion to binary image when foreground and background are not declared. Defaults to "NB" (normalized blue). See image_index() for more details. User can also calculate your own index using the bands names, e.g. index = "R+B/G"

r, g, b, re, nir

The red, green, blue, red-edge, and near-infrared bands of the image, respectively. Defaults to 1, 2, 3, 4, and 5, respectively. If a multispectral image is provided (5 bands), check the order of bands, which are frequently presented in the 'BGR' format.

shapefile

(Optional) An object created with image_shp(). If NULL (default), both nrow and ncol must be declared.

interactive

If FALSE (default) the grid is created automatically based on the image dimension and number of nrow/columns. If interactive = TRUE, users must draw points at the diagonal of the desired bounding box that will contain the grid.

plot

Plots the processed images? Defaults to FALSE.

parallel

If TRUE 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. When object_index is informed, multiple sections will be used to extract the RGB values for each object in the image. This may significantly speed up processing time when an image has lots of objects (say >1000).

workers

A positive numeric scalar or a function specifying the number of parallel processes that can be active at the same time. By default, the number of sections is set up to 30% of available cores.

watershed

If TRUE (default) performs watershed-based object detection. This will detect objects even when they are touching one other. If FALSE, all pixels for each connected set of foreground pixels are set to a unique object. This is faster but is not able to segment touching objects.

filter

Performs median filtering in the binary image? See more at image_filter(). Defaults to FALSE. Use a positive integer to define the size of the median filtering. Larger values are effective at removing noise, but adversely affect edges.

object_size

Argument to control control the watershed segmentation. See analyze_objects() for more details.

efourier

Logical argument indicating if Elliptical Fourier should be computed for each object. This will call efourier() internally. It efourier = TRUE is used, both standard and normalized Fourier coefficients are returned.

object_index

Defaults to FALSE. If an index is informed, the average value for each object is returned. It can be the R, G, and B values or any operation involving them, e.g., object_index = "R/B". In this case, it will return for each object in the image, the average value of the R/B ratio. Use pliman_indexes_eq() to see the equations of available indexes.

veins

Logical argument indicating whether vein features are computed. This will call object_edge() and applies the Sobel-Feldman Operator to detect edges. The result is the proportion of edges in relation to the entire area of the object(s) in the image. Note that THIS WILL BE AN OPERATION ON AN IMAGE LEVEL, NOT OBJECT!.

width_at

Logical. If TRUE, the widths of the object at a given set of quantiles of the height are computed.

verbose

If TRUE (default) a summary is shown in the console.

invert

Inverts the binary image if desired. This is useful to process images with a black background. Defaults to FALSE. If reference = TRUE is use, invert can be declared as a logical vector of length 2 (eg., invert = c(FALSE, TRUE). In this case, the segmentation of objects and reference from the foreground using back_fore_index is performed using the default (not inverted), and the segmentation of objects from the reference is performed by inverting the selection (selecting pixels higher than the threshold).

...

Aditional arguments passed on to analyze_objects.

Value

An object of class anal_obj. See more details in the Value

section of analyze_objects().

Details

The analyze_objects_shp function performs object analysis on an image and generates shapefiles representing the analyzed objects. The function first prepares the image for analysis using the image_prepare() function if the prepare argument is set to TRUE. If a shapefile object is provided, the number of rows and columns for splitting the image is obtained from the shapefile. Otherwise, the image is split into multiple sub-images based on the specified number of rows and columns using the object_split_shp() function. The objects in each sub-image are analyzed using the analyze_objects() function, and the results are stored in a list. If parallel processing is enabled, the analysis is performed in parallel using multiple workers.

The output object provides access to various components of the analysis results, such as the analyzed object coordinates and properties. Additionally, the shapefiles representing the analyzed objects are included in the output object for further analysis or visualization.

Examples

if(interactive()){
library(pliman)

# Computes the DGCI index for each flax leaf
flax <- image_pliman("flax_leaves.jpg", plot =TRUE)
res <-
   analyze_objects_shp(flax,
                       nrow = 3,
                       ncol = 5,
                       plot = FALSE,
                       object_index = "DGCI")
plot(flax)
plot(res$shapefiles)
plot_measures(res, measure = "DGCI")
}