469,948 Members | 2,898 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,948 developers. It's quick & easy.

convert images

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?

Jun 27 '08 #1
1 4596
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
Jun 27 '08 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

9 posts views Thread by gsb | last post: by
1 post views Thread by Linda Chen | last post: by
5 posts views Thread by Carl Gilbert | last post: by
4 posts views Thread by velu | last post: by
1 post views Thread by Just D. | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.