ReducePalette - Maple Help

ColorTools

 ReducePalette
 reduce a large list of colors to a smaller, representative list

 Calling Sequence ReducePalette(colors)

Parameters

 colors - list of colors in formats recognized by ColorTools or a Palette object. opts - (optional) equation(s) of the form option=value where option is either number or space

Options

 • number=positive integer - maximum number of colors to return, 20 by default
 • space=string - the color space of the output color objects, "Lab" by default

Description

 • This command reduces a large list of colors down to a small representative list of less than 20 colors.

Examples

 > $\mathrm{with}\left(\mathrm{ColorTools}\right):$
 > $\mathrm{full}≔\left[\mathrm{seq}\left(\mathrm{Color}\left("RGB",\left[1-i,i,1-i\right]\right),i=0..1,0.05\right)\right]$
 ${\mathrm{full}}{≔}\left[{⟨}\colorbox[rgb]{1,0,1}{RGB : 1 0 1}{⟩}{,}{⟨}\colorbox[rgb]{0.949019607843137,0.0509803921568627,0.949019607843137}{RGB : 0.95 0.05 0.95}{⟩}{,}{⟨}\colorbox[rgb]{0.901960784313726,0.101960784313725,0.901960784313726}{RGB : 0.9 0.1 0.9}{⟩}{,}{⟨}\colorbox[rgb]{0.850980392156863,0.149019607843137,0.850980392156863}{RGB : 0.85 0.15 0.85}{⟩}{,}{⟨}\colorbox[rgb]{0.8,0.2,0.8}{RGB : 0.8 0.2 0.8}{⟩}{,}{⟨}\colorbox[rgb]{0.749019607843137,0.250980392156863,0.749019607843137}{RGB : 0.75 0.25 0.75}{⟩}{,}{⟨}\colorbox[rgb]{0.701960784313725,0.301960784313725,0.701960784313725}{RGB : 0.7 0.3 0.7}{⟩}{,}{⟨}\colorbox[rgb]{0.650980392156863,0.349019607843137,0.650980392156863}{RGB : 0.65 0.35 0.65}{⟩}{,}{⟨}\colorbox[rgb]{0.6,0.4,0.6}{RGB : 0.6 0.4 0.6}{⟩}{,}{⟨}\colorbox[rgb]{0.549019607843137,0.450980392156863,0.549019607843137}{RGB : 0.55 0.45 0.55}{⟩}{,}{⟨}\colorbox[rgb]{0.501960784313725,0.501960784313725,0.501960784313725}{RGB : 0.5 0.5 0.5}{⟩}{,}{⟨}\colorbox[rgb]{0.450980392156863,0.549019607843137,0.450980392156863}{RGB : 0.45 0.55 0.45}{⟩}{,}{⟨}\colorbox[rgb]{0.4,0.6,0.4}{RGB : 0.4 0.6 0.4}{⟩}{,}{⟨}\colorbox[rgb]{0.349019607843137,0.650980392156863,0.349019607843137}{RGB : 0.35 0.65 0.35}{⟩}{,}{⟨}\colorbox[rgb]{0.301960784313725,0.701960784313725,0.301960784313725}{RGB : 0.3 0.7 0.3}{⟩}{,}{⟨}\colorbox[rgb]{0.250980392156863,0.749019607843137,0.250980392156863}{RGB : 0.25 0.75 0.25}{⟩}{,}{⟨}\colorbox[rgb]{0.2,0.8,0.2}{RGB : 0.2 0.8 0.2}{⟩}{,}{⟨}\colorbox[rgb]{0.149019607843137,0.850980392156863,0.149019607843137}{RGB : 0.15 0.85 0.15}{⟩}{,}{⟨}\colorbox[rgb]{0.101960784313725,0.901960784313726,0.101960784313725}{RGB : 0.1 0.9 0.1}{⟩}{,}{⟨}\colorbox[rgb]{0.0509803921568627,0.949019607843137,0.0509803921568627}{RGB : 0.05 0.95 0.05}{⟩}{,}{⟨}\colorbox[rgb]{0,1,0}{RGB : 0 1 0}{⟩}\right]$ (5.1)
 > $\mathrm{numelems}\left(\mathrm{full}\right)$
 ${21}$ (5.2)
 > $\mathrm{reduced}≔\mathrm{ReducePalette}\left(\mathrm{full}\right)$
 ${\mathrm{reduced}}{≔}\left[{⟨}\colorbox[rgb]{0.925490196078431,0.0784313725490196,0.925490196078431}{Lab : 56.4 91.1 -56.5}{⟩}{,}{⟨}\colorbox[rgb]{1,0,1}{Lab : 60.3 98.3 -60.8}{⟩}{,}{⟨}\colorbox[rgb]{0.701960784313725,0.301960784313725,0.701960784313725}{Lab : 49.5 55 -35.3}{⟩}{,}{⟨}\colorbox[rgb]{0.8,0.2,0.8}{Lab : 51.3 74.8 -46.9}{⟩}{,}{⟨}\colorbox[rgb]{0.6,0.4,0.6}{Lab : 50.2 29.1 -19.5}{⟩}{,}{⟨}\colorbox[rgb]{0.501960784313725,0.501960784313725,0.501960784313725}{Lab : 53.4 0.00446 -0.00714}{⟩}{,}{⟨}\colorbox[rgb]{0.4,0.6,0.4}{Lab : 58.6 -27.7 21.6}{⟩}{,}{⟨}\colorbox[rgb]{0.301960784313725,0.701960784313725,0.301960784313725}{Lab : 65.1 -50.2 42.7}{⟩}{,}{⟨}\colorbox[rgb]{0.2,0.8,0.2}{Lab : 72.3 -66.6 60.8}{⟩}{,}{⟨}\colorbox[rgb]{0.0274509803921569,0.976470588235294,0.0274509803921569}{Lab : 85.8 -84.2 81.1}{⟩}{,}{⟨}\colorbox[rgb]{0.101960784313725,0.901960784313726,0.101960784313725}{Lab : 80 -78 74.1}{⟩}\right]$ (5.3)
 > $\mathrm{numelems}\left(\mathrm{reduced}\right)$
 ${11}$ (5.4)
 > $\mathrm{imgfile}≔\mathrm{cat}\left(\mathrm{kernelopts}\left(\mathrm{datadir}\right),"/images/antennas.jpg"\right):$
 > $\mathrm{ImageTools}:-\mathrm{Embed}\left(\mathrm{ImageTools}:-\mathrm{Read}\left(\mathrm{imgfile}\right)\right)$

 > $\mathrm{full}≔\mathrm{ColorsFromImage}\left(\mathrm{imgfile}\right):$
 > $\mathrm{numelems}\left(\mathrm{full}\right)$
 ${226}$ (5.5)
 > $\mathrm{reduced}≔\mathrm{ReducePalette}\left(\mathrm{full}\right)$
 ${\mathrm{reduced}}{≔}\left[{⟨}\colorbox[rgb]{0.529411764705882,0.603921568627451,0.694117647058824}{Lab : 62.8 -1.33 -14.4}{⟩}{,}{⟨}\colorbox[rgb]{0.223529411764706,0.2,0.137254901960784}{{Lab : 21.4 -0.302 11.1}}{⟩}{,}{⟨}\colorbox[rgb]{0.776470588235294,0.701960784313725,0.529411764705882}{Lab : 73.6 0.0941 24.9}{⟩}{,}{⟨}\colorbox[rgb]{0.470588235294118,0.447058823529412,0.380392156862745}{Lab : 48.3 -1.06 10.5}{⟩}{,}{⟨}\colorbox[rgb]{0.905882352941176,0.905882352941176,0.882352941176471}{Lab : 91.4 -0.834 2.85}{⟩}{,}{⟨}\colorbox[rgb]{0.611764705882353,0.541176470588235,0.384313725490196}{Lab : 58.2 0.733 23.9}{⟩}{,}{⟨}\colorbox[rgb]{0.745098039215686,0.76078431372549,0.756862745098039}{Lab : 78.1 -1.56 0.00854}{⟩}{,}{⟨}\colorbox[rgb]{0.337254901960784,0.313725490196078,0.250980392156863}{{Lab : 34.2 -0.502 10.3}}{⟩}{,}{⟨}\colorbox[rgb]{0.63921568627451,0.615686274509804,0.568627450980392}{Lab : 64.9 0.0325 7.04}{⟩}{,}{⟨}\colorbox[rgb]{0.831372549019608,0.815686274509804,0.749019607843137}{Lab : 83.4 -1.77 9.21}{⟩}{,}{⟨}\colorbox[rgb]{0.486274509803922,0.52156862745098,0.549019607843137}{Lab : 54.9 -1.49 -5.23}{⟩}{,}{⟨}\colorbox[rgb]{0.654901960784314,0.690196078431373,0.717647058823529}{Lab : 71.3 -1.72 -5.04}{⟩}{,}{⟨}\colorbox[rgb]{0.717647058823529,0.709803921568627,0.662745098039216}{Lab : 73.5 -1.44 6.35}{⟩}{,}{⟨}\colorbox[rgb]{0.6,0.619607843137255,0.627450980392157}{Lab : 64.7 -1.15 -1.59}{⟩}{,}{⟨}\colorbox[rgb]{0.549019607843137,0.537254901960784,0.462745098039216}{Lab : 56.9 -2.31 10.6}{⟩}{,}{⟨}\colorbox[rgb]{0.396078431372549,0.376470588235294,0.301960784313725}{{Lab : 40.7 -1.41 11.8}}{⟩}{,}{⟨}\colorbox[rgb]{0.713725490196078,0.635294117647059,0.466666666666667}{Lab : 67.3 1.03 25.1}{⟩}{,}{⟨}\colorbox[rgb]{0.282352941176471,0.254901960784314,0.184313725490196}{{Lab : 27.7 -0.271 12.1}}{⟩}{,}{⟨}\colorbox[rgb]{0.549019607843137,0.47843137254902,0.392156862745098}{Lab : 52.3 3.36 14.6}{⟩}{,}{⟨}\colorbox[rgb]{0.537254901960784,0.576470588235294,0.615686274509804}{Lab : 60.4 -1.58 -6.56}{⟩}\right]$ (5.6)
 > $\mathrm{reduced}≔\mathrm{ReducePalette}\left(\mathrm{full},'\mathrm{number}'=8,'\mathrm{space}'="RGB"\right)$
 ${\mathrm{reduced}}{≔}\left[{⟨}\colorbox[rgb]{0.490196078431373,0.572549019607843,0.666666666666667}{RGB : 0.49 0.573 0.667}{⟩}{,}{⟨}\colorbox[rgb]{0.223529411764706,0.2,0.137254901960784}{{RGB : 0.224 0.2 0.137}}{⟩}{,}{⟨}\colorbox[rgb]{0.776470588235294,0.701960784313725,0.529411764705882}{RGB : 0.776 0.703 0.53}{⟩}{,}{⟨}\colorbox[rgb]{0.470588235294118,0.447058823529412,0.380392156862745}{RGB : 0.471 0.449 0.38}{⟩}{,}{⟨}\colorbox[rgb]{0.905882352941176,0.905882352941176,0.882352941176471}{RGB : 0.907 0.905 0.882}{⟩}{,}{⟨}\colorbox[rgb]{0.611764705882353,0.541176470588235,0.384313725490196}{RGB : 0.612 0.541 0.384}{⟩}{,}{⟨}\colorbox[rgb]{0.745098039215686,0.76078431372549,0.756862745098039}{RGB : 0.745 0.761 0.757}{⟩}{,}{⟨}\colorbox[rgb]{0.337254901960784,0.313725490196078,0.250980392156863}{{RGB : 0.337 0.314 0.251}}{⟩}\right]$ (5.7)

Compatibility

 • The ColorTools[ReducePalette] command was introduced in Maple 18.