Odd handling of binary png files by pylab.imread

Hello all,

Earlier today I looked into a problem someone on the users list was
having with imread working on a binary png file of his (attached). The
array returned does not correspond to the picture, as verified by
imshow'ing the imread'd file, which results in a distorted image with
rainbow colouring at parts. After working through how imread would
handle his file, it seems the problem has to be somewhere in
matplotlib._png.read_png, which stems from matplotlib/src/_png.cpp in
the source tree. Interestingly enough, using the function pil_to_array
from matplotlib.image on the output of Image.open(fname) works
correctly on the file. I plan on poking around in the cpp file more
myself later tonight, but I was wondering if anyone more familiar with
matplotlib's png-handling could see something immediately obvious that
would break imread's capabilities on binary PNGs.

Josh

bin.png

I'm looking into this. It seems that matplotlib is not making the right calls to libpng to convert < 8-bit images for us.

Mike

Joshua Lippai wrote:

···

Hello all,

Earlier today I looked into a problem someone on the users list was
having with imread working on a binary png file of his (attached). The
array returned does not correspond to the picture, as verified by
imshow'ing the imread'd file, which results in a distorted image with
rainbow colouring at parts. After working through how imread would
handle his file, it seems the problem has to be somewhere in
matplotlib._png.read_png, which stems from matplotlib/src/_png.cpp in
the source tree. Interestingly enough, using the function pil_to_array
from matplotlib.image on the output of Image.open(fname) works
correctly on the file. I plan on poking around in the cpp file more
myself later tonight, but I was wondering if anyone more familiar with
matplotlib's png-handling could see something immediately obvious that
would break imread's capabilities on binary PNGs.

Josh
  
------------------------------------------------------------------------

------------------------------------------------------------------------

-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
------------------------------------------------------------------------

_______________________________________________
Matplotlib-devel mailing list
Matplotlib-devel@lists.sourceforge.net
matplotlib-devel List Signup and Options
  
--
Michael Droettboom
Science Software Branch
Operations and Engineering Division
Space Telescope Science Institute
Operated by AURA for NASA

This is now fixed in SVN r6318. I also added some of the PNG test suite images to out regression tests so we're sure that it works with all of the basic PNG types.

Mike

Joshua Lippai wrote:

···

Hello all,

Earlier today I looked into a problem someone on the users list was
having with imread working on a binary png file of his (attached). The
array returned does not correspond to the picture, as verified by
imshow'ing the imread'd file, which results in a distorted image with
rainbow colouring at parts. After working through how imread would
handle his file, it seems the problem has to be somewhere in
matplotlib._png.read_png, which stems from matplotlib/src/_png.cpp in
the source tree. Interestingly enough, using the function pil_to_array
from matplotlib.image on the output of Image.open(fname) works
correctly on the file. I plan on poking around in the cpp file more
myself later tonight, but I was wondering if anyone more familiar with
matplotlib's png-handling could see something immediately obvious that
would break imread's capabilities on binary PNGs.

Josh
  
------------------------------------------------------------------------

------------------------------------------------------------------------

-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
------------------------------------------------------------------------

_______________________________________________
Matplotlib-devel mailing list
Matplotlib-devel@lists.sourceforge.net
matplotlib-devel List Signup and Options
  
--
Michael Droettboom
Science Software Branch
Operations and Engineering Division
Space Telescope Science Institute
Operated by AURA for NASA