Quantizes raster to a set number of discrete levelsSource:
Quantizes raster to a set number of discrete levels starting at 0. There are 2 methods of quantization are available: "uniform" and "equal prob"
quantize_raster( r, n_levels, method, min_val = NULL, max_val = NULL, filename = NULL, overwrite = FALSE, wopt = list() )
A single layer SpatRaster or RasterLayer.
number of levels to quantize to
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.
minimum value for equal range quantization (if not supplied, the minimum value of the raster is used)
maximum value for equal range quantization (if not supplied, the maximum value of the raster is used)
character Output filename.
logical. If TRUE, filename is overwritten (default is FALSE).
list with named options for writing files as in writeRaster
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.
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