[Numpy-discussion] reading tiff images

Zachary Pincus zachary.pincus at yale.edu
Tue Apr 26 14:45:35 EDT 2011

On Apr 26, 2011, at 2:31 PM, Daniel Lepage wrote:

> You need PIL no matter what; scipy.misc.imread, scipy.ndimage.imread,
> and scikits.image.io.imread all call PIL.

scikits.image.io also has a ctypes wrapper for the freeimage library.  
I prefer these (well, I wrote them), though apparently there are some  
64-bit issues (crashes?). I haven't been working on a 64-bit system so  
I haven't been able to address them, but I will be soon. It's a very  
thin wrapper around a simple image IO library, so there's lots of room  
to add and extend as need be...

All of the PIL wrappers are kluges around serious flaws in how PIL  
reads images, particularly non-8-bit images and in particular non- 
native-endian 16-bit images.


> Theoretically there's no difference between any of them, although in
> actuality some use "import Image" and others use "from PIL import
> Image"; one of these may fail depending on how you installed PIL. (I'm
> not sure which is supposed to be standard - the PIL docs use both
> interchangeably, and I think the latest version of PIL on pypi sets it
> up so that both will work).
> I'd use whichever tool you're already importing - if you're using
> ndimage anyway, just use ndimage.imread rather than adding more
> imports.
> Note that using PIL directly is easy, but does require adding an extra
> step; OTOH, if you're familiar with PIL, you can use some of its
> transformations from the start, e.g.
> def imread(fname, mode='RGBA'):
>    return np.asarray(Image.open(fname).convert(mode))
> to ensure that you always get 4-channel images, even for images that
> were initially RGB or grayscale.
> HTH,
> Dan
> On Tue, Apr 26, 2011 at 2:00 PM, Mathew Yeates  
> <mat.yeates at gmail.com> wrote:
>> Hi
>> What is current method of using ndiimage on a Tiff file? I've seen
>> different methods using ndimage itself, scipy.misc and Pil.
>> Mathew
>> _______________________________________________
>> NumPy-Discussion mailing list
>> NumPy-Discussion at scipy.org
>> http://mail.scipy.org/mailman/listinfo/numpy-discussion
> _______________________________________________
> NumPy-Discussion mailing list
> NumPy-Discussion at scipy.org
> http://mail.scipy.org/mailman/listinfo/numpy-discussion

More information about the NumPy-Discussion mailing list