How to read a raw image using PIL?

前端 未结 4 1961
执笔经年
执笔经年 2020-11-29 05:31

I have a raw image where each pixel corresponds to a 16 bits unsigned integer. I am trying to read using the PIL Image.fromstring() function as in the following code:

<
4条回答
  •  时光说笑
    2020-11-29 05:46

    This is an old question, but this might help someone in the future. One of the problems with the original code snippet is that in Image.fromstring('L', imgSize, rawData, 'raw', 'F;16'), the F;16 part works for 'F' mode.

    This works for me:

    image = Image.fromstring('F', imgSize, rawData, 'raw', 'F;16')
    image.convert('L').save('out.png')
    

提交回复
热议问题