HOME/Articles/

pil example convert palette (snippet)

Article Outline

Python pil example 'convert palette'

Functions in program:

  • def nearest(pixel_color, mem={}):

python convert palette

Python pil example: convert palette

def nearest(pixel_color, mem={}):
    if pixel_color in mem:
        return mem[pixel_color]
    n = min(floss_palette, key=lambda fc:delta_e_cie2000(pixel_color, fc))
    mem[pixel_color] = n
    return mem[pixel_color]

result = [nearest(pixel_color) for pixel_color in image]