0

I have a 1D RGB565 array that I get from a camera and would like to convert it to a 3D RGB image.

So the image has QVGA resolution (320x240) and with the RGB565 format that results to a 153600 byte array.

enter image description here

Is there a quick way to convert that to an image, preferably with PIL?

thanks

  • 1
    See if the [following post](https://stackoverflow.com/questions/5414638/using-numpy-and-pil-to-convert-56516bit-color-to-88824bit-color) helps. – Rotem Jun 12 '22 at 18:27
  • Thanks Rotem. It does help and solve my problem with far fewer lines of code than my solution. – Michael Papageorge Jun 22 '22 at 10:20

1 Answers1

0

this solves my problem

And here's the code:

length = 76800 # 320*240
one = [46888] * length # this would be the list of 76800 16bit RGB565 values
xdim = 320
ydim = 240
im = Image.new("RGB",(xdim,ydim))
for y in range(ydim):
   for x in range(xdim):
      px = one[i]
      i = i+1
      im.putpixel((x,y),((px&0xF800) >> 8, (px&0x07E0) >> 3, (px&0x001F) << 3))