1

I'm working on a program where I open an image file(jpg), edit some of the pixels, and save the image with a new file name. It seems, however, that even when I am not editing any pixels, they are still being altered. This is a quick sample I wrote up. All I am doing is opening an image and saving it with a different name.

import Image

img1 = Image.open('image.jpg')
print img1.getpixel((0,0))
img1.save('testimage.jpg')

img2 = Image.open('testimage.jpg')
print img2.getpixel((0,0))

The output of the first print statement is (253,254,248) and the output of the second is (253,251,255). Why are the Green and Blue values changing if I am doing absolutely nothing to the image?

3
  • image.jpg and testimage.jpg are exactly the same? I don't see you saving any image? Is there any difference between the pixels if you look in an image editing program? Given that it's a jpeg, the simple act of opening and saving might alter the image ever so slightly. Commented Sep 28, 2012 at 4:38
  • I ran this code on a simple jpeg image, and received the same color for each image. Can you give us a link to the image you're using? Commented Sep 28, 2012 at 4:42
  • I was just using that as an example to show that it was altering the pixels just by opening it and then saving it. I switched to using a png instead thanks to nneonneo's answewr. Thanks for the help though. Commented Sep 28, 2012 at 5:16

1 Answer 1

2

JPEGs are lossy: saving a JPEG may result in quality loss and thus changed pixels. If you want to edit without (further) losing quality, save as .png or some other lossless format instead.

Sign up to request clarification or add additional context in comments.

1 Comment

wow, I knew it would be something little like that. I haven't worked with images much so I had no idea. Thanks Alot!

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.