Argonne National Laboratory

Experimental Physics and
Industrial Control System

1994  1995  1996  1997  1998  1999  2000  2001  2002  2003  2004  2005  2006  2007  2008  2009  2010  2011  <20122013  2014  2015  2016  2017  2018  2019  Index 1994  1995  1996  1997  1998  1999  2000  2001  2002  2003  2004  2005  2006  2007  2008  2009  2010  2011  <20122013  2014  2015  2016  2017  2018  2019 
<== Date ==> <== Thread ==>

Subject: Re: 32-bit TIFFs and PIL
From: Matt Newville <newville@cars.uchicago.edu>
To: Mark Rivers <rivers@cars.uchicago.edu>
Cc: "dvine@aps.anl.gov" <dvine@aps.anl.gov>, Timothy Madden <tmadden@aps.anl.gov>, Ross Harder <rharder@aps.anl.gov>, "tech-talk@aps.anl.gov" <tech-talk@aps.anl.gov>
Date: Tue, 20 Mar 2012 11:21:38 -0500
Hi Mark, all,

On Tue, Mar 20, 2012 at 8:03 AM, Mark Rivers <rivers@cars.uchicago.edu> wrote:
> Hi Tim (and tech-talkers),
>
> I know you've done quite a bit with TIFF files, so I've got a question for you.
>
> The areaDetector NDFileTIFF plugin can write 8-bit, 16-bit and 32-bit TIFF files.  All of them can be read fine by ImageJ and IDL.  However, the 32-bit TIFFs cannot be read by the Python Imaging Library (PIL).  But 32-bit TIFF files written by the Dectris Pilatus driver can be read by PIL.
>
> Do you have any idea what needs to be done to make a 32-bit TIFF readable by PIL?

Actually, I see a problem with PIL even when doing what I recommended earlier:
   >>> data = open('32bit_int_1.tiff').read()  # raw file read
   >>> img = Image.frombuffer('I', (1024, 1024), data, 'raw', 'I')
   >>> img.show()

There seems to be corrupt data in the first few pixels, as if the
offset in the file was incorrect.   So, there are definitely problems
with the Python Imaging Library and 32-bit tiff files.  That
"Image.frombuffer()" does work well to convert raw image data (say,
straight from AreaDetector's ArrayData PV) or from a 2D intensity
array.

I tried the newer pylibtiff: http://code.google.com/p/pylibtiff/ and
had much better success.
   >>> from libtiff import TIFF
   >>> tiff_img = TIFF.open('32bit_int_1.tiff')
   >>> im_array = tiff_img.read_image()     # reads image to numpy array

   >>> import Image
   >>> im = Image.frombuffer('I', im_array.shape),
im_array.tostring()) # numpy-> image
   >>> im.show()

I tried several TIFF images from Area Detectors, and they all worked
fine this way, with the arrays have the correct shape and min/max
values (comparing with IDL's read_tiff).  Reading Tiff images from the
Pilatus 100K still gives the same warnings as the tiffinfo utility.

I'm not sure why the one Pilatus 32-bit TIFF could be read with PIL's
"Image.open()" while the rest could not --  the error message seems to
suggest that it couldn't even identify it as a TIFF file.  But it
looks like the pylibtiff library is better at reading these TIFF
files.

--Matt


Replies:
Re: 32-bit TIFFs and PIL Timothy Madden
References:
32-bit TIFFs and PIL Mark Rivers

Navigate by Date:
Prev: Re: "Size of symbol changed" warnings building EPICS Base 3.14.12.2 Dirk Zimoch
Next: Re: "Size of symbol changed" warnings building EPICS Base 3.14.12.2 Andrew Johnson
Index: 1994  1995  1996  1997  1998  1999  2000  2001  2002  2003  2004  2005  2006  2007  2008  2009  2010  2011  <20122013  2014  2015  2016  2017  2018  2019 
Navigate by Thread:
Prev: 32-bit TIFFs and PIL Mark Rivers
Next: Re: 32-bit TIFFs and PIL Timothy Madden
Index: 1994  1995  1996  1997  1998  1999  2000  2001  2002  2003  2004  2005  2006  2007  2008  2009  2010  2011  <20122013  2014  2015  2016  2017  2018  2019 
ANJ, 18 Nov 2013 Valid HTML 4.01! · Home · News · About · Base · Modules · Extensions · Distributions · Download ·
· Search · EPICS V4 · IRMIS · Talk · Bugs · Documents · Links · Licensing ·