binarize_by_region: Regional thresholding of greyscale images

View source: R/binarize_by_region.R

binarize_by_regionR Documentation

Regional thresholding of greyscale images

Description

Perform thresholding of greyscale images by applying a method regionally, using a segmentation map.

Usage

binarize_by_region(r, segmentation, method)

Arguments

r

numeric terra::SpatRaster of one layer. Typically the blue channel of a canopy photograph.

segmentation

numeric terra::SpatRaster of one layer. A labeled segmentation map defining the regions over which to apply the thresholding method. Ring segmentation (see ring_segmentation()) is often preferred for fisheye images \insertCiteLeblanc2005rcaiman.

method

character vector of length one. Name of the thresholding method to apply. See Details.

Details

This function supports several thresholding methods applied within the regions defined by segmentation:

Methods from the autothresholdr package:

Any method supported by autothresholdr::auto_thresh() can be used by specifying its name. For example, "IsoData" applies the classic iterative intermeans algorithm \insertCiteisodata;textualrcaiman, which is among the most recommended for canopy photography \insertCiteJonckheere2005rcaiman.

In-package implementation of IsoData:

Use "thr_isodata" to apply thr_isodata(), a native implementation of the same algorithm

Two-corner method:

Use "thr_twocorner" to apply thr_twocorner(), which implements a geometric thresholding strategy based on identifying inflection points in the histogram, first introduced to canopy photography by \insertCiteMacfarlane2011;textualrcaiman. Since this method tend to fail, the fallback is thr_isodata

Value

Logical terra::SpatRaster (TRUE for sky, FALSE for non-sky) of the same dimensions as r.

Note

When methods from the autothresholdr package are used, r values should be constrained to the range [0, 1]. See normalize_minmax().

References

\insertAllCited

Examples

## Not run: 
path <- system.file("external/DSCN4500.JPG", package = "rcaiman")
zenith_colrow <- c(1276, 980)
diameter <- 756*2
caim <- read_caim(path, zenith_colrow - diameter/2, diameter, diameter)
z <- zenith_image(ncol(caim), lens("Nikon_FCE9"))
r <- invert_gamma_correction(caim$Blue)
r <- correct_vignetting(r, z, c(0.0638, -0.101)) %>% normalize_minmax()
rings <- ring_segmentation(z, 15)
bin <- binarize_by_region(r, rings, "thr_isodata")
plot(bin)

## End(Not run)

rcaiman documentation built on Sept. 9, 2025, 5:42 p.m.