[Image-SIG] open, show, png, blank

Randolph Bentson bentson at holmsjoen.com
Sun Feb 5 02:47:23 CET 2012


On Tue, Jan 31, 2012 at 01:38:25PM -0500, Nelson Tong wrote:
> 
> when I use "show()", the image appears to have an all-white
> background, nothing else is on it.
... 
> Attached is example image which I am having problem with.  Can you
> reproduce the same problem I'm seeing with this image, possibly due to
> the png image being broken?
...
> > Try this:
> >
> >  outI = Image.open( fileOutPNGFile )

There's some faulty magic at the core of this problem. When the file
you cited goes through "outI = Image.open( fileOutPNGFile )", the open
method notes all the pixels are shades of gray, so the internal image is
converted to a grayscale form. For example, "outI.getbands()" reports
"('I',)" instead of "('R','G','B')".

The command "outI.getextrema()" returns (8200,60602).  So when the image
is saved as a pbm file for display, the shades of gray are all rendered
as white when all the pixels are being converted to the (R,G,B) value of
(255,255,255). This flaw is related to the conversion of the grayscale
format.  If one executes "outI.save("altfile.png") the resulting file
looks like the original (for some reason), but "tmpJ.getpixel((x,y))"
where "tmpJ=outI.convert("RGB")" returns (255,255,255) for all x,y.

If you insert the line "outI = outI.point(lambda i:i * .0039062500 + 0)"
the I mode gets scaled down so the conversion to 'RGB' mode is
valid.

-- 
Randolph Bentson
bentson at holmsjoen.com


More information about the Image-SIG mailing list