image_index: Image indexes

View source: R/utils_imagem.R

image_indexR Documentation

Image indexes

Description

image_index() Builds image indexes using Red, Green, Blue, Red-Edge, and NIR bands.

Generates a raster or density plot of the index values computed with image_index().

Usage

image_index(
  img,
  index = NULL,
  r = 1,
  g = 2,
  b = 3,
  re = 4,
  nir = 5,
  return_class = c("ebimage", "terra"),
  resize = FALSE,
  has_white_bg = FALSE,
  plot = TRUE,
  nrow = NULL,
  ncol = NULL,
  max_pixels = 1e+05,
  parallel = FALSE,
  workers = NULL,
  verbose = TRUE,
  ...
)

## S3 method for class 'image_index'
plot(x, type = c("raster", "density"), nrow = NULL, ncol = NULL, ...)

Arguments

img

An Image object. Multispectral mosaics can be converted to an Image object using mosaic_as_ebimage().

index

A character value (or a vector of characters) specifying the target mode for conversion to a binary image. Use pliman_indexes() or the details section to see the available indexes. Defaults to NULL (normalized Red, Green, and Blue). You can also use "RGB" for RGB only, "NRGB" for normalized RGB, "MULTISPECTRAL" for multispectral indices (provided NIR and RE bands are available) or "all" for all indexes. Users can also calculate their own index using the band names, e.g., index = "R+B/G".

r, g, b, re, nir

The red, green, blue, red-edge, and near-infrared bands of the image, respectively. Defaults to 1, 2, 3, 4, and 5, respectively. If a multispectral image is provided (5 bands), check the order of bands, which are frequently presented in the 'BGR' format.

return_class

The class of object to be returned. If ⁠"terra⁠ returns a SpatRaster object with the number of layers equal to the number of indexes computed. If "ebimage" (default) returns a list of Image objects, where each element is one index computed.

resize

Resize the image before processing? Defaults to resize = FALSE. Use resize = 50, which resizes the image to 50% of the original size to speed up image processing.

has_white_bg

Logical indicating whether a white background is present. If TRUE, pixels that have R, G, and B values equals to 1 will be considered as NA. This may be useful to compute an image index for objects that have, for example, a white background. In such cases, the background will not be considered for the threshold computation.

plot

Show image after processing?

nrow, ncol

The number of rows or columns in the plot grid. Defaults to NULL, i.e., a square grid is produced.

max_pixels

integer > 0. Maximum number of cells to plot the index. If max_pixels < npixels(img), downsampling is performed before plotting the index. Using a large number of pixels may slow down the plotting time.

parallel

Processes the images asynchronously (in parallel) in separate R sessions running in the background on the same machine. It may speed up the processing time when image is a list. The number of sections is set up to 70% of available cores.

workers

A positive numeric scalar or a function specifying the maximum number of parallel processes that can be active at the same time.

verbose

If TRUE (default) a summary is shown in the console.

...

Additional arguments passed to plot_index() for customization.

x

An object of class image_index.

type

The type of plot. Use type = "raster" (default) to produce a raster plot showing the intensity of the pixels for each image index or type = "density" to produce a density plot with the pixels' intensity.

Details

The following indexes are available in pliman.

  • RGB color space

  • R red

  • G green

  • B blue

  • NR normalized red R/(R+G+B).

  • NG normalized green G/(R+G+B)

  • NB normalized blue B/(R+G+B)

  • GB green blue ratio G/B

  • RB red blue ratio R/B

  • GR green red ratio G/R

  • BI brightness Index sqrt((R^2+G^2+B^2)/3)

  • BIM brightness Index 2 sqrt((R*2+G*2+B*2)/3)

  • SCI Soil Colour Index (R-G)/(R+G)

  • GLI Green leaf index Vis Louhaichi et al. (2001) (2*G-R-B)/(2*G+R+B)

  • HI Primary colours Hue Index (2*R-G-B)/(G-B)

  • NDGRI Normalized green red difference index (Tucker, 1979) (G-R)/(G+R)

  • NDGBI Normalized green blue difference index (G-B)/(G+B)

  • NDRBI Normalized red blue difference index (R-B)/(R+B)

  • I R+G+B

  • S ((R+G+B)-3*B)/(R+G+B)

  • L R+G+B/3

  • VARI A Visible Atmospherically Resistant Index (G-R)/(G+R-B)

  • HUE Overall Hue Index atan(2*(B-G-R)/30.5*(G-R))

  • HUE2 atan(2*(R-G-R)/30.5*(G-B))

  • BGI B/G

  • GRAY 0.299*R + 0.587*G + 0.114*B

  • GRAY2 ((R^2.2+(1.5*G)^2.2+(0.6*B)^2.2)/(1+1.5^2.2+0.6^2.2))^1/2.2

  • GLAI (25*(G-R)/(G+R-B)+1.25)

  • CI Coloration Index (R-B)/R

  • SAT Overhall Saturation Index (max(R,G,B) - min(R,G,B)) / max(R,G,B)

  • SHP Shape Index 2*(R-G-B)/(G-B)

  • RI Redness Index R**2/(B*G**3)

  • HSB color space

  • DGCI Dark Green Color Index, based on HSB color space ⁠60\*((G - B) / (max(R, G, B) - min(R, G, B)))⁠

  • CIE-Lab color space

  • ⁠L*⁠: relative luminance (0.2126 * R + 0.7152 * G + 0.0722 * B)

  • ⁠a*⁠: 0.55*( (R - (0.2126 * R + 0.7152 * G + 0.0722 * B)) / (1.0 - 0.2126))

When type = "raster" (default), the function calls plot_index() to create a raster plot for each index present in x. If type = "density", a for loop is used to create a density plot for each index. Both types of plots can be arranged in a grid controlled by the ncol and nrow arguments.

Value

A list containing Grayscale images. The length will depend on the number of indexes used.

A NULL object

Author(s)

Tiago Olivoto tiagoolivoto@gmail.com

References

Nobuyuki Otsu, "A threshold selection method from gray-level histograms". IEEE Trans. Sys., Man., Cyber. 9 (1): 62-66. 1979. \Sexpr[results=rd]{tools:::Rd_expr_doi("10.1109/TSMC.1979.4310076")}

Examples

library(pliman)
img <- image_pliman("soybean_touch.jpg")
image_index(img, index = c("R, NR"))

# Example for S3 method plot()
library(pliman)
img <- image_pliman("sev_leaf.jpg")
# compute the index
ind <- image_index(img, index = c("R, G, B, NGRDI"), plot = FALSE)
plot(ind)

# density plot
plot(ind, type = "density")

pliman documentation built on Oct. 15, 2023, 1:06 a.m.

Related to image_index in pliman...