How To Reduce Image Palette To Specific Colors?
I am playing with a program in Python to create cross stitch schemes and need to reduce colors in an image to specific floss colors like this. Not necessary to use all the colors f
Solution 1:
Here is an example of memoize. I've also used the builtin min
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]
Post a Comment for "How To Reduce Image Palette To Specific Colors?"