Generate maximally perceptually-distinct colors
Editor's Note: This file was selected as MATLAB Central Pick of the Week
When plotting a set of lines, you may want to distinguish them by color. By default, Matlab chooses a small set of colors and cycles among them, and so if you have more than a few lines there will be confusion about which line is which. To fix this problem, one would want to be able to pick a much larger set of distinct colors, where the number of colors equals or exceeds the number of lines you want to plot. Because our ability to distinguish among colors has limits, one should choose these colors to be "maximally perceptually distinguishable."
This function generates a set of colors which are distinguishable by reference to the "Lab" color space, which more closely matches human color perception than RGB. Given an initial large list of possible colors, it iteratively chooses the entry in the list that is farthest (in Lab space) from all previously-chosen entries.
Cite As
Tim Holy (2024). Generate maximally perceptually-distinct colors (https://www.mathworks.com/matlabcentral/fileexchange/29702-generate-maximally-perceptually-distinct-colors), MATLAB Central File Exchange. Retrieved .
MATLAB Release Compatibility
Platform Compatibility
Windows macOS LinuxCategories
- Image Processing and Computer Vision > Image Processing Toolbox > Image Segmentation and Analysis > Image Segmentation > L*a*b* Color Space >
Tags
Acknowledgements
Inspired by: varycolor, Colorspace Transformations
Inspired: Maximally Distinct Color Generator, Youden's plot, LCS_v1.39, LCS, Sunburst or Polar Treemap Plot and Range Plot, Explore Experimental Data, Colorize Document Bar, Intuitive RGB color values from XKCD, rgbmap color maps, MatPlotLib Perceptually Uniform Colormaps, Feedback Control of Many Differential-Drive Robots with Uniform Control Inputs, TACTICS Toolbox, Simulate Control of Magnetized Tetrahymena Pyriformis Cells, plot spread points (beeswarm plot), justinblaber/image_match
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!Discover Live Editor
Create scripts with code, output, and formatted text in a single executable document.
Version | Published | Release Notes | |
---|---|---|---|
1.2.0.0 | As suggested by Il, I added the ability to avoid multiple background colors. |
||
1.1.0.0 | I have added the option for the user to supply a function handle to any desired colorspace conversion function. One application is to use the file exchange's "colorspace" set of tools. In this case, you no longer need the image processing toolbox. |
||
1.0.0.0 |