Learn R Programming

rcaiman (version 1.2.2)

apply_thr: Apply threshold

Description

Global or local thresholding of images.

Usage

apply_thr(r, thr)

Value

An object of class SpatRaster with values 0 and 1.

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.

See Also

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

Examples

Run this code
r <- read_caim()
bin <- apply_thr(r$Blue, thr_isodata(r$Blue[]))
plot(bin)
if (FALSE) {
# 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)
}

Run the code above in your browser using DataLab