执行ImageEnhance.Sharpness()时“无法过滤调色板图像”错误 [英] 'cannot filter palette images' error when doing a ImageEnhance.Sharpness()

查看:741
本文介绍了执行ImageEnhance.Sharpness()时“无法过滤调色板图像”错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个GIF图像文件。我使用 PIL.Image 打开它做了几个大小的变换。然后我尝试使用 ImageSharpness.Enhance() 就可以了...

I have a GIF image file. I opened it using PIL.Image and did a couple of size transforms on it. Then I tried to use ImageSharpness.Enhance() on it...

sharpener = PIL.ImageEnhance.Sharpness(img)
sharpened = sharpener.enhance(2.0)

这导致异常:

<type 'exceptions.ValueError'>
('cannot filter palette images',)

我试图谷歌此错误,但没有找到任何东西。有人可以帮我弄清楚出了什么问题吗?

I tried to google for this error, but did not find anything. Can someone help me figure out what is going wrong?

FYI输入图像的模式是'P' 。如果我使用jpg图像,我没有这个问题。

FYI the mode of the input image is 'P'. I don't have this problem if I work with jpg images.

推荐答案

sharpener = PIL.ImageEnhance.Sharpness (img.convert('RGB'))

算法很常见无法使用基于调色板的图像。上面的转换将其更改为在每个像素位置都有一个完整的RGB值。

It's quite common for algorithms to be unable to work with a palette based image. The convert in the above changes it to have a full RGB value at each pixel location.

这篇关于执行ImageEnhance.Sharpness()时“无法过滤调色板图像”错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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