[英]limit the number of colors of an image to a specified number based on prodominant colors in python
I want to process images in a way to limit the number of colors to a predetermined and specific number我想以一种将 colors 的数量限制为预定的特定数量的方式处理图像
I tried using this method我尝试使用这种方法
from PIL import image
image= Image.open("input.png")
result = image.convert('P', palette=Image.ADAPTIVE, colors=2)
result.save("saved.png")
for some reason it used to work but now doesn't work i'm pretty sure i didn't change anything由于某种原因它曾经工作但现在不工作我很确定我没有改变任何东西
is there a fix or another method?有修复或其他方法吗? thanks谢谢
FIXED: the problem is the color mode to be able to use this function you need first to convert the color mode of the image to RGB like this:已修复:问题是颜色模式要能够使用此 function,您首先需要将图像的颜色模式转换为 RGB,如下所示:
image = image.convert('RGB')
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.