imread issues

Hello,

while working on the scikits-image io plugin system, I noticed some issues with matplotlib's imread function. I have a patch for all these issues and will submit a PR but wanted to check on the list first.

1) imread does not properly detect the file type if an open file handle is used.

lena = pylab.imread(matplotlib.cbook.get_sample_data('lena.jpg'))

Traceback (most recent call last):
   File "<stdin>", line 1, in <module>
   File "X:\Python27\lib\site-packages\matplotlib\pyplot.py", line 1740, in imread
     return _imread(*args, **kwargs)
   File "X:\Python27\lib\site-packages\matplotlib\image.py", line 1207, in imread
     return handler(fname)
RuntimeError: _image_module::readpng: file not recognized as a PNG file

2) imread does not properly convert uint16 images to uint8 as reported on the scikits-image ML <Redirecting to Google Groups.

3) Any non-PNG image loaded with imread is displayed upside-down in imshow:

imshow(imread("lena.jpg")); show()

A solution is to pass `origin='lower'` to imshow for non-PNG images. But is there a reason for this asymmetry? Any image loaded with PIL is explicitly flipped upside-down at <https://github.com/matplotlib/matplotlib/blob/master/lib/matplotlib/image.py#L1267&gt;\.

Christoph

Pull request at <https://github.com/matplotlib/matplotlib/pull/616&gt;

Christoph

···

On 12/9/2011 12:11 PM, Christoph Gohlke wrote:

Hello,

while working on the scikits-image io plugin system, I noticed some
issues with matplotlib's imread function. I have a patch for all these
issues and will submit a PR but wanted to check on the list first.

1) imread does not properly detect the file type if an open file handle
is used.

lena = pylab.imread(matplotlib.cbook.get_sample_data('lena.jpg'))

Traceback (most recent call last):
    File "<stdin>", line 1, in<module>
    File "X:\Python27\lib\site-packages\matplotlib\pyplot.py", line 1740,
in imread
      return _imread(*args, **kwargs)
    File "X:\Python27\lib\site-packages\matplotlib\image.py", line 1207,
in imread
      return handler(fname)
RuntimeError: _image_module::readpng: file not recognized as a PNG file

2) imread does not properly convert uint16 images to uint8 as reported
on the scikits-image ML
<Redirecting to Google Groups.

3) Any non-PNG image loaded with imread is displayed upside-down in imshow:

imshow(imread("lena.jpg")); show()

A solution is to pass `origin='lower'` to imshow for non-PNG images. But
is there a reason for this asymmetry? Any image loaded with PIL is
explicitly flipped upside-down at
<https://github.com/matplotlib/matplotlib/blob/master/lib/matplotlib/image.py#L1267&gt;\.

Christoph

------------------------------------------------------------------------------
Cloud Services Checklist: Pricing and Packaging Optimization
This white paper is intended to serve as a reference, checklist and point of
discussion for anyone considering optimizing the pricing and packaging model
of a cloud services business. Read Now!
http://www.accelacomm.com/jaw/sfnl/114/51491232/
_______________________________________________
Matplotlib-devel mailing list
Matplotlib-devel@lists.sourceforge.net
matplotlib-devel List Signup and Options