Ask HN: color sorting algorithm?
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.
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.
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.
What I haven't tried yet: hilbert curves, from what I see on pictures it won't help.
Suggestions, anyone?
7 comments
[ 3.2 ms ] story [ 18.6 ms ] threadThat 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.
As colors are not uniquely defined by their wavelength there is no linear one dimensional ordering of colors. It's more like cube: http://goo.gl/aCp5X
So now the questions is how to sort it anyway if you need to, which dimension are you going to choose?
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.