Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

simulate_cvd

Simulate Color Vision Deficiency


Description

Transformation of R colors by simulating color vision deficiencies, based on a CVD transform matrix.

Usage

simulate_cvd(col, cvd_transform)

deutan(col, severity = 1)

protan(col, severity = 1)

tritan(col, severity = 1)

interpolate_cvd_transform(cvd, severity = 1)

Arguments

col

character. A color or vector of colors, e.g., "#FFA801" or "blue". Input col can also be a matrix with three rows containing R/G/B (0-255) values, see details.

cvd_transform

numeric 3x3 matrix, specifying the color vision deficiency transform matrix.

severity

numeric. Severity of the color vision defect, a number between 0 and 1.

cvd

list of cvd transformation matrices. See cvd for available options.

Details

Using the physiologically-based model for simulating color vision deficiency (CVD) of Machado et al. (2009), different kinds of limitations can be emulated: deuteranope (green cone cells defective), protanope (red cone cells defective), and tritanope (blue cone cells defective). The workhorse function to do so is simulate_cvd which can take any vector of valid R colors and transform them according to a certain CVD transformation matrix (see cvd) and transformation equation.

The functions deutan, protan, and tritan are the high-level functions for simulating the corresponding kind of colorblindness with a given severity. Internally, they all call simulate_cvd along with a (possibly interpolated) version of the matrices from cvd. Matrix interpolation can be carried out with the function interpolate_cvd_transform (see Examples).

If input col is a matrix with three rows named R, G, and B (top down) they are interpreted as Red-Green-Blue values within the range [0-255]. Instead of an (s)RGB color vector a matrix of the same size as the input col with the corresponding simulated Red-Green-Blue values will be returned. This can be handy to avoid too many conversions.

References

Machado GM, Oliveira MM, Fernandes LAF (2009). A Physiologically-Based Model for Simulation of Color Vision Deficiency. IEEE Transactions on Visualization and Computer Graphics. 15(6), 1291–1298. doi: 10.1109/TVCG.2009.113 Online version with supplements at http://www.inf.ufrgs.br/~oliveira/pubs_files/CVD_Simulation/CVD_Simulation.html.

Zeileis A, Fisher JC, Hornik K, Ihaka R, McWhite CD, Murrell P, Stauffer R, Wilke CO (2020). “colorspace: A Toolbox for Manipulating and Assessing Colors and Palettes.” Journal of Statistical Software, 96(1), 1–49. doi: 10.18637/jss.v096.i01

See Also

Examples

# simulate color-vision deficiency by calling `simulate_cvd` with specified matrix
simulate_cvd(c("#005000", "blue", "#00BB00"), tritanomaly_cvd["6"][[1]])

# simulate color-vision deficiency by calling the shortcut high-level function
tritan(c("#005000", "blue", "#00BB00"), severity = 0.6)

# simulate color-vision deficiency by calling `simulate_cvd` with interpolated cvd matrix
simulate_cvd(c("#005000", "blue", "#00BB00"),
             interpolate_cvd_transform(tritanomaly_cvd, severity = 0.6))

# apply CVD directly on RGB matrix
RGB <- t(hex2RGB(rainbow(3))@coords*255)
deutan(RGB)

colorspace

A Toolbox for Manipulating and Assessing Colors and Palettes

v2.0-1
BSD_3_clause + file LICENSE
Authors
Ross Ihaka [aut], Paul Murrell [aut] (<https://orcid.org/0000-0002-3224-8858>), Kurt Hornik [aut] (<https://orcid.org/0000-0003-4198-9911>), Jason C. Fisher [aut] (<https://orcid.org/0000-0001-9032-8912>), Reto Stauffer [aut] (<https://orcid.org/0000-0002-3798-5507>), Claus O. Wilke [aut] (<https://orcid.org/0000-0002-7470-9261>), Claire D. McWhite [aut] (<https://orcid.org/0000-0001-7346-3047>), Achim Zeileis [aut, cre] (<https://orcid.org/0000-0003-0918-3766>)
Initial release
2021-05-03

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.