Nearest color algorithm using Hex Triplet

Posted by Lijo on Programmers See other posts from Programmers or by Lijo
Published on 2012-08-07T09:01:55Z Indexed on 2012/10/04 15:52 UTC
Read the original article Hit count: 232

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

  1. http://stackoverflow.com/questions/5440051/algorithm-for-parsing-hex-into-color-family
  2. 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)))

© Programmers or respective owner

Related posts about algorithms

Related posts about data-structures