RGB565 1D array to 3d RGB image

Question:

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 (320×240) 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

Asked By: Michael Papageorge

||

Answers:

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))
Answered By: Michael Papageorge
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.