

Ask HN: color sorting algorithm? - xentronium

Imagine a pallete with N colors. You need to display them in some order that suits human eye best.<p>I seem to have problems with definition of what I want. Ideally, I'd like to see some gradients, e.g.: blue gradient from lightest to darkest, yellow gradient from lightest to darkest, etc.<p>The problem is that sorting by [H,S,V/L] or [H,V/L,S] doesn't seem to work for non-ideal palletes. The biggest problems are with shades of gray or something similar to shade of gray (when [R,G,B] components are almost equal) that appear in between gradients. Also, it should allow some deviation on hue (which would be invisible for human eye but surely visible for simple sorting algorithm), but my simple tries of generating a keys consisting of weighed sum of components failed.<p>What I also tried: building a matrix of RGB distance and then trying to sort colors keeping distance between two neighbours minimal; using combination of HSL and YUV components; sorting by [R,G,B], [H,S,L] keys and all the possible transpositions of keys.<p>What I haven't tried yet: hilbert curves, from what I see on pictures it won't help.<p>Suggestions, anyone?
======
RiderOfGiraffes
Have you considered that what you're trying to do is impossible? Without
constraints on the colors being sorted, there is no single "obvious" mapping
from a random collection of colours chosen from 3-space into 1-space.

If you do have constraints on the colors being chosen then you'll need to be
explicit as to what they are, and then use them in a non-trivial manner.

------
michael_dorfman
_You need to display them in some order that suits human eye best._

That sounds woefully ill-defined, if you ask me. My suggestion would be that
you try to figure out better what it is you are looking for, and then start
thinking about the algorithm to implement it.

 _I seem to have problems with definition of what I want._

Yep.

------
drKarl
You can try using ranges of frequencies in the light specter and ordering by
wavelength.

~~~
xentronium
Isn't it similar to hue?

~~~
drKarl
Technically yes, but you are trying to sort by HSV, or just by euclidean
distance between RGB values, but RGB values doesn't correlate to frequencies.
You could map RGB values to frequencies and order by frequency/wavelength
instead of ordering by RGB values using distance.

~~~
khaldoun
I have the same problem I sorted colors by eucleudian distance , even distance
CIELAB2000 in LCH format , it does not give the best result. How to convert
the RGB to frequency/Wavelength ??

