开发者

Python and PIL pixel values different for GIF and JPEG

开发者 https://www.devze.com 2023-02-28 19:14 出处:网络
I have a question about the pixel values returned from an image opened with PIL load function. I am using the fol开发者_如何学Pythonlowing code:

I have a question about the pixel values returned from an image opened with PIL load function. I am using the fol开发者_如何学Pythonlowing code:

frame = Image.open(fname).load()
a = frame[10, 10]

If I load a GIF image, a is the integer value 43. But if I convert the image a JPEG and rerun the code, a is a tuple (253, 254, 100).

Why? And how can i convert (253, 254, 100) back to 43?


GIFs are pallettized, whereas JPEGs are RGB. The act of transforming the image disposes of the palette, so you will have to look through the pallette entries in the GIF to find the closest match to the desired color.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号