interpolate_sky_points: Interpolate sky points

View source: R/interpolate_sky_points.R

interpolate_sky_pointsR Documentation

Interpolate sky points

Description

Interpolate values from canopy photographs.

Usage

interpolate_sky_points(sky_points, r, k = 3, p = 2, rmax = 200, col_id = "rl")

Arguments

sky_points

An object of class data.frame. The data.frame returned by extract_rl() or extract_dn(), or a data.frame with same basic structure and names.

r

SpatRaster. The image from which sky_points was obtained.

k

Numeric vector of length one. Number of k-nearest neighbors.

p

Numeric vector of length one. Power for inverse-distance weighting.

rmax

Numeric vector of length one. Maximum radius where to search for knn.

col_id

Numeric vector of length one. ID of the column with the values to interpolate.

Details

This function use lidR::knnidw() as workhorse function, so arguments k, p, and rmax are passed to it.

This function is based on \insertCiteLang2010;textualrcaiman. In theory, the best result would be obtained with data showing a linear relation between digital numbers and the amount of light reaching the sensor. See extract_radiometry() and read_caim_raw() for further details. As a compromise solution, gbc() can be used.

Default parameters are the ones used by \insertCiteLang2010;textualrcaiman. The argument rmax should account for between 15 to 20 degrees, but it is expressed in pixels units. So, image resolution and lens projections should be taken into account to set this argument properly.

Value

An object of class SpatRaster.

References

\insertAllCited

See Also

Other Sky Reconstruction Functions: cie_sky_model_raster(), fit_cie_sky_model(), fit_coneshaped_model(), fit_trend_surface(), fix_reconstructed_sky(), ootb_sky_reconstruction()

Examples

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

bin <- ootb_obia(caim, z, a, m, HSV(239, 0.85, 0.5), gamma = NULL)

g <- sky_grid_segmentation(z, a, 10)
sky_points <- extract_sky_points(r, bin, g, dist_to_plant = 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_sky_points(sky_points, r, col_id = 3)
plot(sky)
plot(r/sky)

# A quick demonstration of how to use trend surface fitting to smooth the
# interpolation
persp(terra::aggregate(sky, 10), theta = 45, phi = 30)
sky_s <- fit_trend_surface(sky, z, a, !is.na(z))
persp(terra::aggregate(sky_s$image, 10), theta = 45, phi = 30)
plot(sky_s$image)
plot(r)
plot(r/sky_s$image)
plot(apply_thr(r/sky_s$image, 0.5))

## End(Not run)

rcaiman documentation built on Nov. 15, 2023, 1:08 a.m.