'cannot filter palette images' error when doing a ImageEnhance.Sharpness()

痞子三分冷 提交于 2019-12-10 13:48:16

问题


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:


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.



来源:https://stackoverflow.com/questions/10323692/cannot-filter-palette-images-error-when-doing-a-imageenhance-sharpness

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