Cannot Load Pixel Information From PNG Image

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Cannot Load Pixel Information From PNG Image

Karol Krizka
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]

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  -  [hidden email]
http://mail.python.org/mailman/listinfo/image-sig

house.png (3K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: Cannot Load Pixel Information From PNG Image

Karol Krizka
On Wed, Jan 5, 2011 at 11:23 PM, Joao S. O. Bueno <[hidden email]> wrote:

> On Thu, Jan 6, 2011 at 3:06 AM, Karol Krizka <[hidden email]> 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  -  [hidden email]
>> http://mail.python.org/mailman/listinfo/image-sig
>>
>>
>



--
Cheers,
Karol Krizka
_______________________________________________
Image-SIG maillist  -  [hidden email]
http://mail.python.org/mailman/listinfo/image-sig
Reply | Threaded
Open this post in threaded view
|

Re: Cannot Load Pixel Information From PNG Image

Chris Barker
On 1/5/11 11:50 PM, Karol Krizka wrote:
>> 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...

yup.

> For those interested, I now managed to create an RGB image using the
> following command:
> convert house.ppm png24:house.png

you could have converted to RGB inside PIL, as well.

-Chris



--
Christopher Barker, Ph.D.
Oceanographer

Emergency Response Division
NOAA/NOS/OR&R            (206) 526-6959   voice
7600 Sand Point Way NE   (206) 526-6329   fax
Seattle, WA  98115       (206) 526-6317   main reception

[hidden email]
_______________________________________________
Image-SIG maillist  -  [hidden email]
http://mail.python.org/mailman/listinfo/image-sig