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.
我想从R中的三个2D矩阵创建一个RGB图像。我知道matlab有一个类似的帖子,但是我无法将这个问题转换为R世界。
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-
我尝试了不同的软件包,例如用于创建3D数组的abind,尝试将其转换为带有writeJPEG的JPEG。但那不起作用 -
any help is very much appreciated!
很感谢任何形式的帮助!
1 个解决方案
#1
14
Try with ?rgb
,
尝试使用?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)
#1
14
Try with ?rgb
,
尝试使用?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)