Learn R Programming

rcaiman (version 2.0.1)

correct_vignetting: Correct vignetting effect

Description

Apply a vignetting correction to an image using a polynomial model.

Usage

correct_vignetting(r, z, lens_coef_v)

Value

terra::SpatRaster with the same content as r but with pixel values adjusted to correct for vignetting, preserving all other properties (layers, names, extent, and CRS).

Arguments

r

terra::SpatRaster of one or more layers (e.g., RGB channels or binary masks) in fisheye projection.

z

terra::SpatRaster generated with zenith_image().

lens_coef_v

numeric vector. Coefficients of the vignetting function \(f_v(\theta) = 1 + a\theta + b\theta^2 + \dots + m\theta^n\), where \(\theta\) is the zenith angle (in radians) and \(a,b,\dots,m\) are the polynomial coefficients. Degrees up to 6 are supported. See extract_radiometry() for guidance on estimating these coefficients.

Details

Vignetting is the gradual reduction of image brightness toward the periphery. This function corrects it by applying a device-specific correction as a function of the zenith angle at each pixel.

Examples

Run this code
if (FALSE) {
path <- system.file("external/APC_0836.jpg", package = "rcaiman")
caim <- read_caim(path)
z <- zenith_image(2132, lens("Olloclip"))
a <- azimuth_image(z)
zenith_colrow <- c(1063, 771)

caim <- expand_noncircular(caim, z, zenith_colrow)
m <- !is.na(caim$Red) & !is.na(z)
caim[!m] <- 0

bin <- binarize_with_thr(caim$Blue, thr_isodata(caim$Blue[m]))
display_caim(caim$Blue, bin)

caim <- invert_gamma_correction(caim, 2.2)
caim <- correct_vignetting(caim, z, c(-0.0546, -0.561, 0.22)) %>%
        normalize_minmax()
}

Run the code above in your browser using DataLab