'cannot filter palette images' error when

2019-06-21 07:17发布

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)

This is causing an exception:

<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 the mode of the input image is 'P'. I don't have this problem if I work with jpg images.

1条回答
Root(大扎)
2楼-- · 2019-06-21 07:35
sharpener = PIL.ImageEnhance.Sharpness (img.convert('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.

查看更多
登录 后发表回答