Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 494
feroze Avatar asked Apr 25 '12 20:04

feroze


1 Answers

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.

like image 119
Mark Ransom Avatar answered Oct 28 '22 02:10

Mark Ransom