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

simulate_cvd(col, cvd_transform, linear = TRUE)

deutan(col, severity = 1, linear = TRUE)

protan(col, severity = 1, linear = TRUE)

tritan(col, severity = 1, linear = TRUE)

interpolate_cvd_transform(cvd, severity = 1)

Arguments

col

vector of R colors. Can be any of the three kinds of R colors, i.e., either a color name (an element of colors), a hexadecimal (hex) string of the form "#rrggbb" or "#rrggbbaa" (see rgb), or an integer i meaning palette()[i]. Additionally, col can be a formal color-class object or a matrix with three named rows (or columns) containing R/G/B (0-255) values.

cvd_transform

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

linear

logical. Should the color vision deficiency transformation be applied to the linearized RGB coordinates (default)? If FALSE, the transformation is applied to the gamma-corrected sRGB coordinates (which was the default up to version 2.0-3 of the package).

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.

Value

A color object as specified in the input col (hexadecimal string, RGB matrix, or formal color class) with simulated color vision deficiency.

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]. Then the CVD transformation is applied directly to these coordinates avoiding any further conversions.

Finally, if col is a formal color-class object, then its coordinates are transformed to (s)RGB coordinates, as described above, and returned as a formal object of the same class after the color vision deficiency simulation.

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]])
#> [1] "#004F2C" "#0046D7" "#00B96F"

# simulate color-vision deficiency by calling the shortcut high-level function
tritan(c("#005000", "blue", "#00BB00"), severity = 0.6)
#> [1] "#004F2C" "#0046D7" "#00B96F"

# 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))
#> [1] "#004F2C" "#0046D7" "#00B96F"

# apply CVD directly on wide RGB matrix (with R/G/B channels in rows)
RGB <- diag(3) * 255
rownames(RGB) <- c("R", "G", "B")
deutan(RGB)
#>       [,1]     [,2]      [,3]
#> R 93.66711 219.4647   0.00000
#> G 71.42167 171.4878  12.09031
#> B  0.00000  10.9497 247.06465