2

I'm running the code below to remove unwanted gradients between uniform color patches. This works well enough in plenty of cases however sometimes it fails because of the similarity of some gradient colors and the palette colors, like in the image below (top = original, bottom = result, right = palette image). How could I avoid that?

enter image description here

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!")

/edit: now with some circles for clarification!

MapEngine
  • 553
  • 1
  • 9
  • 21
  • Note for those who don't immediately see the differences: on the right hill, 2nd step up there is an orange block, as well as 5th. On the left hill left side there's an orange block about halfway up. (Needs more [circles](http://meta.stackexchange.com/a/19775/148169)) – Wayne Werner Apr 05 '16 at 16:39

0 Answers0