### Find nearest color match

Let's say you have a color, and you want to find the closest match in defined color scheme set. The first problem is defining what closest means. It's not a simple problem to solve.

There are a number of approaches to this, the simplest being to measure the euclidean distance between two colors in a 3D color space - for example RGB, HSL, HSV etc. Here's and article that shows how to do that.

However, these mathematical approaches do not really adjust for color perception. Another color model  CIEL*a*b*, has used various algorithms over the years to create better matches to take account of perceived color differences

#### CIEDE2000

This is the latest CIE algorithm (from  wikipedia) for comparing two colors for closeness. It's a monster

I thought I may as well implement this in VBA , javaScript and google apps script to add to my color function libraries. Here's the VBA version. Luckily I found (by Gaurav Sharma, Wencheng Wu,Edul N. Dalal) this paper to get me started. The GAS version is at Color Matching in GAS

#### Does it work?

Amazingly, it works very well. In Looking up color table I've built up a table of schemes such as Pantone, dulux etc through various web scraping sessions, and now have getting on for 10,000 named colors in that library. To test it, I generate some random colors, then look up the closest in each of the schemes in my color table. Here's the result - I tried to find a match for the first column of random numbers in all of the color table, and also in each of the individual color schemes. Their names are shown along with their color. Pretty close in all cases. Of course the html color scheme is rather short, but still close results.

#### The gory details

It's not pretty, but here are the main functions in color match algorithm.

#### comparing colors use CIE algorithm

and here' the test procedure that generated the above

#### comparing colors test procedure

`More color related topics?`
`For help and more information join our forum,follow the blog or follow me on twitter .`

`JOT_postEvent('registerForRpc', this, ['6252951446049660111', 1133121661, '//tal2tot4uenli8d3lphbjvrrl237cfes-a-sites-opensocial.googleusercontent.com/gadgets/ifr?url\x3dhttp://hosting.gmodules.com/ig/gadgets/file/106581606564100174314/iframe.xml\x26container\x3denterprise\x26view\x3dcanvas\x26lang\x3den\x26country\x3dALL\x26sanitize\x3d0\x26v\x3dec744837e115146b\x26libs\x3dcore:dynamic-height\x26mid\x3d123\x26parent\x3dhttp://www.mcpher.com/Home/excelquirks/colorfiesta/nearest#up_scroll\x3dauto\x26up_iframeURL\x3dhttp://xliberation.com/b/but.html\x26st\x3de%3DAIHE3cC1DQzMh032F%252ByD6FgSa0E3%252Fsh4%252FXhi2LWpUW4QCr84f%252BCGib68Aq8G6pb9tNJJV1CBlFf719BH059sPEh3BbUiGHKn7t3QXXtfvmvuTWMtlWPmKZ6iqh99N9iDodwXyh1B48m4%26c%3Denterprise\x26rpctoken\x3d6252951446049660111'])`