1

I'm planning to convert multispectral images to rgb based images- (RGB values of visible spectrum)

Basically, I'm reading png spectral image by "readPNG" function in R.

So, I have 2 dimensions 512X512 matrix. then according to the link above I write function that return values for R,G,B.

Now, my question is how I can apply this RGB to the my image to convert to rgb?

Some part of my code:

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)

I'm doing code like above , and still couldn't convert to get color image.

(more information about spectral: multispectral )

Community
  • 1
  • 1
Big Data
  • 15
  • 4

1 Answers1

0

The rasterImage() function takes a 3D array, which you cannot create using as.matrix(). Instead, use abind() from the abind package.

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

That should do it!

paleolimbot
  • 406
  • 2
  • 3