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,
  opening = FALSE,
  closing = FALSE,
  filter = FALSE,
  erode = FALSE,
  dilate = 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. If segment_objects = FALSE, the objects are not segmented and the entire image is analyzed (useful for whole-canopy indices).

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 index for conversion to binary image.

r, g, b, re, nir

The red, green, blue, red-edge, and near-infrared bands, respectively.

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.

workers

Number of parallel processes.

watershed

If TRUE (default) performs watershed-based object detection.

opening, closing, filter, erode, dilate

Morphological operations (brush size), applied in hierarchical order.

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.

object_index

If informed, the average index value for each object is returned.

veins

Logical argument indicating whether vein features are computed per object.

width_at

Logical. If TRUE, widths at quantiles of height are computed.

verbose

If TRUE (default) shows progress summary in console.

invert

Inverts the binary image if desired.

...

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 (FALSE) { # 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")
}