Home > database >  Why pixel data is modified when i open an image with PIL.Image.open?
Why pixel data is modified when i open an image with PIL.Image.open?

Time:11-20

I am creating a new image with Image.new from PIL, where data = [(0,1,0)]*12, then i use imag.putdata(data) method and finally i save it as 'sample.jpg' using img.save. It turns out that when i open 'sample.jpg', function getdata returns all pixels with value 1, when in fact i saved it with some null pixel values.

CodePudding user response:

Seems correct. You made an image in which the pixels were each 0% red, 0.5% green and 0% blue, and saved it as a enter image description here enter image description here

If you want lossless image saving, you'll need to use a lossless format such as PNG.

  • Related