#' RGB normalized difference indices
#'
#' Computes normalized difference indices from a three-band RGB image.
#'
#' @param image A RasterBrick or RasterStack object with three bands (R, G, B).
#'
#' @return
#' 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)).
#'
#' @examples
#' 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)
#'
#' @export
rgb_normdiff <- function(image){
  suppressWarnings({
    img <- raster::brick(image)
    R <- img[[1]]; G <- img[[2]]; B <- img[[3]]
    out <- raster::stack((R-G)/(R+G+B),(R-B)/(R+G+B),(G-B)/(R+G+B),
                         (G-R)/(R+G+B),(B-G)/(R+G+B),(B-R)/(R+G+B))
    names(out) <- c("NRGDI","NRBDI","NGBDI","NGRDI","NBGDI","NBRDI")
    out[!is.finite(out)] <- NA
    out
  })
}