2017-03-17 230 views
1

我打算转换多光谱图像为rgb基于图像 - (RGB values of visible spectrum如何在R语言中将光谱图像元素转换为RGB?

基本上,我通过“readPNG”功能R.读取PNG光谱图像

所以,我有2点512×512的尺寸矩阵。然后根据上面的链接我写函数返回值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) 

我做这样的代码之上,并且仍无法转换为获得彩色图像。

(更多有关的光谱信息:multispectral

回答

0

rasterImage()函数采用一个三维阵列,它可以不使用as.matrix()创建。而应使用abind包中的abind()

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

这应该做到这一点!

相关问题