#' RGB vegetation indices
#'
#' Computes vegetation-related indices from a three-band RGB image.
#'
#' @param image A RasterBrick or RasterStack object with three bands (R, G, B).
#'
#' @return
#' 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.
#'
#' @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_veg(img)
#'
#' @export
rgb_veg <- function(image){
  suppressWarnings({
    img <- raster::brick(image)
    R <- img[[1]]; G <- img[[2]]; B <- img[[3]]
    r <- R/(R+G+B); g <- G/(R+G+B); b <- B/(R+G+B)
    
    out <- raster::stack((G-B)/(R-G),(G-R)/(G+R),(R-B)/(R+B),(R-G)/(R+G),(G-B)/(G+B),
                         (2*G-R-B)/(2*G+R+B),(G-R)/(G+R-B),(g-r)/(g+r),
                         2*g-r-b,1.4*r-g,3*g-2.4*r-b,1.262*G-0.884*R-0.311*B,1.4*b-g,
                         (G^2-(R*B))/(G^2+(R*B)))
    
    names(out) <- c("WI","GRVI","IKAW","NDTI","GBI","GLI","VARI","NDI",
                    "ExG","ExR","ExGR","MxEG","ExB","RGBVI")
    
    out[!is.finite(out)] <- NA
    out
  })
}