I am trying to reduce number of colors to 1024, but got error ValueError: bad number of colors
img = img.convert('P', palette=Image.ADAPTIVE, colors=1024)
or
img = img.quantize(256, 0)
What is wrong?
I am trying to reduce number of colors to 1024, but got error ValueError: bad number of colors
img = img.convert('P', palette=Image.ADAPTIVE, colors=1024)
or
img = img.quantize(256, 0)
What is wrong?
As you can see here from the
PIL.Imagemodule source codehttps://pillow.readthedocs.io/en/stable/_modules/PIL/Image.htmlthe documenting comment for theconvertmethod states that:so the
quantizemethod is used for the operation because you didn't provide amatrixargument to the convert method and now inside of thequantizemethod the documenting states that:so the number of colors should be less than or equal to 256 instead a
ValueErrorexception will be raised.