can the python PIL deal with raw image data?

a 夏天 提交于 2019-12-01 06:47:29

问题


I have an raw image file that is .bin and is composed of 16 bits unsigned intergers. Can the python imaging library take this type of file and process it? My code is not running properly and giving me an invalid file type error but I think it may be an error in the coding rather than just that it doesn't take this file type.

Any knowledge on this out there?


回答1:


Assuming your file doesn't have a header and is tightly packed, try the following:

with open('filename', 'rb') as f:
    im = Image.fromstring('L;16', (width, height), f.read()) # also try 'L;16B', 'I;16', and 'I;16B'
im.show()

The 'L' formats will truncate from 16 bits per pixel to 8; the 'I' formats will keep it at 16 bits per pixel but might be harder to work with.

If your raw file is encoded in some way you'll have to search for documentation on it, since raw formats aren't standardized at all. With a .bin extension I doubt that's the case.



来源:https://stackoverflow.com/questions/10901547/can-the-python-pil-deal-with-raw-image-data

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!