fit_trend_surface: Fit a trend surface to sky digital numbers

View source: R/fit_trend_surface.R

fit_trend_surfaceR Documentation

Fit a trend surface to sky digital numbers

Description

Fit a trend surface using spatial::surf.ls() as workhorse function.

Usage

fit_trend_surface(r, z, a, bin, filling_source = NULL, np = 6)

Arguments

r

SpatRaster. A normalized greyscale image. Typically, the blue channel extracted from a canopy photograph. Please see read_caim() and normalize().

z

SpatRaster built with zenith_image().

a

SpatRaster built with azimuth_image().

bin

SpatRaster. This should be a preliminary binarization of r useful for masking pixels that are very likely pure sky pixels.

filling_source

SpatRaster. An actual or reconstructed above-canopy image to complement the sky pixels detected through the gaps of r. A photograph taken immediately after or before taking r under the open sky with the same equipment and configuration is a very good option but not recommended under fleeting clouds. The orientation relative to the North must be the same as for r. If it is set to NULL (default), only sky pixels from r will be used as input.

np

degree of polynomial surface

Details

This function is meant to be used after fit_coneshaped_model().

This method was presented in \insertCiteDiaz2018;textualrcaiman, under the heading Estimation of the sky DN as a previous step for our method. If you use this function in your research, please cite that paper in addition to this package (⁠citation("rcaiman"⁠).

Value

A list with an object of class SpatRaster and of class trls (see spatial::surf.ls()).

Note

If an incomplete above-canopy image is available as filling source, non-sky pixels should be turned NA or they will be erroneously considered as sky pixels.

References

\insertAllCited

See Also

thr_mblt()

Other Sky Reconstruction Functions: cie_sky_model_raster(), fit_cie_sky_model(), fit_coneshaped_model(), fix_reconstructed_sky(), interpolate_sky_points(), 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 = 5)
plot(bin)
points(sky_points$col, nrow(caim) - sky_points$row, col = 2, pch = 10)
rl <- extract_rl(r, z, a, sky_points)

model <- fit_coneshaped_model(rl$sky_points)
summary(model$model)
sky_cs <- model$fun(z, a)
persp(terra::aggregate(sky_cs, 10), theta = 90, phi = 45)

sky_s <- fit_trend_surface(r, z, a, bin, sky_cs)
persp(terra::aggregate(sky_s$image, 10), theta = 90, phi = 45)

## End(Not run)

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