【问题标题】:How convert spectral image elements to RGB in R language?如何在 R 语言中将光谱图像元素转换为 RGB?
【发布时间】:2017-03-17 10:18:22
【问题描述】:

我打算将多光谱图像转换为基于 rgb 的图像-(RGB values of visible spectrum)

基本上,我正在通过 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)

我正在做类似上面的代码,但仍然无法转换为彩色图像。

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

【问题讨论】:

    标签: r image-processing


    【解决方案1】:

    rasterImage() 函数采用 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)
    

    应该这样做!

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-09-16
      • 1970-01-01
      • 2019-03-16
      • 2020-12-27
      • 2021-12-15
      • 1970-01-01
      • 2020-07-03
      相关资源
      最近更新 更多