2017-03-17 234 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) 

這應該做到這一點!

相關問題