为何Python Pillow 10.1.0可将RGB图转17色调色板,更少则失败?
Pillow 10.1.0自适应调色板转换异常问题
测试发现,无论使用哪张RGB图像,均可通过Python Pillow 10.1.0将其转换为17色自适应调色板(Adaptive Palette)图像,但转换为16色及以下时会触发报错:ValueError: conversion not supported
测试所用RGB图像

测试代码
import numpy as np import PIL from PIL import Image img = Image.open('sigh.png') img_P17 = img.convert('P', palette = Image.Palette.ADAPTIVE, colors = 17) # 17色调色板图像 img_P17.show() # 转换为少于17色的调色板时出现异常: img_P16 = img.convert('P', palette = Image.Palette.ADAPTIVE, colors = 16) # 16色调色板图像 img_P16.show() #ValueError: conversion not supported
相关对比图

内容的提问来源于stack exchange,提问作者user3382426
相关产品推荐
相关产品推荐

