Learn R Programming

rcaiman (version 2.0.1)

rem_nearby_points: Remove nearby sky points

Description

Select a subset of points so that no retained pair is closer than min_dist in planar or spherical space.

Usage

rem_nearby_points(
  sky_points,
  r = NULL,
  z = NULL,
  a = NULL,
  min_dist = 3,
  space = "planar",
  use_window = TRUE
)

Value

A data.frame with columns row and col for retained points.

Arguments

sky_points

data.frame with columns row and col (raster coordinates).

r

single-layer terra::SpatRaster or NULL. Optional ranking raster used to prioritize retention (higher values kept first).

z

terra::SpatRaster generated with zenith_image().

a

terra::SpatRaster generated with azimuth_image().

min_dist

numeric vector of length one. Minimum allowed distance between retained points. Units: pixels for "planar", deg for "spherical".

space

character vector of length one. Coordinate system for distances: "planar" (default) or "spherical".

use_window

logical of length one. If TRUE (default), use a \(3 \times 3\) local mean around each point; if FALSE, use only the central pixel.

Details

When space = "planar", distances are computed in image coordinates and z and a are ignored. When space = "spherical", distances are angular (deg) in hemispherical coordinates. If r is provided, points are ranked by the extracted raster values and retained in descending order.

Examples

Run this code
if (FALSE) {
caim <- read_caim()
r <- caim$Blue
z <- zenith_image(ncol(caim), lens())
a <- azimuth_image(z)
bin <- binarize_by_region(r, ring_segmentation(z, 30),
                          method = "thr_isodata")
bin <- bin & select_sky_region(z, 0, 80)
g <- sky_grid_segmentation(z, a, 10, first_ring_different = TRUE)
sky_points <- extract_sky_points(r, bin, g, dist_to_black = 3)

# planar
sky_points_p <- rem_nearby_points(sky_points, r, min_dist = 100,
                                        space = "planar")
plot(r)
points(sky_points$col, nrow(caim) - sky_points$row, col = 2, pch = 10)
points(sky_points_p$col, nrow(caim) - sky_points_p$row, col = 3, pch = 0)

# spherical
sky_points_s <- rem_nearby_points(sky_points, r, z, a, min_dist = 30,
                                        space = "spherical")
plot(r)
points(sky_points$col, nrow(caim) - sky_points$row, col = 2, pch = 10)
points(sky_points_s$col, nrow(caim) - sky_points_s$row, col = 3, pch = 0)
}

Run the code above in your browser using DataLab