Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

convert images

1 view
Skip to first unread message

wilson

unread,
Apr 27, 2008, 9:42:13 AM4/27/08
to
hi
i converted some P5 type .pgm images to .jpg using
x=Image.open("oldimage.pgm")
imsz=x.size
newimg=Image.new('L',imsz)
newimg.putdata(x.getdata())
newimg.save("newimg.jpg")

when i again check the pixel data for these images using getdata()
method i,I find that they are slightly different

ie if oldimage.pgm has pixels
[29 31 38 ..., 10 4 18]
then the corresponding jpg image has
[29 31 38 ..., 10 3 17]

why this difference? shouldn't they be identical?can someone pls
explain this?

Marc 'BlackJack' Rintsch

unread,
Apr 27, 2008, 12:36:22 PM4/27/08
to
On Sun, 27 Apr 2008 06:42:13 -0700, wilson wrote:


> i converted some P5 type .pgm images to .jpg using

> […]


> ie if oldimage.pgm has pixels
> [29 31 38 ..., 10 4 18]
> then the corresponding jpg image has
> [29 31 38 ..., 10 3 17]
>
> why this difference? shouldn't they be identical?can someone pls
> explain this?

JPEG uses a lossy compression algorithm, i.e. the image loses quality and
therefore the pixel values are not exactly the same as before saving. If
you want get the exact values back you have to use another image format.
For RGB or RGBA data PNG is a good format.

Ciao,
Marc 'BlackJack' Rintsch

0 new messages