from PIL import Image
img = Image.open(“E:\image\myimg.jpg”)
result = img.convert(
"P", palette=Image.ADAPTIVE, colors=10
)
3、 模式“P”
模式“P”为8位彩色图像,它的每个像素用8个bit表示,其对应的彩色值是按照调色板查询出来的。
image.convert(“P”)
Image 模块 — Pillow (PIL Fork) 8.4.0 文档
https://www.osgeo.cn/pillow/reference/Image.html#the-image-class