Reputation: 67
>>> from PIL import Image
>>> im = Image.open("E:\\aaa.jpeg")
>>> color = im.getpixel((100,100))
>>> print color
(235, 229, 205)
>>> im.putpixel((100,100),(1,1,1))
>>> im.save("E:\\new.jpeg")
>>> im=Image.open("E:\\new.jpeg")
>>> color=im.getpixel((100,100))
>>> print color
(8, 1, 0)
The value should have been (1,1,1)....but it shows(8,1,0)
Upvotes: 1
Views: 120
Reputation: 1121514
JPEG is a lossy format.
On save, your pixel data is compressed with an algorithm that does not preserve precise pixel information. When reading and decompressing that data, there is no guarantee that specific pixels will still have the exact same colour value. (8, 1, 0)
is close enough, as far as the JPEG compression is concerned.
Use a different format that preserves pixel data exactly like PNG, if this is important to your application.
Upvotes: 2