A scientific figure has two well-known accessibility constraints which are to stay readable for colorblind readers and to hold once printed in grayscale, each one having its own set of tools with on one side the matrices from Machado et al. (2009) that simulate protanopia, deuteranopia and tritanopia, along with palettes like viridis or cividis designed to stay distinguishable under these simulations, and on the other side the grayscale conversion which relies on the luminance of the colors.
The issue is that these solutions do not overlap. A palette designed for color blindness relies on hue more than on luminance and collapses once converted to grayscale, while a palette with well-spread luminance can easily become unreadable under protanopia. Getting a palette that holds in both cases therefore requires chaining a generator, a color blindness simulator and a grayscale converter, and then validating the result visually.
Colorally covers the three steps at once.
Method
The algorithm draws colors at random and keeps them one by one, checking at each addition that they stay far enough from the colors already in the palette. The check runs in five modes at the same time, namely normal vision, protanopia, deuteranopia, tritanopia and grayscale.
The distance between two colors is measured with the CIEDE2000 formula which returns the distance perceived by the human eye, which matters more than a plain difference in RGB values since two numerically distant colors can look nearly identical to the eye. The default thresholds are ΔE ≥ 10 for normal vision and ΔE ≥ 15 for the four other modes, values set by hand through trial and error to find a balance between diversity and readability.
Grayscale conversion
The rigorous method linearizes the sRGB values before applying the luminance coefficients and then converts back to sRGB. This round trip flattens the mid-tones however and brings the colors visually closer on paper. Colorally therefore applies the coefficients directly on the sRGB values, which is less pure from a colorimetric standpoint but produces grays that are better spread when printed. Users who need strict colorimetric accuracy should take this into account.
Bound on palette size
A second greedy algorithm scans the color space to find out how large a palette the constraints allow. It stops at 5, blocked by the minimum distance imposed in grayscale. This result does not prove that 5 is the theoretical maximum but gives a reliable bound for the default settings.
Usage
The online demo covers the most common case, namely generating a palette of 2 to 5 colors ready to use with the default thresholds. Hex codes can be copied directly and the rendering in each vision mode is displayed for visual validation.
The source code is available on GitHub under the GPL-3.0 license. It allows adjusting the ΔE thresholds, changing the vision modes taken into account or running new generations with custom constraints.
github.com pieetie/colorally Source code on GitHub