Learn R Programming

rcaiman (version 2.0.1)

binarize_by_region: 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)

Value

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

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 Leblanc2005rcaiman.

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 isodata;textualrcaiman, which is among the most recommended for canopy photography Jonckheere2005rcaiman.

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 Macfarlane2011;textualrcaiman. Since this method tend to fail, the fallback is thr_isodata

References

Examples

Run this code
if (FALSE) {
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)
}

Run the code above in your browser using DataLab