I have a 7GB image I got from NASA and I wanted to write a decoder using Python and PIL. The page from where I got the image states the following:
The data are formatted as a single-channel 16-bit integer (two byte, long) signed raw binary file, with big-endian byte order and no header.
Here's the documentation for writing an image decoder, but I don't have much experience dealing with images in Python and I'm at a total loss here.
I deal a lot with raw images, some in 16bit and some in 8bit grayscale.
I have found that loading the raw image into a numpy array, then converting it to an image usually works.
If there is a problem with the byte order, then the numpy array.byteswap() command should take care of it before conversion to the PIL image object.
This code is taken from a program that works to read 8-bit raw images into PIL:
In the second line, changing from uint8 to uint16 will load a 2-byte instead of a 1-byte raw image. In the third line, the image is cast into a 4-byte integer, as some of the PIL routines seem to work better with this type.
The problem you are encountering is that the files are 16-bit pixels when PIL only supports 8-bit pixels in the provided list, and 16-bit little endian from this mail on the same topic:
http://osdir.com/ml/python.image/2006-11/msg00021.html
That was 4 years ago, and here is the same topic raised again this year:
http://mail.python.org/pipermail/image-sig/2010-April/006166.html
Found this looking in
.../Imaging-1.1.7/PIL/Image.py
of the sources forPIL v1.1.7
, note the comment at the end about some "Experimental modes":So it looks like there's some support in it for 16-bit images.
UTSL - Use the Source Luke