Data reading problem
Fredrik Lundh
fredrik at pythonware.com
Sun Dec 19 18:14:13 EST 2004
> if you need to read lots of 12-bit values, you can create a simple bitstream
> generator:
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:
import Image
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?)
</F>
More information about the Python-list
mailing list