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 from the floss palette. On Python or Pseudocode.
Custom palette (in PILL/Pillow for example) is not situable. There 256 colors max, but floss palette has around 450 colors and I plan to use multiple color charts from different manufacturers.
Dithering also not situable in cross-stitching.
I think this could be something like:
result = []
for pixel_color in image:
nearest = None
for floss_color in floss_palette:
distance = delta_e_cie2000(pixel_color, floss_color)
if distance < nearest:
nearest = floss_color
result.append(nearest)
May be there is a faster algorithm? (image_width * image_heigh * colors in palette = 112M delta_e calculations and comparisons on average 500x500px image. It's a lot.)
Dictonary for already calculated delta_e? Another algorithm/aproach/optimization?