如何在R语言中将光谱图像元素转换为RGB?

如何在R语言中将光谱图像元素转换为RGB?,r,image-processing,R,Image Processing,我计划将多光谱图像转换为基于rgb的图像-() 基本上,我是通过R中的“readPNG”函数来读取png光谱图像的 所以,我有2维512X512矩阵。然后根据上面的链接,我编写了返回R,G,B值的函数 现在,我的问题是如何将这个RGB应用到“我的图像”以转换为RGB 我的部分代码: img <-readPNG("sample_img.png") # 512 X 512 Matrix # after calculate R,G,B r = 1 g = 0.892 b = 0 el

我计划将多光谱图像转换为基于rgb的图像-()

基本上,我是通过R中的“readPNG”函数来读取png光谱图像的

所以,我有2维512X512矩阵。然后根据上面的链接,我编写了返回R,G,B值的函数

现在,我的问题是如何将这个RGB应用到“我的图像”以转换为RGB

我的部分代码:

img <-readPNG("sample_img.png")  # 512 X 512 Matrix 

# after calculate R,G,B 
r = 1
g =  0.892
b = 0

el1 <- img * r 
el2 <- img * g
el3 <- img * b

col <- as.matrix(el1, el2, el3)
plot (1:512 , type="n" ) 
rasterImage(col, 1, 1, 512, 512)
img函数
rasterImage()
采用3D数组,不能使用
as.matrix()
创建3D数组。相反,使用
abind
包中的
abind()

library(abind)
col <- abind(el1, el2, el3, along=3)
plot (1:512 , type="n" ) 
rasterImage(col, 1, 1, 512, 512)
库(abind)
col函数
光栅图像()
采用3D数组,不能使用
as.matrix()
创建该数组。相反,使用
abind
包中的
abind()

library(abind)
col <- abind(el1, el2, el3, along=3)
plot (1:512 , type="n" ) 
rasterImage(col, 1, 1, 512, 512)
库(abind)
上校