Fwd: Re: [Image-SIG] Reading 16bit image

Bob Klimek klimek@grc.nasa.gov
Fri, 09 Aug 2002 13:19:06 -0400

I've managed to read in a 16-bit TIFF image in the following way. I don't 
know if it will work for all 16-bit images but here it goes. It read 16-bit 
images save by a package called IMAP.

imgDir = '/home/klimek/Images/16-bit'
inFile = os.path.abspath(os.path.join(imgDir, '16-bit-IMAP.tif'))
f = open(inFile, 'rb')
allData = f.read()
offset = 8 # this was determined from "StripOffsets" tag by reading an 
8-bit IMAP image
data = allData[offset : 1024*1024*16/8+offset] # 16-bit saved by IMAP
im = Image.fromstring("F", (1024,1024), data, "raw", "F;16", 0,1)
pix1 = im.getpixel((50,50))
pix2 = im.getpixel((500,300))
print pix1, pix2


>Date: Fri, 09 Aug 2002 11:36:11 +0200
>I use PIL 1.1.3 to read uncompressed 16 bit TIFF images. LZW compressed 
>tiffs doesn't work for me.
>PIL uses the "I,16" mode in the default Image.open(). I addition I added 
>the following line to the TiffImagePlugin.py OPEN_INFO :
>(1, 1, (16,), ()): ("I;16", "I;16")
>I'm not shure if this is really needed.
>Most of the PIL functions doesn't seem to work in this mode  so I 
>converted the Image to 32bit with
>im = Image.open(<file>).convert("I") in order to access the image data 
>with putpixel()/getpixel() at least.
>M. Volkmer
>Am 08/06/2002 11:03 AM, Aureli Soria Frisch schrieb:
>>>how can I use the "raw decoder" to read a binary 16 bit image?
>>>I tried doing this:
>>>>>  import Image
>>>>>  data = open('binary_file').read()   #string buffer with data
>>>>>  size = (256 256)                        #this is really its size
>>>>>  mode = 'F;16'
>>>>>  image = Image.fromstrin(mode,size,data,"raw")
>>>Python tells me this mode (F;16) does not exist. So, wich mode must I 
>>>use for
>>>16 bit images?
>>>Could somebody help me?
>>I submitted a while ago a question related to the possibility of opening 
>>TIF files with 16 bit depth that remained with no answer...
>>It would be interesting to know how to work with 16 bit files in PIL in 
>>general (it does not seem to be possible with the open source version of 
>Image-SIG maillist  -  Image-SIG@python.org