[Image-SIG] Cannot Load Pixel Information From PNG Image

Karol Krizka kkrizka at gmail.com
Thu Jan 6 08:50:41 CET 2011


On Wed, Jan 5, 2011 at 11:23 PM, Joao S. O. Bueno <gwidion at mpc.com.br> wrote:
> On Thu, Jan 6, 2011 at 3:06 AM, Karol Krizka <kkrizka at gmail.com> wrote:
>> Hi there,
>>
>> I have a PNG file for which PIL 1.1.7 cannot seem to load the pixel
>> values. It returns an integer for all of them instead of a touple. The
>> script that I use to test this is very simple:
>>
>> import Image
>> im=Image.open('house.png')
>> print im
>> data=im.load()
>> print data
>> print data[149,136]
>>
>
> It just lookslike you have an indexed image, instead of an RGB one -
> Just print out your
> "im.mode" to get shure -
>

print im.mode
'L'

Hmm, that seemed to have been the problem... I guess because this
image only had greyish values (all RGB components were equal),
ImageMagick decided that it would be best to create an grayscale PNG.

Thank you for your help!

> Proper parameter passing to imagemagick can convert it to a proper RGB
> .png file.
>
For those interested, I now managed to create an RGB image using the
following command:
convert house.ppm png24:house.png

>  js
>  -><-
>> The output of it is:
>> <PngImagePlugin.PngImageFile image mode=L size=300x200 at 0x800DD0>
>> <PixelAccess object at 0x641150>
>> 97
>>
>> I should note that the point (149,136) contains a pixel of colour
>> (97,97,97). However when I change the colour at that point to
>> (128,0,1), I get a value of 160.
>>
>> The PNG image was created by converting a PPM file (which PIL has no
>> trouble reading) using ImageMagick's convert utility. PIL has no
>> trouble reading other images created using the same method. My image
>> viewing programs (xv, gwenview) have no trouble opening this
>> problematic PNG file. I've attached the image to this email.
>>
>> The PIL version that I used is 1.1.7. It is the one in Gentoo Linux
>> repositories. I also tried it with PIL that comes with Ubuntu Maverick
>> 10.10 with the same results.
>>
>>
>> --
>> Cheers,
>> Karol Krizka
>> http://www.krizka.net
>>
>> _______________________________________________
>> Image-SIG maillist  -  Image-SIG at python.org
>> http://mail.python.org/mailman/listinfo/image-sig
>>
>>
>



-- 
Cheers,
Karol Krizka


More information about the Image-SIG mailing list