Nearest color algorithm using Hex Triplet
- by Lijo
Following page list colors with names http://en.wikipedia.org/wiki/List_of_colors.
For example #5D8AA8 Hex Triplet is "Air Force Blue". This information will be stored in a databse table (tbl_Color (HexTriplet,ColorName)) in my system
Suppose I created a color with #5D8AA7 Hex Triplet. I need to get the nearest color available in the tbl_Color table. The expected anaser is "#5D8AA8 - Air Force Blue". This is because #5D8AA8 is the nearest color for #5D8AA7.
Do we have any algorithm for finding the nearest color? How to write it using C# / Java?
REFERENCE
http://stackoverflow.com/questions/5440051/algorithm-for-parsing-hex-into-color-family
http://stackoverflow.com/questions/6130621/algorithm-for-finding-the-color-between-two-others-in-the-colorspace-of-painte
Suggested Formula:
Suggested by @user281377. Choose the color where the sum of those squared differences is minimal
(Square(Red(source)-Red(target))) + (Square(Green(source)-Green(target))) +(Square(Blue(source)-Blue(target)))