GIF和JPEG的Python和PIL像素值不同 [英] Python and PIL pixel values different for GIF and JPEG

查看:86
本文介绍了GIF和JPEG的Python和PIL像素值不同的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对使用PIL加载功能打开的图像返回的像素值有疑问.我正在使用以下代码:

I have a question about the pixel values returned from an image opened with PIL load function. I am using the following code:

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

如果加载GIF图像,则a是整数值43.但是,如果将图像转换为JPEG并重新运行代码,则a是元组(253, 254, 100).

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).

为什么?以及如何将(253, 254, 100)转换回43?

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

推荐答案

将GIF打包,而JPEG则是RGB.变换图像的操作会处理调色板,因此您必须浏览GIF中的调色板条目,以找到与所需颜色最接近的匹配项.

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.

这篇关于GIF和JPEG的Python和PIL像素值不同的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