| Title: | RGB Visible Indices for Image Analysis |
|---|---|
| Description: | Computes RGB-based vegetation, color, and spectral indices from digital images for applications in agriculture, crop phenotyping, and remote sensing. The methods are based on digital image processing and plant phenotyping approaches (Singh et al. (2023) <doi:10.1080/10106049.2022.2160831>). |
| Authors: | RN Singh [aut], Bappa Das [aut], Sonam [aut], Anil Kumar [aut], Santosha Rathod [aut, cre] |
| Maintainer: | Santosha Rathod <[email protected]> |
| License: | MIT + file LICENSE |
| Version: | 0.1.1 |
| Built: | 2026-05-30 10:53:47 UTC |
| Source: | https://github.com/cran/rgbIndices |
Computes basic RGB indices including normalized red (r), green (g), blue (b), and intensity (INT) from an RGB image.
rgb_basic(image)rgb_basic(image)
image |
A RasterBrick or RasterStack object with three bands (R, G, B). |
A RasterStack object with seven layers:
R, G, B: Original red, green, and blue bands
r, g, b: Normalized RGB indices
INT: Intensity component (mean of R, G, B)
set.seed(123) r <- raster::raster(matrix(runif(50*50), 50, 50)) g <- raster::raster(matrix(runif(50*50), 50, 50)) b <- raster::raster(matrix(runif(50*50), 50, 50)) img <- raster::stack(r, g, b) rgb_basic(img)set.seed(123) r <- raster::raster(matrix(runif(50*50), 50, 50)) g <- raster::raster(matrix(runif(50*50), 50, 50)) b <- raster::raster(matrix(runif(50*50), 50, 50)) img <- raster::stack(r, g, b) rgb_basic(img)
Computes multiple RGB-based color indices from a three-band RGB image.
rgb_color(image)rgb_color(image)
image |
A RasterBrick or RasterStack object with three bands (R, G, B). |
A RasterStack object where each layer represents a specific RGB-based color index, including Grey, BI, HI, RI, SI, CI, CIVE, VEG, IPCA, GLAI, SAT, OHI, TCVI, COM1, and COM2.
set.seed(123) r <- raster::raster(matrix(runif(50*50), 50, 50)) g <- raster::raster(matrix(runif(50*50), 50, 50)) b <- raster::raster(matrix(runif(50*50), 50, 50)) img <- raster::stack(r, g, b) rgb_color(img)set.seed(123) r <- raster::raster(matrix(runif(50*50), 50, 50)) g <- raster::raster(matrix(runif(50*50), 50, 50)) b <- raster::raster(matrix(runif(50*50), 50, 50)) img <- raster::stack(r, g, b) rgb_color(img)
Computes difference-based RGB indices from a three-band RGB image.
rgb_diff(image)rgb_diff(image)
image |
A RasterBrick or RasterStack object with three bands (R, G, B). |
A RasterStack object where each layer represents a difference between RGB bands: GRD (G - R), BGD (B - G), RGD (R - G), RBD (R - B), GBD (G - B), and BRD (B - R).
set.seed(123) r <- raster::raster(matrix(runif(50*50), 50, 50)) g <- raster::raster(matrix(runif(50*50), 50, 50)) b <- raster::raster(matrix(runif(50*50), 50, 50)) img <- raster::stack(r, g, b) rgb_diff(img)set.seed(123) r <- raster::raster(matrix(runif(50*50), 50, 50)) g <- raster::raster(matrix(runif(50*50), 50, 50)) b <- raster::raster(matrix(runif(50*50), 50, 50)) img <- raster::stack(r, g, b) rgb_diff(img)
Provides the file path to an example RGB image included in the package. Optionally allows saving the image to a user-specified location.
rgb_example(save_path = NULL)rgb_example(save_path = NULL)
save_path |
Optional file path to save the example image. |
A character string representing the file path to the example RGB image.
# Get example image path img_path <- rgb_example() img_path # Save image to temporary location rgb_example(tempfile(fileext = ".jpg"))# Get example image path img_path <- rgb_example() img_path # Save image to temporary location rgb_example(tempfile(fileext = ".jpg"))
Computes the mean values of RGB-based indices from a RasterBrick or RasterStack object.
rgb_indices_to_mean(x)rgb_indices_to_mean(x)
x |
A RasterBrick or RasterStack object containing RGB indices. |
The function calculates the mean of each layer in the input raster object
using raster::cellStats. The output provides a summary of the indices
for the entire image.
A tibble (data frame) with a single row where each column represents the mean value of an RGB index computed across all pixels.
r <- raster::raster(matrix(runif(50*50), 50, 50)) g <- raster::raster(matrix(runif(50*50), 50, 50)) b <- raster::raster(matrix(runif(50*50), 50, 50)) img <- raster::stack(r, g, b) x <- rgb_basic(img) rgb_indices_to_mean(x)r <- raster::raster(matrix(runif(50*50), 50, 50)) g <- raster::raster(matrix(runif(50*50), 50, 50)) b <- raster::raster(matrix(runif(50*50), 50, 50)) img <- raster::stack(r, g, b) x <- rgb_basic(img) rgb_indices_to_mean(x)
Converts a RasterBrick or RasterStack object of RGB indices into a tibble.
rgb_indices_to_tbl(x)rgb_indices_to_tbl(x)
x |
A RasterBrick or RasterStack object containing RGB indices. |
The function converts raster layers into a tabular format using
raster::as.data.frame, preserving layer names as column names.
A tibble where each column corresponds to an RGB index and each row represents a pixel from the input raster.
r <- raster::raster(matrix(runif(50*50), 50, 50)) g <- raster::raster(matrix(runif(50*50), 50, 50)) b <- raster::raster(matrix(runif(50*50), 50, 50)) img <- raster::stack(r, g, b) x <- rgb_basic(img) rgb_indices_to_tbl(x)r <- raster::raster(matrix(runif(50*50), 50, 50)) g <- raster::raster(matrix(runif(50*50), 50, 50)) b <- raster::raster(matrix(runif(50*50), 50, 50)) img <- raster::stack(r, g, b) x <- rgb_basic(img) rgb_indices_to_tbl(x)
Computes normalized difference indices from a three-band RGB image.
rgb_normdiff(image)rgb_normdiff(image)
image |
A RasterBrick or RasterStack object with three bands (R, G, B). |
A RasterStack object where each layer represents a normalized difference between RGB bands: NRGDI ((R - G)/(R + G + B)), NRBDI ((R - B)/(R + G + B)), NGBDI ((G - B)/(R + G + B)), NGRDI ((G - R)/(R + G + B)), NBGDI ((B - G)/(R + G + B)), and NBRDI ((B - R)/(R + G + B)).
set.seed(123) r <- raster::raster(matrix(runif(50*50), 50, 50)) g <- raster::raster(matrix(runif(50*50), 50, 50)) b <- raster::raster(matrix(runif(50*50), 50, 50)) img <- raster::stack(r, g, b) rgb_normdiff(img)set.seed(123) r <- raster::raster(matrix(runif(50*50), 50, 50)) g <- raster::raster(matrix(runif(50*50), 50, 50)) b <- raster::raster(matrix(runif(50*50), 50, 50)) img <- raster::stack(r, g, b) rgb_normdiff(img)
Computes ratio-based indices from a three-band RGB image.
rgb_ratio(image)rgb_ratio(image)
image |
A RasterBrick or RasterStack object with three bands (R, G, B). |
A RasterStack object where each layer represents a ratio between RGB bands: GRRI (G/R), GBRI (G/B), RBRI (R/B), RGRI (R/G), BGRI (B/G), and BRRI (B/R).
set.seed(123) r <- raster::raster(matrix(runif(50*50), 50, 50)) g <- raster::raster(matrix(runif(50*50), 50, 50)) b <- raster::raster(matrix(runif(50*50), 50, 50)) img <- raster::stack(r, g, b) rgb_ratio(img)set.seed(123) r <- raster::raster(matrix(runif(50*50), 50, 50)) g <- raster::raster(matrix(runif(50*50), 50, 50)) b <- raster::raster(matrix(runif(50*50), 50, 50)) img <- raster::stack(r, g, b) rgb_ratio(img)
Computes vegetation-related indices from a three-band RGB image.
rgb_veg(image)rgb_veg(image)
image |
A RasterBrick or RasterStack object with three bands (R, G, B). |
A RasterStack object containing multiple vegetation indices derived from RGB bands. Each layer corresponds to a specific vegetation index, including: WI, GRVI, IKAW, NDTI, GBI, GLI, VARI, NDI, ExG, ExR, ExGR, MxEG, ExB, and RGBVI.
set.seed(123) r <- raster::raster(matrix(runif(50*50), 50, 50)) g <- raster::raster(matrix(runif(50*50), 50, 50)) b <- raster::raster(matrix(runif(50*50), 50, 50)) img <- raster::stack(r, g, b) rgb_veg(img)set.seed(123) r <- raster::raster(matrix(runif(50*50), 50, 50)) g <- raster::raster(matrix(runif(50*50), 50, 50)) b <- raster::raster(matrix(runif(50*50), 50, 50)) img <- raster::stack(r, g, b) rgb_veg(img)