Quantizes raster to a set number of discrete levels starting at 0. There are 2 methods of quantization are available: "equal range" and "equal prob"
Usage
quantize_raster(
r,
n_levels,
method,
min_val = NULL,
max_val = NULL,
maxcell = Inf,
filename = NULL,
overwrite = FALSE,
wopt = list()
)
Arguments
- r
A single layer SpatRaster or RasterLayer.
- n_levels
number of levels to quantize to
- method
quantization method (either "equal range" or "equal prob"). "equal range" quantization will create bins that cover a range of equal size. "equal prob" performs equal probability quantization and will use quantiles to create bins with approximately equal number of samples.
- min_val
minimum value for equal range quantization (if not supplied, the minimum value of the raster is used)
- max_val
maximum value for equal range quantization (if not supplied, the maximum value of the raster is used)
- maxcell
positive integer used to take a regular sample of x if "equal prob" is used (default is Inf)
- filename
character Output filename.
- overwrite
logical. If TRUE, filename is overwritten (default is FALSE).
- wopt
list with named options for writing files as in writeRaster
Details
Equal probability quantization is the method recommended in Haralick et al., 1973. However, equal range may be more desirable if making comparisons across several different rasters where you need the gray levels to correspond in a consistent way to the original data, as you can supply the global max/min or the theoretical max/min values that could occur. When equal probability quantization is used, quantiles are generated using type 8 as recommended by Hyndman and Fan (1996). This method provides estimates that are approximately median-unbiased regardless of the distribution of x.
References
Haralick, R.M., Shanmugam, K., Dinstein, I., 1973. Textural features for image classification. IEEE Transactions on Systems, Man, and Cybernetics 610–621. https://doi.org/10.1109/TSMC.1973.4309314
Hyndman, R.J., Fan, Y., 1996. Sample Quantiles in Statistical Packages. The American Statistician 50, 361–365. https://doi.org/10.1080/00031305.1996.10473566