extract_sky_points: Extract sky points

View source: R/extract_sky_points.R

extract_sky_pointsR Documentation

Extract sky points

Description

Sample representative sky pixels for use in model fitting or interpolation.

Usage

extract_sky_points(r, bin, g, dist_to_black = 3, method = "grid")

Arguments

r

numeric terra::SpatRaster of one layer. Typically the blue band of a canopy image.

bin

logical terra::SpatRaster of one layer. Binary image where TRUE marks candidate sky pixels. Typically the output of binarize_with_thr().

g

numeric terra::SpatRaster of one layer. Segmentation grid, usually built with sky_grid_segmentation() or chessboard(). Ignored when method = "local_max".

dist_to_black

numeric vector of length one or NULL. Minimum distance (pixels) to the nearest black pixel for a candidate sky pixel to be valid. If NULL, no distance constraint is applied.

method

character vector of length one. Sampling method; either "grid" (default) or "local_max".

Details

Two sampling strategies are provided:

"grid"

select one sky point per cell of a segmentation grid (g) as the brightest pixel marked TRUE in bin, provided the cell’s white pixel count exceeds one fourth of the mean across valid cells.

"local_max"

detect local maxima within a fixed 9 \times 9 window, restricted to pixels marked TRUE in bin, after removing patches of connected TRUE pixels that are implausible based on fixed area/size thresholds. Each detected maximum is taken as a sky point.

Use "grid" to promote an even, representative spatial distribution (good for model fitting), and "local_max" to be exhaustive for interpolation.

Value

data.frame with columns row and col.

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)

## End(Not run)

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