correct_vignetting: Correct vignetting effect

View source: R/correct_vignetting.R

correct_vignettingR Documentation

Correct vignetting effect

Description

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

Usage

correct_vignetting(r, z, lens_coef_v)

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.

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

Examples

## Not run: 
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()

## End(Not run)

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