## digitalmars.D - [OT] a good color distance function

Justin Johansson <no spam.com> writes:
```Can anyone please suggest a decent algorithm for
determining a "color distance" metric between
two colors?  The requirement is to come up with
a good algorithm for contrasting a computed color
from another color.

Should this algorithm (function) be dependent upon
whether the color model be additive (aka RGB) or
subtractive (aka CMYK) or other?

Also should a decent "color distance" function take
in to account the possibility of color blindness
disability amongst the potential audience?

Somehow me thinks that (in say an RGB model) a
Pythagorean square-root of the the sum of the squares
of the respective RGB axis deltas is, whilst
mathematically pleasing, not best practice for
accessibility/visual impairment issues.

Justin Johansson
```
Oct 14 2010
BCS <none anon.com> writes:
```Hello Justin,

Can anyone please suggest a decent algorithm for
determining a "color distance" metric between
two colors?  The requirement is to come up with
a good algorithm for contrasting a computed color
from another color.

I'd work in HSV. convert the hue channel to an absolute difference and then
combine with a weighted sum. You might also take a look at some graphics
design ideas about the color wheel (e.g. make the f(H) have peeks for
complementary
colors) and you could have some fun with a crowd sourced fitness function
driving a GA to get the tuning factors right.

--
... <IXOYE><
```
Oct 14 2010
Justin Johansson <no spam.com> writes:
```On 15/10/2010 1:16 AM, BCS wrote:
Hello Justin,

I'd work in HSV. convert the hue channel to an absolute difference and
then combine with a weighted sum. You might also take a look at some
graphics design ideas about the color wheel (e.g. make the f(H) have
peeks for complementary colors) and you could have some fun with a crowd
sourced fitness function driving a GA to get the tuning factors right.

Thanks BCS for these useful ideas.
Cheers, Justin
```
Oct 15 2010
ponce <spam spam.org> writes:
```
Somehow me thinks that (in say an RGB model) a
Pythagorean square-root of the the sum of the squares
of the respective RGB axis deltas is, whilst
mathematically pleasing, not best practice for
accessibility/visual impairment issues.

```
Oct 14 2010
Justin Johansson <no spam.com> writes:
```On 15/10/2010 2:54 AM, ponce wrote:
Somehow me thinks that (in say an RGB model) a
Pythagorean square-root of the the sum of the squares
of the respective RGB axis deltas is, whilst
mathematically pleasing, not best practice for
accessibility/visual impairment issues.

Another useful tip.  Thanks also ponce.
Cheers, Justin
```
Oct 15 2010
=?UTF-8?B?IkrDqXLDtG1lIE0uIEJlcmdlciI=?= <jeberger free.fr> writes:
```Justin Johansson wrote:
Can anyone please suggest a decent algorithm for
determining a "color distance" metric between
two colors?  The requirement is to come up with
a good algorithm for contrasting a computed color
from another color.
=20
Should this algorithm (function) be dependent upon
whether the color model be additive (aka RGB) or
subtractive (aka CMYK) or other?
=20

In the imaging industry (printers, scanners and screens), we
usually use the L*a*b* [1] or L*u*v* [2] color spaces. Pythagorean
distances in these spaces give reasonably good results, but more
advanced measures have been developed [3] if you need more precision.

Jerome

[1] http://en.wikipedia.org/wiki/Lab_color_space
[2] http://en.wikipedia.org/wiki/CIELUV_color_space
[3] http://en.wikipedia.org/wiki/Color_difference
--=20
mailto:jeberger free.fr
http://jeberger.free.fr
Jabber: jeberger jabber.fr
```
Oct 16 2010