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.
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 detailsIt's not pretty, but here are the main functions in color match algorithm.
and here' the test procedure that generated the above More color related topics? For help and more information join our forum,follow the blog or follow me on twitter .
|
Services > Desktop Liberation - the definitive resource for Google Apps Script and Microsoft Office automation > Color Fiesta >