Data reading problem
fredrik at pythonware.com
Mon Dec 20 00:14:13 CET 2004
> if you need to read lots of 12-bit values, you can create a simple bitstream
in private mail, Michal told me that his files were quite large, and that
the bitstream approach wasn't fast enough.
another way to do this is to use PIL's "bit" decoder:
im = Image.fromstring("F", (w, h), data, "bit", 12)
im = im.convert("I") # convert to INT32
seq = im.getdata() # get flattened sequence
where (w, y) is the width and height of a rectangle with the same size
as your data (if your data isn't rectangular, (size, 1) should work), data
is the raw data (size*12/8 bytes), and seq is a sequence object.
I'm pretty sure there are other toolkits out there that can do similar things;
any ideas, anyone? (numpy/scipy?)
More information about the Python-list