如何使用 PIL 减少调色板 [英] How to reduce color palette with PIL
本文介绍了如何使用 PIL 减少调色板的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我不确定如何减少 PIL 图像的调色板.我想将图像的调色板减少到该图像中的 5 种突出颜色.我的总体目标是进行一些基本的颜色采样.
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)
我使用 Image.ADAPTIVE 来避免抖动
I'm using Image.ADAPTIVE to avoid dithering
这篇关于如何使用 PIL 减少调色板的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文