[Image-SIG] n00b Question

Steve Freitas sflist at ihonk.com
Mon Feb 22 08:05:13 CET 2010

Hi all,

I've downloaded image data[1] which has no header and is comprised of
16-bit signed big-endian pixels (it's a heightmap). I figured I'd cull a
portion of the data and turn it into a TIFF so I could check it out
visually to make sure it looks kinda like a heightmap should. However, I
seem to be doing something wrong. I've read the data into a string (not
unicode, and the file was opened with 'rb'), and I'm using essentially
this code to generate a TIFF:

f = open('data.bin', 'rb')
data = f.read(<a subset of the file representing, say, Colorado>)
p = Image.fromstring('F', (tile_width, tile_height), data, 'raw',
'F;16BS', 0, 1)

I've verified that I'm pulling data that isn't just a bunch of zeros,
and I've verified that the generated TIFF isn't just a bunch of zeros,
but when I view it I get the checkerboard pattern which seems to
indicate a translucent image. Or something.

Part of my confusion comes from the interrelation between the two "mode"
arguments to Image.fromstring(). I guess the first one indicates the
kind of output mode you want, and the second one indicates the raw
decoder to use? But why am I specifying 'F' if the input data is all
integers? I tried changing them respectively to 'I' and 'I;16BS', but
that didn't change the resulting blank image.

Any tips appreciated!



[1] http://visibleearth.nasa.gov/view_rec.php?id=8391
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/image-sig/attachments/20100221/7dfc8eee/attachment.html>

More information about the Image-SIG mailing list