extract_dn: Extract digital numbers

View source: R/extract_dn.R

extract_dnR Documentation

Extract digital numbers

Description

It is a wrapper function around extract.

Usage

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

Arguments

r

SpatRaster.

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 sky 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, which 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.

See Also

Other Tool Functions: colorfulness(), defuzzify(), extract_feature(), extract_rl(), extract_sky_points(), masking(), read_bin(), read_caim(), write_bin(), write_caim()

Examples

## Not run: 
caim <- read_caim()
r <- gbc(caim$Blue)
bin <- apply_thr(r, thr_isodata(r[]))
z <- zenith_image(ncol(caim), lens("Nikon_FCE9"))
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)
sky_points <- extract_sky_points(r, bin, g)
sky_points

## End(Not run)

# ImageJ can be used to digitize points.
# See calc_zenith_raster_coord() for details.
path <- system.file("external/b4_2_5724.jpg", package = "rcaiman")
caim <- read_caim(path)
plot(caim)
path <- system.file("external/points_over_perimeter.csv",
                     package = "rcaiman")
img_points <- read.csv(path)
img_points <- img_points[,c(ncol(img_points), ncol(img_points)-1)]
colnames(img_points) <- c("row", "col")
head(img_points)
v <- cellFromRowCol(caim, img_points$row, img_points$col) %>%
  xyFromCell(caim, .) %>% vect()
plot(v, add = TRUE, col = 2)
extract_dn(caim, img_points, fun = median)

rcaiman documentation built on Sept. 20, 2022, 1:05 a.m.

Related to extract_dn in rcaiman...