extract_dn: Extract digital numbers

View source: R/extract_dn.R

extract_dnR Documentation

Extract digital numbers

Description

Wrapper function around terra::extract().

Usage

extract_dn(r, img_points, use_window = TRUE, fun = NULL)

Arguments

r

SpatRaster. A fish-eye image.

img_points

The result of a call to extract_sky_points(), or an object of the same class and structure.

use_window

Logical vector of length one. If TRUE, a 3 \times 3 window will be used to extract the digital number from r.

fun

A function that takes a vector as input and returns a one-length numeric or logical vector as output (e.g. mean).

Value

An object of the class data.frame. It is the argument img_points with an added column per each layer from r. The layer names are used to name the new columns. If a function is provided as the fun argument, the result will be summarized per column using the provided function, and the row and col information will be omitted. Moreover, if r is an RGB image, a color will be returned instead of a data.frame. The latter feature is useful for obtaining the sky_blue argument for enhance_caim().

Note

The point selection tool of ‘ImageJ’ software can be used to manually digitize points and create a CSV file from which to read coordinates (see Examples). After digitizing the points on the image, use the dropdown menu Analyze>Measure to open the Results window. To obtain the CSV file, use File>Save As...

See Also

Other Tool Functions: colorfulness(), correct_vignetting(), defuzzify(), extract_feature(), extract_rl(), extract_sky_points_simple(), extract_sky_points(), extract_sun_coord(), find_sky_pixels_nonnull(), find_sky_pixels(), masking(), optim_normalize(), percentage_of_clipped_highlights(), read_bin(), read_caim_raw(), read_caim(), write_bin(), write_caim()

Examples

## Not run: 
caim <- read_caim()
r <- caim$Blue
bin <- apply_thr(r, thr_isodata(r[]))
z <- zenith_image(ncol(caim), lens())
a <- azimuth_image(z)
g <- sky_grid_segmentation(z, a, 10)
sky_points <- extract_sky_points(r, bin, g)
sky_points <- extract_dn(caim, sky_points)
head(sky_points)

# ImageJ can be used to digitize points
path <- system.file("external/sky_points.csv",
                    package = "rcaiman")
sky_points <- read.csv(path)
sky_points <- sky_points[c("Y", "X")]
colnames(sky_points) <- c("row", "col")
head(sky_points)
plot(bin)
points(sky_points$col, nrow(caim) - sky_points$row, col = 2, pch = 10)
extract_dn(caim, sky_points, fun = median)

## End(Not run)

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