Using imager
library, I have a dataframe that has the following information about the image in the columns:
X column
: x coordinate of pixelY column
: y coordinate of pixelRvalue
: Red component of pixelGvalue
: Green component of pixelBvalue
: Blue component of pixel
I'm trying to convert this dataframe into a cimg
to store it on disk as image -after I finished my processing on the dataframe-.
I tried using as.cimg
to do the conversion as instructed in the docs
https://rdrr.io/cran/imager/man/as.cimg.data.frame.html
But It does not support RGB argument and takes instead a value
argument representing all colors, how can I convert RGB into value or how is this value calculated so I could rebuild it with my code from RGB components?
Here is an example to try with
install.packages('imager')
library(imager)
im <- load.image("~/any_image.png")
df_image <- as.data.frame(im, wide="c") # that's the same structure as my dataframe
# need to convert that back to an image
here is a head sample of my df
x y c.1 c.2 c.3
1 1 1 0.8588235 0.7058824 0.4039216
2 2 1 0.9019608 0.7254902 0.4549020
3 3 1 0.8862745 0.7294118 0.4313725
4 4 1 0.8745098 0.7254902 0.4117647
5 5 1 0.8823529 0.7019608 0.4039216
6 6 1 0.8941176 0.7333333 0.4509804