| binarize_with_thr | R Documentation |
Apply a threshold or a raster of thresholds to a grayscale image, producing a binary image.
binarize_with_thr(r, thr)
r |
numeric terra::SpatRaster with one layer. |
thr |
either a numeric vector of length one (for global thresholding) or a numeric terra::SpatRaster with one layer (for local thresholding). |
This function supports both global and pixel-wise thresholding. It is a
wrapper around the > operator from the terra package. If a single numeric
threshold is provided via thr, it is applied globally to all pixels in r.
If instead a terra::SpatRaster object is provided, local thresholding
is performed, where each pixel is compared to its corresponding threshold
value.
This is useful after estimating thresholds using thr_twocorner(),
thr_isodata(), or
apply_by_direction(method = "thr_isodata"), among other posibilities.
Logical terra::SpatRaster (TRUE for sky, FALSE for
non-sky) with the same dimensions as r.
For global thresholding, thr must be greater than or equal to the minimum
value of r and lower than its maximum value.
r <- read_caim()
bin <- binarize_with_thr(r$Blue, thr_isodata(r$Blue[]))
plot(bin)
## Not run:
# This function is also compatible with thresholds estimated using
# the 'autothresholdr' package:
require(autothresholdr)
r <- r$Blue
r <- normalize_minmax(r) %>% multiply_by(255) %>% round()
thr <- auto_thresh(r[], "IsoData")[1]
bin <- binarize_with_thr(r, thr)
plot(bin)
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.