3
$\begingroup$

I can find equidistant colors in the LAB colorspace. Since, it is complicated, I first calculated the values of a and b for equidistant points on the AB plane and incremented the L values gradually for each point. Below is what I've done so far:

getLABColors[n_] := (
      RM = {{Cos[\[Theta]], -Sin[\[Theta]]}, {Sin[\[Theta]], 
            Cos[\[Theta]]}};
      coord = {{1}, {1}};
      l = Table[x, {x, 0, 1, 1/(n - 1)}];
      ab = Table[RM.coord, {\[Theta], 0, 2 Pi , 2 Pi /(n - 1)}];
      a = Table[ab[[i]][[1]][[1]], {i, 1, n, 1}];
      b = Table[ab[[i]][[2]][[1]], {i, 1, n, 1}];
      labcolors = 
          Table[LABColor[N[l[[i]]], N[a[[i]]], N[b[[i]]]], {i, 1, n, 1}]
     );

Using this, I can find 6 equidistant colors:

labcolors = getLABColors[6]

and the result is:

{LABColor[0., 1., 1.], LABColor[
 0.2, -0.6420395219202061, 1.260073510670101], LABColor[
 0.4, -1.3968022466674206`, -0.22123174208247431`], LABColor[
 0.6, -0.22123174208247431`, -1.3968022466674206`], LABColor[
 0.8, 1.260073510670101, -0.6420395219202061], LABColor[1., 1., 1.]}

When I tried to visualise the points on the 3D Gamut, I found the point lie on the surface of the gamut in the form of a spiral of one complete turn as I wanted.

Show[ChromaticityPlot3D["LAB", FillingStyle -> Opacity[0.2]], 
 ChromaticityPlot3D[labcolors, PlotStyle -> PointSize[.02]]]

enter image description here

I tried to do the same with RGB colorspace but did not get the expected result.

getRGBColors[n_] := (
   RM = {{Cos[\[Theta]], -Sin[\[Theta]]}, {Sin[\[Theta]], 
   Cos[\[Theta]]}};
   coord = {{1}, {1}};
   b = Table[x, {x, 0, 1, 1/(n - 1)}];
   rg = Table[RM.coord, {\[Theta], 0, 2 Pi , 2 Pi /(n - 1)}];
   r = Sort[Rescale[Table[N[rg[[i]][[1]][[1]]], {i, 1, n, 1}]]];
   g = Sort[Rescale[Table[N[rg[[i]][[2]][[1]]], {i, 1, n, 1}]]];
   rgbcolors = 
   Table[RGBColor[N[r[[i]]], N[g[[i]]], N[b[[i]]]], {i, 1, n, 1}]
 );

 rgbcolors = getRGBColors[6];

Show[ChromaticityPlot3D["RGB", FillingStyle -> Opacity[0.5]], 
ChromaticityPlot3D[rgbcolors, PlotStyle -> PointSize[.02]]]

enter image description here

(a) What is the correct way to fix this? (b) How can I extend this to other color spaces? (c) Is it possible to achieve this in a far better and faster way than the approach I have followed?

[It will be a bonus if the color values for the points can be displayed on the chromaticity plot either statically or on mouse hover.]

$\endgroup$
  • $\begingroup$ What is your definition of labcolors being equidistant? Surely all six colors can't be pairwise equidistant from each other. $\endgroup$ – kirma Apr 4 '17 at 19:23
  • $\begingroup$ @kirma : I agree. I want a list of colors such that the distance between two consecutive colors are same and it utilizes the maximum range of the colorspace. $\endgroup$ – Majis Apr 4 '17 at 19:43
  • 1
    $\begingroup$ I use Hue /@ Most[Subdivide[n]] often $\endgroup$ – yode Apr 4 '17 at 20:34
  • $\begingroup$ @Majis I have some old code which tries to maximize various measures based on ColorDistance, but my experiences with it are not very convincing. I might later clean up some code demonstrating it, though. $\endgroup$ – kirma Apr 5 '17 at 5:41
  • $\begingroup$ @yode It's really great. But how can it be extended to other color spaces? $\endgroup$ – Majis Apr 5 '17 at 9:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.