Color wheel corrected for human discernment
Posted: Thu Dec 04, 2014 6:21 pm
I'm making for myself some hiking maps in the form of *.kml files that I can import into Google Earth. I wanted each hiking trail to have a different color, and so I assigned each trail a random color from the rainbow. Specifically, if there are n trails, then for each trail, I randomly choose a color (without replacement) from the sequence of colors printed by the following python function:
In this sequence, each color has approximately equidistant hue from its neighbors. In the maps I'm creating, most trails have many intersections and many other nearby trails in general. One thing I noticed is if two nearby trails colored in the purplish-reddish part of the spectrum happened to intersect each other, it was difficult to tell the trails apart, whereas this problem didn't exist in other parts of the spectrum, such as the yellowish-greenish part. I suspect that human vision is better at discerning between hues in some parts of the spectrum versus others. So how would I write a function similar to the above that, instead of generating colors with equidistant hues, generates colors with hues with distance such that each hue is equally discernible from its neighbors? For instance, in such a sequence, I'd imagine there would be fewer reddish-purplish colors, since they need to be of greater hue distance to tell apart, whereas there would be more yellowish-greenish colors, since they don't need as much hue distance to tell apart.
Another solution to the map problem in general is to try assign colors to trails not entirely randomly but such that trails that intersect each other or are otherwise nearby each other don't have similar colors, but I think that even if this solution were employed, coloring trails with the most easily discernible hues would still be valuable, for instance, for creating a map legend. Plus, this seems like an interesting problem that must have a known solution. But I haven't been able to come across anything so far. Any thoughts?
Code: Select all
import colorsys
def rainbow(n):
for i in xrange(n):
rgb = colorsys.hsv_to_rgb(float(i) / n, 1.0, 1.0)
rgb = tuple(round(x * 255) for x in rgb)
print '#%.2x%.2x%.2x' % rgb
Another solution to the map problem in general is to try assign colors to trails not entirely randomly but such that trails that intersect each other or are otherwise nearby each other don't have similar colors, but I think that even if this solution were employed, coloring trails with the most easily discernible hues would still be valuable, for instance, for creating a map legend. Plus, this seems like an interesting problem that must have a known solution. But I haven't been able to come across anything so far. Any thoughts?