Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to create RGB image from three matrices in R?

I want to create an RGB image from three 2D matrices in R. I know that there was a similar post for matlab, however I could not translate that problem to the R world.

I tried already different packages such as abind for creating a 3D array, tried to turn it into a JPEG with writeJPEG. but that did not work-

any help is very much appreciated!

like image 954
Jens Avatar asked Jul 03 '12 07:07

Jens


1 Answers

Try with ?rgb,

r <- matrix(runif(9, 0, 1), 3)
g <- matrix(runif(9, 0, 1), 3)
b <- matrix(runif(9, 0, 1), 3)

col <- rgb(r, g, b)
dim(col) <- dim(r)

library(grid)
grid.raster(col, interpolate=FALSE)
like image 85
baptiste Avatar answered Nov 20 '22 09:11

baptiste