[comp.graphics] References sought on finding "closest match" to a color

mlandau@bbn.com (Matt Landau) (05/23/88)

I'm looking for references to techniques that do a resonable at finding
the "closest" match to a desired color, given a pool of candidate colors
from which to select.  

More specifically, given a target RGB value and an arbitrary sized colormap 
consisting of RGB triplets over which you have no control, how do you go
about choosing the nearest available color?

There are a couple of obvious techniques.  For example, you could consider 
RGB as defining axes in 3-space and try to minimize the spatial distance 
between the color you want and the colors you have -- looking at the code, 
X11R2 seems to do this.  

I suspect there are better techniques available.  Can someone out there
save me some research time, or is it time to head back to the reference
books?
--
 Matt Landau		    	mlandau@bbn.com
 
 Diplomacy is the art of saying "nice doggy" until you can find a rock.

jbm@eos.UUCP (Jeffrey Mulligan) (05/24/88)

From article <11076@jade.BBN.COM>, by mlandau@bbn.com (Matt Landau):
> I'm looking for references to techniques that do a resonable at finding
> the "closest" match to a desired color, given a pool of candidate colors
> from which to select.  
> 

If you want to minimize the perceived color difference, there are
a number of formulas which attempt to quantify color differences.
There are a number of different scales to choose from; a good review
is provided in chapter 6 of Wyszecki and Stiles, "Color Science,"
Wiley, 2nd ed. 1982.

These things are generally messy; for example in the Munsell
system, value (lightness) is defined implicitly in terms of
luminance (Y) in the following equation:

Y = 1.2219 V - 0.23111 V^2 + 0.23951 V^3 - 0.021009 V^4 + 0.0008404 V^5 .

For many applications a simpler approach such as the one you described
in your posting is probably good enough.

-- 

	Jeff Mulligan (jbm@ames-aurora.arpa)
	NASA/Ames Research Ctr., Mail Stop 239-3, Moffet Field CA, 94035
	(415) 694-5150

becker@ziebmef.uucp (Bruce Becker) (06/01/88)

In article <11076@jade.BBN.COM> mlandau@bbn.com (Matt Landau) writes:
>I'm looking for references to techniques that do a resonable at finding
>the "closest" match to a desired color, given a pool of candidate colors
>from which to select.  
>
>More specifically, given a target RGB value and an arbitrary sized colormap 
>consisting of RGB triplets over which you have no control, how do you go
>about choosing the nearest available color?
>
> Matt Landau		    	mlandau@bbn.com

The usual problem involves some form of quantization of the output color map,
so that the target color gamut is effectively partitioned by an octree.
Unfortunately the term "nearest" in RGB space is not closely approximated
by perceptual color space. A crude approximation would be to transform
to HSV coordinates and weight the search distance 2*H,1*S,4*V, where V has
been computed to be about 0.3Red+0.6Grn+0.1Blue.

Partitioning the color space into an octree is best referenced by the work
of Hanan Samet - ACM siggraph has Tutorials on some general methods...

Please note that it is entirely possible to define colors which are outside
the gamut of the target display media - it is not a simple task to decide
in the general case how to pick the nearest possible color, but a rule of
thumb is get the brightness right first, and try to get a color that
intersects the gamut on a line perpendicular to the V axis. This is not
always attractive when accurate color rendition is at stake...

There's lots more, but this should start you off OK..

Cheers, B. Becker

UUCP:   ...!ncrcan!ziebmef!becker!bdb
BitNet: BECKER@HUMBER