interpolate_planar: Interpolate in planar space

View source: R/interpolate_planar.R

interpolate_planarR Documentation

Interpolate in planar space

Description

Interpolate values from canopy photographs using inverse distance weighting (IDW) with k-nearest neighbors in image (planar) coordinates. A radius limits neighbor search.

Usage

interpolate_planar(sky_points, r, k = 3, p = 2, rmax = 200, col_id = "dn")

Arguments

sky_points

data.frame with columns row, col, and one additional numeric column with values to interpolate. Typically returned by extract_rr() or extract_dn().

r

numeric terra::SpatRaster with one layer. Image from which sky_points were derived, or another raster with the same number of rows and columns. Used only as geometric template; cell values are ignored.

k, p, rmax

numeric vector of length one. Parameters passed to lidR::knnidw(): number of neighbors (k), inverse distance weighting exponent (p), and maximum search radius (rmax) in units of the output resolution.

col_id

numeric or character vector of length one. The name or position of the column in sky_points containing the values to interpolate.

Details

Delegates interpolation to lidR::knnidw(), passing k, p, and rmax unchanged. Defaults follow \insertCiteLang2013;textualrcaiman. Note that rmax is given in pixels but intended to approximate 15–20 deg in angular terms. Therefore, this value needs fine-tuning based on image resolution and lens projection. For best results, the interpolated quantity should be linearly related to scene radiance; see extract_radiometry() and read_caim_raw(). For JPEG images, consider invert_gamma_correction() to reverse gamma encoding.

Value

Numeric terra::SpatRaster with one layer and the same geometry as r.

Note

No consistency checks are performed to ensure that sky_points and r are geometrically compatible. Incorrect combinations may lead to invalid outputs.

References

\insertAllCited

Examples

## Not run: 
caim <- read_caim()
z <- zenith_image(ncol(caim), lens())
a <- azimuth_image(z)
m <- !is.na(z)
r <- caim$Blue

bin <- binarize_by_region(r, ring_segmentation(z, 15), "thr_isodata") &
  select_sky_region(z, 0, 88)

g <- sky_grid_segmentation(z, a, 10)
sky_points <- extract_sky_points(r, bin, g, dist_to_black = 3)
plot(bin)
points(sky_points$col, nrow(caim) - sky_points$row, col = 2, pch = 10)
sky_points <- extract_dn(r, sky_points)

sky <- interpolate_planar(sky_points, r, col_id = 3)
plot(sky)
plot(r/sky)

## End(Not run)

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