Color Vision Deficiency Emulation

Overview

Different kinds of limitations can be emulated using the physiologically-based model for simulating color vision deficiency (CVD) of Machado et al. [7]: deuteranomaly (green cone cells defective), protanomaly (red cone cells defective), and tritanomaly (blue cone cells defective). While most other CVD simulations handle only dichromacy, where one of three cones is non-functional, Machado et al. [7] provides a unified model of both dichromacy and anomalous trichromacy, where one cone has shifted spectral sensitivity. As anomalous trichromacy is the most common form of color vision deficiency, it is important to emulate along with the rarer, but more severe dichromacy.

The workhorse function to emulate color vision deficiencies is simulate_cvd(), which can take any vector of valid R colors and transform them according to a certain CVD transformation matrix and transformation equation. The transformation matrices have been established by Machado et al. [7] and are provided by methods of the CVD. The convenience interfaces deutan, protan, tritan are the high-level functions for simulating the corresponding kind of color blindness with a given severity. A severity of 1 corresponds to dichromacy, 0 to normal color vision, and intermediate values to varying severities of anomalous trichromacy.

For further guidance on color blindness in relation to statistical graphics see Lumley [6] which accompanies the R package dichromat [6] and is based on earlier emulation techniques [1, 11, 12].

Illustration: Heatmap with sequential palette

To illustrate that poor color choices can severely reduce the usefulness of a statistical graphic for readers with color vision deficiencies, we employ the infamous RGB rainbow color palette in a heatmap. In base R this can be generated by rainbow(end = 2/3, rev = True)(11) ranging from red (for high values) to blue (for low values).

The poor results for the RGB rainbow palette are contrasted with a proper sequential palette ranging from dark blue to light yellow: sequential_hcl("Blue-Yellow")(11).

The statistical graphic employed for illustration is a heatmap of the well-known Maunga Whau volcano data from base R. This heatmap is easily available as demoplot(x, "Heatmap") where x is the color vector to be used, e.g.,

In [1]: from colorspace import rainbow, deutan

In [2]: print(rainbow(end = 2/3, rev = True)(11))
['#0000FF', '#0066FF', '#00CCFF', '#00FFCC', '#00FF66', '#00FF00', '#66FF00', '#CCFF00', '#FFCC00', '#FF6600', '#FF0000']

In [3]: print(deutan(rainbow(end = 2/3, rev = True)(11)))
['#003DFB', '#0067FC', '#93B3FE', '#DDDAD0', '#EBD773', '#EFD63A', '#F5DB39', '#FFEC35', '#F2D820', '#B8A400', '#A39000']

and so on. To aid the interpretation of the heatmap a perspective display using only gray shades is included first, providing another intuitive display of what the terrain around Maunga Whau looks like.

(Source code)

Subsequently, all combinations of palette and color vision deficiency are visualized. Additionally, a grayscale version is created with desaturate.

(Source code, png, hires.png, pdf)

../_images/cvd-2.png

This clearly shows how poorly the RGB rainbow performs, often giving quite misleading impressions of the terrain around Maunga Whau. In contrast, the HCL-based blue-yellow palette works reasonably well in all settings. The most important problem of the RGB rainbow is that it is not monotonic in luminance, making correct interpretation quite hard. Moreover, the red-green contrasts deteriorate substantially in the dichromatic emulations.

Illustration: Map with diverging palette

As another example for the poor performance of the RGB rainbow we employ a shaded map. This is available as demoplot(x, "Map") and is based on county polygons for Alabama, Georgia, and South Carolina along with an artifical variable used for coloring.

Often the red-yellow-green RGB spectrum is used for a diverging palette with yellow as the neutral value. In base R this can be generated by rainbow(end = 1/3)(11). However, this palette has again a number of weaknesses, especially that the green-yellow part of the palette almost collapses to the same color when desaturated or when color blindness is emulated.

