PIL changes pixel value when saving

两盒软妹~` 提交于 2019-12-01 17:15:32

Save it as a .png. .jpg is a lossy compressed format.

JPG doesn't promise to store precisely the pixels you intended. It compresses your data to make the file smaller, and the compression is based on human perception. The idea is to create an array of pixels that appear the same to a human, even though they are different pixels.

So the pixel you are writing is in the output, but the adjacent pixels have been altered to be able to store the entire image in less space. This is called "lossy compression" because data is lost.

Other image formats don't have this property. PNG is a lossless compressed format, meaning precisely the same pixels will results after decompressing a compressed PNG. If you save your image as a PNG, you will have the result you want.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!