imread() and binary PNGs

Howdy,

I noticed that MPL's imread() command, when applied to binary (1-bit grayscale) PNGs does some serious mangling.

Anyone know what's going on, or is it just that only RGBA PNG's are supported?

Thanks,

David

I'm not aware of that problem. It should convert any PNG implicitly to our native RGBA format. Can you provide a PNG file that illustrates the breakage?

Mike

David Warde-Farley wrote:

···

Howdy,

I noticed that MPL's imread() command, when applied to binary (1-bit grayscale) PNGs does some serious mangling.

Anyone know what's going on, or is it just that only RGBA PNG's are supported?

Thanks,

David

-------------------------------------------------------------------------
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-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users
  
--
Michael Droettboom
Science Software Branch
Operations and Engineering Division
Space Telescope Science Institute
Operated by AURA for NASA

Sure; see http://morrislab.med.utoronto.ca/~dwf/bin.png

In [12]: x = imread('bin.png'); imshow(x)

produces a colourful plot that bears no resemblance to the original.

David

···

On 23-Oct-08, at 8:50 AM, Michael Droettboom wrote:

I'm not aware of that problem. It should convert any PNG implicitly to our native RGBA format. Can you provide a PNG file that illustrates the breakage?

Two other things:

  a) PIL can read in these without incident; my work around has been to open with PIL and manually read each bit into a dtype=bool numpy array.

  b) I might add that what appears seems to be cyclic, making me think that it's trying to read a few bytes for each pixel where in fact there is only a single bit, and thus reading far less data than it's expecting, and thus only has a few columns worth of pixels that is somehow getting repeatedly referenced in the numpy array. This is all just (mildly educated) guesswork though.

David

···

On 23-Oct-08, at 4:43 PM, David Warde-Farley wrote:

Sure; see http://morrislab.med.utoronto.ca/~dwf/bin.png

In [12]: x = imread('bin.png'); imshow(x)

produces a colourful plot that bears no resemblance to the original.

David,

After playing around with this file and the various elements of
image.py, I've determined that the pil_to_array function in
matplotlib.image works just fine, so the place where the problem is
introduced in imread is the read_png function in matplotlib._png. So a
simpler work-around for this file than reading each bit into a bool
array yourself would be to import Image (PIL) and matplotlib.image to
call the pil_to_array function on an Image.open'd object directly:

import Image
import matplotlib.image as image
import pylab as p
x = image.pil_to_array(Image.open('bin.png')); p.imshow(x); p.show()

In the mean time, I'll see if the devel list has some better insight
on the issue.

Josh

···

On Thu, Oct 23, 2008 at 1:52 PM, David Warde-Farley <dwf@...386...> wrote:

On 23-Oct-08, at 4:43 PM, David Warde-Farley wrote:

Sure; see http://morrislab.med.utoronto.ca/~dwf/bin.png

In [12]: x = imread('bin.png'); imshow(x)

produces a colourful plot that bears no resemblance to the original.

Two other things:

       a) PIL can read in these without incident; my work around has been to
open with PIL and manually read each bit into a dtype=bool numpy array.

       b) I might add that what appears seems to be cyclic, making me think
that it's trying to read a few bytes for each pixel where in fact
there is only a single bit, and thus reading far less data than it's
expecting, and thus only has a few columns worth of pixels that is
somehow getting repeatedly referenced in the numpy array. This is all
just (mildly educated) guesswork though.

David

-------------------------------------------------------------------------
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-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users

Actually, I should clarify something. The way imread is set up, since
the file is a PNG, it never goes through pil_to_array at all in
standard imread and instead gets passed to the handler _png.read_png.
Anyway, I'll take a closer peek inside the _png.cpp file once I get
some more time.

Josh

···

On Thu, Oct 23, 2008 at 3:51 PM, Joshua Lippai <discerptor@...287...> wrote:

David,

After playing around with this file and the various elements of
image.py, I've determined that the pil_to_array function in
matplotlib.image works just fine, so the place where the problem is
introduced in imread is the read_png function in matplotlib._png. So a
simpler work-around for this file than reading each bit into a bool
array yourself would be to import Image (PIL) and matplotlib.image to
call the pil_to_array function on an Image.open'd object directly:

import Image
import matplotlib.image as image
import pylab as p
x = image.pil_to_array(Image.open('bin.png')); p.imshow(x); p.show()

In the mean time, I'll see if the devel list has some better insight
on the issue.

Josh

On Thu, Oct 23, 2008 at 1:52 PM, David Warde-Farley <dwf@...386...> wrote:

On 23-Oct-08, at 4:43 PM, David Warde-Farley wrote:

Sure; see http://morrislab.med.utoronto.ca/~dwf/bin.png

In [12]: x = imread('bin.png'); imshow(x)

produces a colourful plot that bears no resemblance to the original.

Two other things:

       a) PIL can read in these without incident; my work around has been to
open with PIL and manually read each bit into a dtype=bool numpy array.

       b) I might add that what appears seems to be cyclic, making me think
that it's trying to read a few bytes for each pixel where in fact
there is only a single bit, and thus reading far less data than it's
expecting, and thus only has a few columns worth of pixels that is
somehow getting repeatedly referenced in the numpy array. This is all
just (mildly educated) guesswork though.

David

-------------------------------------------------------------------------
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-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users