Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change the CVD simulation matrices to use the more accurate Viénot model #28

Merged
merged 1 commit into from
Nov 2, 2021

Conversation

nburrus
Copy link
Contributor

@nburrus nburrus commented Oct 29, 2021

Hi! I've recently been reviewing the CVD simulation models used in opensource software, and it turns out that the currently used ColorMatrix from colorjack.com are very inaccurate. I wrote a full article about that, but in a nutshell these matrices were a quick hack that the author himself recognized to be a very inaccurate approximation of the more complex "HCIRN Color Blind Simulation function". The implementation used in Coblis by MaPePeR shows the comment:

You're right, the ColorMatrix version is very simplified, and not accurate. I created that color matrix one night (http://www.colorjack.com/labs/colormatrix/) and since then it's shown up many places... I should probably take that page down before it spreads more! Anyways, it gives you an idea of what it might look like, but for the real thing...

A more solid reference is the paper of Viénot, Brettel and Mollon in 1999 Digital video colourmaps for checking the legibility of displays by dichromats. This is the simulation part used by most daltonization algorithms. The cool thing is that it also reduces to a single 3x3 matrix at the end, so this PR switches to these matrices instead of the ones from colorjack.com.

An important note is that for all these models to be correct we first need to go from the sRGB color space to a linear RGB color space. Fortunately this is easy to enforce for SVG filters with color-interpolation-filters="linearRGB". This PR also adds that.

This Viénot model is pretty good for protanopia and deuteranopia (with all the limits of that kind of simulator of course..), but not great for tritanopia. However none will be great with a single matrix, we'd need to implement for example the Brettel, Viénot and Mollon Computerized simulation of color appearance for dichromats 1997 algorithm for that, but it requires two matrices and a per-pixel dot product test to find out which projection it should use. I'm not very familiar with SVG filters but it does not seem trivial to do, so the Viénot model is probably a reasonable single-matrix fallback.

An alternative to Viénot 1999 would be the Machado 2009 algorithm, they also provide single precomputed 3x3 matrices on their website. I picked Viénot in this PR because I'm more familiar with it but the final results will be kind of similar anyway.

I've included a Jupyter notebook to show how I dumped the precomputed values for each deficiency. For the anomalous versions, I picked 0.6 as the severity factor to be close to the original "HCIRN Color Blind Simulation function" code. There is no real justification to pick that number versus another, but I guess it's a reasonable choice to give an idea of what a less severe deficiency would look like.

Hope this helps!

…rettel and Mollon model.

Also fix the filter color space to be in linearRGB.
@oftheheadland
Copy link
Owner

Thank you taking the time to do this @nburrus! Your changes look great and this really helps out the project.

Your website is very interesting as well, I'm a fan of your work 😄

@oftheheadland oftheheadland merged commit 5241303 into oftheheadland:master Nov 2, 2021
@mathiasbynens
Copy link

Much thanks to @nburrus for pointing this out, and discovering a similar issue in Chromium as well.

I wanted to point out that the color-interpolation-filters="linearRGB" attribute should in theory not be necessary, as linearRGB is the implicit default per spec. But in practice it’s necessary because of https://bugs.chromium.org/p/chromium/issues/detail?id=335066. Once that bug is fixed, the attribute could be removed again.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants