1

I have a dataframe that contains pixels coordinates and its RGB and CIElab value for each.

These values are abstracted from a certain image. After changing some RGB/CIElab value in this dataframe, I would like to let the 'data' go back to an 'image'.

I include a sample with variable r, g, b, x, and y. r, g, and b contain the RGB value of each pixel.x and y indicate the pixel's coordinate.

So basically, I would like to create a picture with three color channels(rgb) with this dataframe. But I have no idea how to implement the process. Abstracting RGB value from image is easy. However, inversing the process is quite difficult.

           r      g       b     x   y
    1   0.91373 0.72157 0.45098 1   1
    2   0.86275 0.59216 0.21961 2   1
    3   0.84314 0.56471 0.18039 3   1
    4   0.83922 0.56078 0.17647 4   1
    5   0.84314 0.56471 0.18039 5   1
    6   0.84706 0.56863 0.18431 6   1
    7   0.85098 0.57255 0.18824 7   1
    8   0.85490 0.57647 0.19216 8   1
    9   0.85490 0.57647 0.19216 9   1
    10  0.85098 0.57255 0.18824 10  1

Update:

I tried to use as.cimg function

my_cimg <- as.cimg(unlist(rgb_image[1:3]), x=length(unique(rgb_image$x)), y=length(unique(rgb_image$y)),cc = 3)

And it works!!!

Thanks!

  • in this dataframe you only show x and y coordinates, where is the channel? Without the knowledge of the channel you can only get a black and white image or a poor mixture of the image colors – Onyambu Aug 09 '20 at 21:51
  • It's easier to help you if you include a simple [reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) with sample input and desired output that can be used to test and verify possible solutions. Images of data are not helpful because we can't copy/paste that into R for testing. – MrFlick Aug 10 '20 at 00:15
  • Thanks for your help. I will quickly update my question and add an example! – Cara Ruiqiong Zhang Aug 10 '20 at 13:14

0 Answers0