How do we convert a single band categorial raster to a three-dimensional RGB array?
Lets say we want to define the color per value(category) and get an RGB array with corresponding decimal RGB values.
E.g. in the example below how would I get rgb_array given r and myCol?
library(raster)
# sample raster
r <- raster(ncol=4, nrow=4)
r[] <- c(rep(1, 8), rep(2, 8))
# plot 1=red, 2=blue
myCol = c("red", "blue")
plot(r, col=myCol)
# rgb_array is the desired output, but how to get it programatically from r?
red_band <- c(rep(255, 8), rep(0, 8))
green_band <- c(rep(0, 8), rep(0, 8))
blue_band <- c(rep(0, 8), rep(255, 8))
rgb_array <- array(c(red_band, green_band, blue_band), dim= c(4, 4, 3))
