Query on im.save in PIL python
I am using im.load()
to get the pixels of ORIGINAL_IMAGE. Subsequently, I save it
I see that whatever is saved is different from what I wanted to save -
This is a code snippet and output that will highlight my issue -
Snippet:
im = Image.open(ORIGINAL_IMAGE)
dup_im = im.copy()
pix = dup_im.load()
dup_im.save(DUP_开发者_如何学CIMAGE)
saved_im = Image.open(DUP_IMAGE)
saved_pix = saved_im.load()
for i in range(10):
print pix[0, i], " : ", saved_pix[0, i]
Output of the print -
BEFORE SAVING : AFTER SAVING
$ python test.py
162 : 162
162 : 162
162 : 163
162 : 163
162 : 163
164 : 162
160 : 161
159 : 160
155 : 153
155 : 155
$
Details about my Python version -
$ python
Python 2.6.1 (r261:67515, Jun 24 2010, 21:47:49)
[GCC 4.2.1 (Apple Inc. build 5646)] on darwin
Any idea why the two fields (pixels before and after saving) aren't the same?
I can recreate this when loading a JPG and saving it as JPG again. The pixel data is equal when saving it as bitmap though. As JPG is a lossy image format, the save causes a re-encoding, thus changing the pixel data.
精彩评论