Simulate colour-vision deficiency and find confusable colour pairs. Input: threshold T, then lines name #hex.
For each colour: linearize sRGB (as in Lab V6.1). To simulate, multiply the linear RGB vector by the Machado et al. (2009) matrix (severity 1.0):
- deuteranopia: [[0.367322, 0.860646, −0.227968], [0.280085, 0.672501, 0.047413], [−0.011820, 0.042940, 0.968881]]
- protanopia: [[0.152286, 1.052583, −0.204868], [0.114503, 0.786281, 0.099216], [−0.003882, −0.048116, 1.051998]]
Convert linear RGB (clipped to 0–1) to CIELAB: XYZ = M·rgb with M = [[0.4124, 0.3576, 0.1805], [0.2126, 0.7152, 0.0722], [0.0193, 0.1192, 0.9505]], divide by the D65 white (0.95047, 1.0, 1.08883), f(t) = t^(1/3) if t > (6/29)³ else t/(3(6/29)²) + 4/29, L = 116 f(Y) − 16, a = 500 (f(X) − f(Y)), b = 200 (f(Y) − f(Z)). The colour difference ΔE is the Euclidean distance in Lab.
For every pair (input order) print red-green: normal dE 119.8, deuteranopia dE 7.3 <- confusable — the normal ΔE and the smaller of the two simulated ΔEs with its deficiency name; mark pairs below the threshold. Finish with 1 confusable pair(s) for colour-vision deficiency (dE < 15).