#' RGB difference indices
#'
#' Computes difference-based RGB 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 difference between RGB bands:
#' GRD (G - R), BGD (B - G), RGD (R - G), RBD (R - B), GBD (G - B), and BRD (B - R).
#'
#' @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_diff(img)
#'
#' @export
rgb_diff <- function(image){
  suppressWarnings({
    img <- raster::brick(image)
    R <- img[[1]]; G <- img[[2]]; B <- img[[3]]
    out <- raster::stack(G-R, B-G, R-G, R-B, G-B, B-R)
    names(out) <- c("GRD","BGD","RGD","RBD","GBD","BRD")
    out[!is.finite(out)] <- NA
    out
  })
}