apply_thr: Apply threshold

apply_thrR Documentation

Apply threshold

Description

Global or local thresholding of images.

Usage

apply_thr(r, thr)

Arguments

r

SpatRaster. A greyscale image.

thr

Numeric vector of length one or a single-layer raster from the class SpatRaster. Threshold.

Details

It is a wrapper function around the operator > from the terra package. If a single threshold value is provided as the thr argument, it is applied to every pixel of the object r. If instead a SpatRaster is provided, a particular threshold is applied to each particular pixel.

Value

An object of class SpatRaster with values 0 and 1.

See Also

Other Binarization Functions: obia(), ootb_mblt(), ootb_obia(), regional_thresholding(), thr_isodata(), thr_mblt()

Examples

r <- read_caim()
bin <- apply_thr(r$Blue, thr_isodata(r$Blue[]))
plot(bin)
## Not run: 
# This function is useful in combination with the ‘autothresholdr’
# package. For example:
require(autothresholdr)
thr <- auto_thresh(r$Blue[], "IsoData")[1]
bin <- apply_thr(r$Blue, thr)
plot(bin)

## End(Not run)

rcaiman documentation built on Nov. 15, 2023, 1:08 a.m.