zonalDT: Calculate aggregated statistics by each image segment or...

View source: R/SOptim_CalcSegmentStats.R

zonalDTR Documentation

Calculate aggregated statistics by each image segment or region

Description

Calculate statistics for each element (e.g., a segment, object or region) based on data.table objects (much faster processing!).

Usage

zonalDT(x, z, fun, na.rm = TRUE, subset = NULL, ...)

## Default S3 method:
zonalDT(x, z, fun, na.rm = TRUE, subset = NULL, ...)

## S3 method for class 'data.frame'
zonalDT(x, z, fun, na.rm = TRUE, subset = NULL, ...)

## S3 method for class 'SpatRaster'
zonalDT(x, z, fun, na.rm = TRUE, subset = NULL, ...)

## S3 method for class 'matrix'
zonalDT(x, z, fun, na.rm = TRUE, subset = NULL, ...)

Arguments

x

An object of class data.frame, matrix or SpatRaster containing data (e.g., classification features).

z

An object of class SpatRaster, vector, or a one column data.frame/matrix containing segment/object/zone indices (as integers). Usually the result of a image segmentation algorithm.

fun

An aggregation function (e.g., mean) applied to the elements within each segment. Either a function object or a function name.

na.rm

A boolean defining whether or not to remove NA values (default: TRUE).

subset

A vector defining which rows should be subset from z (zones or regions).

...

Further parameters to pass to lapply.

Value

A data.table object containing statistics by segment.

Note

Both object must have exactly the same number of elements. For example, if x and z are raster datasets these must have equal number of rows/columns, extent and coordinate reference system. If x is a data.frame or matrix then the number of cells in z must equal the number of rows in x.


joaofgoncalves/SegOptim documentation built on Feb. 5, 2024, 11:10 p.m.