Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/visual-studio-code/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
(Python)我如何影响PIL';s图像量化选择?_Python_Python Imaging Library_Quantization - Fatal编程技术网

(Python)我如何影响PIL';s图像量化选择?

(Python)我如何影响PIL';s图像量化选择?,python,python-imaging-library,quantization,Python,Python Imaging Library,Quantization,我正在运行下面的代码来删除均匀色块之间不需要的渐变。这在很多情况下都能很好地工作,但有时会因为某些渐变颜色和调色板颜色的相似性而失败,如下图所示(顶部=原始,底部=结果,右侧=调色板图像)。我怎么能避免呢 /编辑:现在用一些圆圈来澄清 对于那些没有立即看到差异的人,请注意:在右边的山上,第二级台阶上有一个橙色的街区,还有第五级台阶。在左边的小山左边,大约在半山腰有一个橙色的街区。(需要更多) from PIL import Image import os path_images = "D:/

我正在运行下面的代码来删除均匀色块之间不需要的渐变。这在很多情况下都能很好地工作,但有时会因为某些渐变颜色和调色板颜色的相似性而失败,如下图所示(顶部=原始,底部=结果,右侧=调色板图像)。我怎么能避免呢


/编辑:现在用一些圆圈来澄清

对于那些没有立即看到差异的人,请注意:在右边的山上,第二级台阶上有一个橙色的街区,还有第五级台阶。在左边的小山左边,大约在半山腰有一个橙色的街区。(需要更多)
from PIL import Image
import os

path_images = "D:/RasterCalc/Samples_Original"
path_palette = "D:/RasterCalc/Palettes/palette_nsph.png"
path_output = "D:/RasterCalc/Samples_Converted"

image_palette = (Image.open(path_palette)).convert('RGBA')
image_palette = image_palette.convert('P')

for filename in os.listdir(path_images):
    image = (Image.open(path_images+"/"+filename)).convert('RGB')
    print(filename)
    image_converted = image.quantize(palette=image_palette)
    image_converted.save(path_output+"/"+filename)

print("==================")
print("done!")