To illustrate that much more balanced palettes for the same purpose are available the Geyser palette (mimicked from CARTO 2019) is adopted: divergingx_hcl("Geyser"")(11).

(Source code, png, hires.png, pdf)

../_images/cvd-3.png

While many versions of the RGB rainbow displays are hard to read because they do not bring out any differences in the green-yellow arm of the palette, the HCL-based palette works reasonably well in all settings. Only the grayscale version cannot bring out the different arms of the palette. However, at least both directions of deviation are visible even if they cannot be distinguished. This is preferable to the RGB rainbow which hides all differences in the green-yellow arm of the palette. (However, if grayscale printing is desired a sequential rather than a diverging palette is probably necessary.)

Manipulating figures

In addition of converting colors and palettes the function cvd_emulator() allows to take an existing pixel image (JPG, PNG) and emulate how people with visual constraints will receive the same picture. This requires imageio to be installed (see Package Installation).

The first argument of cvd_emulator() can be a path to any pixel image on your local computer OR the string “DEMO”. When “DEMO” is used a demo image included in the package will be used (thanks to @mariogogh on unsplash.com; the bird is used to show handling of transparency). The following shows the original (full color) image.

In [4]: from colorspace import cvd_emulator

In [5]: cvd_emulator("DEMO", "original", figsize = (8, 3.5))
savefig/cvd_cvd_emulator_demo_original.png

cvd_emulator() allows simulate deuteranope, protanope, tritanope, and desaturated versions with different severities (defaults to severity = 1.0). The function reads the RGB(+alpha) coordinates of the pixel image, creates an sRGB <colorspace.colorlib.sRGB> object, and calls the requested functions (deutan, protan, tritan, and desaturate) before re-creating the image.

In [6]: from colorspace import cvd_emulator

In [7]: cvd_emulator("DEMO", ["deutan", "protan", "tritan", "desaturate"], figsize = (10, 6))
savefig/cvd_cvd_emulator_demo_2x2.png

The additional argument output (path to file) can be used to store the result rather than displaying it.

References

[1]

H Brettel, F Viénot, and J D Mollon. Computerized simulation of color appearance for dichromats. Journal of the Optical Society of America A, 14:2647–2655, 1997. doi:10.1364/josaa.14.002647.

[2]

Fabio Crameri. Geodynamic diagnostics, scientific visualisation and \textit StagLab 3.0. Geoscientific Model Development, 11(6):2541–2562, 2018. doi:10.5194/gmd-11-2541-2018.

[3]

Mark A. Harrower and Cynthia A. Brewer. \textit ColorBrewer.org: an online tool for selecting color schemes for maps. The Cartographic Journal, 40:27–37, 2003. URL: http://ColorBrewer.org/.

[4]

Ed Hawkins, Doug McNeall, David Stephenson, Jonny Williams, and Dave Carlson. The end of the rainbow – an open letter to the climate science community. 2014. URL: http://www.climate-lab-book.ac.uk/2014/end-of-the-rainbow/.

[5]

Thomas Kneib. Mixed model-based inference in geoadditive hazard regression for interval-censored survival times. Computational Statistics & Data Analysis, 51:777–792, 2006. Figure 5 (left). doi:10.1016/j.csda.2006.06.019.

[6] (1,2)

Thomas Lumley. \textit dichromat: Color Schemes for Dichromats. 2013. \textsf R package version 2.0-0. URL: https://CRAN.R-project.org/package=dichromat.

[7] (1,2,3)

Gustavo M. Machado, Manuel M. Oliveira, and Leandro A. F. Fernandes. A physiologically-based model for simulation of color vision deficiency. IEEE Transactions on Visualization and Computer Graphics, 15(6):1291–1298, 2009. URL: http://www.inf.ufrgs.br/~oliveira/pubs_files/CVD_Simulation/CVD_Simulation.html, doi:10.1109/TVCG.2009.113.

[8]

P. S. Quinan, L. M. Padilla, S. H. Creem-Regehr, and M. Meyer. Examining implicit discretization in spectral schemes. In M. Gleicher, H. Leitte, and I. Viola, editors, Eurographics Conference on Visualization (EuroVis) 2019, volume 38, 3. John Wiley & Sons, 2019. URL: https://vdl.sci.utah.edu/publications/2019_eurovis_implicit-discretization/.

[9]

Karthik Ram and Hadley Wickham. \textit wesanderson: A Wes Anderson Palette Generator. 2018. \textsf R package version 0.3.6. URL: https://CRAN.R-project.org/package=wesanderson.

[10]

Reto Stauffer, Georg J. Mayr, Markus Dabernig, and Achim Zeileis. Somewhere over the rainbow: how to make effective use of colors in meteorological visualizations. Bulletin of the American Meteorological Society, 96(2):203–216, 2015. doi:10.1175/BAMS-D-13-00155.1.

[11]

F Viénot, H Brettel, and J D Mollon. Digital video colourmaps for checking the legibility of displays by dichromats. Color Research and Application, 24(4):243–252, 1999. doi:10.1002/(sici)1520-6378(199908)24:4<243::aid-col5>3.3.co;2-v.

[12]

F Viénot, H Brettel, L Ott, A B M'Barek, and J D Mollon. What do colour-blind people see? Nature, 376:127–128, 1995. doi:10.1038/376127a0.

[13]

Wikipedia. CIELAB color space — Wikipedia, the free encyclopedia. 2021. Accessed 2021-06-09. URL: https://en.wikipedia.org/wiki/CIELAB_color_space.

[14]

Leland Wilkinson. The Grammar of Graphics. Springer-Verlag, 2nd edition, 2005.

[15]

Achim Zeileis, Kurt Hornik, and Paul Murrell. Escaping RGBland: selecting colors for statistical graphics. Report 61, Department of Statistics and Mathematics, Wirtschaftsuniversität Wien, Research Report Series, November 2007. URL: http://epub.wu-wien.ac.at/.

[16]

CARTO. Cartocolors – data-driven color schemes. 2019. URL: https://carto.com/carto-colors/.