I'm not sure how I would go about reducing the color palette of a PIL Image. I would like to reduce an image's palette to the 5 prominent colors found in that image. My overall goal is to do some basic color sampling.
That's easy, just use the undocumented colors argument:
result = image.convert('P', palette=Image.ADAPTIVE, colors=5)
I'm using Image.ADAPTIVE to avoid dithering
tzot
The short answer is to use the Image.quantize
method. For more info, see: How do I convert any image to a 4-color paletted image using the Python Imaging Library ?
Paul
来源:https://stackoverflow.com/questions/1065945/how-to-reduce-color-palette-with-pil