# not tested! the code should just give the general idea
import colorsys
# just some utility funcs to wrap colorsys and to offer support for list of colors
def rgb_to_yiq(colors):
return [colorsys.rgb_to_yiq(color) for color in colors]
def yiq_to_rgb(colors):
return [colorsys.yiq_to_rgb(color) for color in colors]
# get these from some source (histogram/whatever)
rgb_colors = [[0.9, 0.2, 0.7], [0.2, 0.5, 0.6], ]
yiq_colors = rgb_to_yiq(rgb_colors)
sorted_yiq = sorted(yiq_colors) # implement comparison func to sort based on I or Q. it uses cmp
# by default it sorts by Y
result_colors = yiq_to_rgb(sorted_yiq)