3

Difference from proposed duplicate

Matlab choose random color for plotting asks how to create a colormap with randomly selected colors. I am asking how to choose visually distinct colors for a colormap. Randomly selected colors are not guaranteed to be visually distinctive. In fact, I use random colors as a counter example in my question.

If my question is going to be a duplicate, it should be a duplicate of Automatically plot different colored lines because at least one of the answers, answers my question about visually distinct colors even though the question does not ask for that detail. But none of the answers of Matlab choose random color for plotting are helpful, so don't use that one!


Original Question

The lines colormap alternates 7 colors that are visually distinct in a predefined order. flag and prism do this also. The colors repeat after 7 distinct colors for lines, 6 for prism and 4 for flag.

These colormaps are very useful for distinguishing between labeled segments in an image because labels often have consecutive values which have low visual distinctness in the jet or parula colorspaces.

For example, using the first image from the NYUv2 dataset, you can see that dishwasher and counter have almost the same color using colormap('parula')

Image segments colored with parula

It gets better for dishwasher and counter using colormap('lines'), but worse for chair and trashcan, because the value of trashcan is 12 and chair is 5. 12 mod 7 = 5, so they get the same color assignment

Image segments colored with lines

I have n labels, so I would like to define a colormap that has n alternating visually distinct colors. Then, I can avoid the problem of two labels sharing the same modulus.

I know how to create a custom colormap, but the challenge is making the colors visually distinct. One thing I tried is randomly sampling colors from jet (similar to the solutions suggested to Matlab choose random color for plotting).

c_jet = colormap('jet');
idx = randperm(size(c_jet, 1));
c_new = c_jet(idx(1:30),:);
colormap(c_new);

But the colors are not visually distinct enough. The ceiling and the wall are practically identical.

Image segments colored with random sample from jet

It may be the case that 30 distinct colors is simply too many to ask for, but I'd like a general approach that gets as close as possible.

Community
  • 1
  • 1
Cecilia
  • 4,512
  • 3
  • 32
  • 75
  • Do you mean `colormap(parula(7))`? Each colormap is a function that takes and argument. – horchler Feb 14 '17 at 21:18
  • That works for numbers < 10, but the colors are not distinctive enough for larger numbers. I would like a way of generating a color map that has n colors where you would be unlikely to confuse one color for another if you were looking at a legend for example. – Cecilia Feb 14 '17 at 22:31
  • 1
    Maybe https://www.mathworks.com/matlabcentral/fileexchange/29702-generate-maximally-perceptually-distinct-colors could help you – jodag Feb 14 '17 at 23:13
  • @jodag Nice! I'll try that out. – Cecilia Feb 14 '17 at 23:49
  • @jodag The file exchange code works perfectly. Would you like to write an answer? – Cecilia Feb 15 '17 at 18:24
  • @Cecilia Good to hear. I created an answer. – jodag Feb 15 '17 at 23:34
  • 1
    @Shai I've edited the question to clarify why it is not a duplicate, but it's been sitting on the reopen queue for several days with only 4 votes. Would you please reconsider your (deciding) close vote? – Cecilia Feb 23 '17 at 18:41

1 Answers1

1

For example from wikipedia you can get a list of distinguishable colors

Help:Distinguishable colors

The references contain a link to a stackexchange thread where you can read more.

With theses colors you can build your own colormap.

JoergVanAken
  • 1,286
  • 9
  • 10