Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mapping a list of numeric values to colors

I have a list of numeric values. I may normalize the values if needed.

I need to transform this list to a list of colors (in HSL, RGB or any other color model — I can always do conversion later).

For any given value the color must be the same every time.

The more different two given numeric values are, the more contrast corresponding values should be.

All used colors must be as contrast to each other as possible (this is a soft limitation, rough solution would do).

Note that list is rather large (thousands of numbers), so simply squeezing all numbers into a single color channel would produce too dense results.

like image 967
Alexander Gladysh Avatar asked Jan 30 '09 23:01

Alexander Gladysh


3 Answers

You could consider using a 3D space-filling curve through your chosen colour space. I'll second Mark's CIELAB suggestion, wish I'd known about that last time I had to solve a similar problem.

like image 195
moonshadow Avatar answered Nov 18 '22 12:11

moonshadow


Whatever algorithm you finally settle on, you might try the CIELAB color space. It normalizes the differences in human color perception, so that equal numeric spacing gives equal perceptual differences.

like image 2
Mark Ransom Avatar answered Nov 18 '22 12:11

Mark Ransom


See: How to automatically generate N "distinct" colors?

It would be best to normalize your values, and run them through the code I suggested (where hue == your value), building a map/hash. (You can use a hash-style function instead, which is probably more efficient.)

You can "randomize" lightness (or brightness, depending on your model) and saturation using some predetermined bits of your number, for example.

like image 1
strager Avatar answered Nov 18 '22 12:11

strager