| 1 |
% Generated by roxygen2: do not edit by hand |
| 2 |
% Please edit documentation in R/simulate_cvd.R |
| 3 |
\name{simulate_cvd} |
| 4 |
\alias{simulate_cvd} |
| 5 |
\alias{deutan} |
| 6 |
\alias{protan} |
| 7 |
\alias{tritan} |
| 8 |
\alias{interpolate_cvd_transform} |
| 9 |
\title{Simulate Color Vision Deficiency} |
| 10 |
\usage{ |
| 11 |
simulate_cvd(col, cvd_transform, linear = TRUE) |
| 12 |
|
| 13 |
deutan(col, severity = 1, linear = TRUE) |
| 14 |
|
| 15 |
protan(col, severity = 1, linear = TRUE) |
| 16 |
|
| 17 |
tritan(col, severity = 1, linear = TRUE) |
| 18 |
|
| 19 |
interpolate_cvd_transform(cvd, severity = 1) |
| 20 |
} |
| 21 |
\arguments{ |
| 22 |
\item{col}{vector of R colors. Can be any of the three kinds of R colors, |
| 23 |
i.e., either a color name (an element of \code{\link[grDevices]{colors}}), a hexadecimal (hex) |
| 24 |
string of the form \code{"#rrggbb"} or \code{"#rrggbbaa"} (see \code{\link[grDevices]{rgb}}), or |
| 25 |
an integer \code{i} meaning \code{palette()[i]}. Additionally, \code{col} can be |
| 26 |
a formal \code{\link[colorspace]{color-class}} object or a matrix with three named |
| 27 |
rows (or columns) containing R/G/B (0-255) values.} |
| 28 |
|
| 29 |
\item{cvd_transform}{numeric 3x3 matrix, specifying the color vision deficiency transform matrix.} |
| 30 |
|
| 31 |
\item{linear}{logical. Should the color vision deficiency transformation be applied to the |
| 32 |
linearized RGB coordinates (default)? If \code{FALSE}, the transformation is applied to the |
| 33 |
gamma-corrected sRGB coordinates (which was the default up to version 2.0-3 of the package).} |
| 34 |
|
| 35 |
\item{severity}{numeric. Severity of the color vision defect, a number between 0 and 1.} |
| 36 |
|
| 37 |
\item{cvd}{list of cvd transformation matrices. See \code{\link{cvd}} for available options.} |
| 38 |
} |
| 39 |
\value{ |
| 40 |
A color object as specified in the input \code{col} (hexadecimal string, RGB matrix, |
| 41 |
or formal color class) with simulated color vision deficiency. |
| 42 |
} |
| 43 |
\description{ |
| 44 |
Transformation of R colors by simulating color vision deficiencies, |
| 45 |
based on a CVD transform matrix. |
| 46 |
} |
| 47 |
\details{ |
| 48 |
Using the physiologically-based model for simulating color vision deficiency (CVD) |
| 49 |
of Machado et al. (2009), different kinds of limitations can be |
| 50 |
emulated: deuteranope (green cone cells defective), protanope (red cone cells defective), |
| 51 |
and tritanope (blue cone cells defective). |
| 52 |
The workhorse function to do so is \code{simulate_cvd} which can take any vector |
| 53 |
of valid R colors and transform them according to a certain CVD transformation |
| 54 |
matrix (see \code{\link{cvd}}) and transformation equation. |
| 55 |
|
| 56 |
The functions \code{deutan}, \code{protan}, and \code{tritan} are the high-level functions for |
| 57 |
simulating the corresponding kind of colorblindness with a given severity. |
| 58 |
Internally, they all call \code{simulate_cvd} along with a (possibly interpolated) |
| 59 |
version of the matrices from \code{\link{cvd}}. Matrix interpolation can be carried out with |
| 60 |
the function \code{interpolate_cvd_transform} (see examples). |
| 61 |
|
| 62 |
If input \code{col} is a matrix with three rows named \code{R}, \code{G}, and |
| 63 |
\code{B} (top down) they are interpreted as Red-Green-Blue values within the |
| 64 |
range \code{[0-255]}. Then the CVD transformation is applied directly to these |
| 65 |
coordinates avoiding any further conversions. |
| 66 |
|
| 67 |
Finally, if \code{col} is a formal \code{\link[colorspace]{color-class}} object, then its |
| 68 |
coordinates are transformed to (s)RGB coordinates, as described above, and returned as a formal |
| 69 |
object of the same class after the color vision deficiency simulation. |
| 70 |
|
| 71 |
Up to version 2.0-3 of the package, the CVD transformations had been applied |
| 72 |
directly to the gamma-corrected sRGB coordinates (corresponding to the hex coordinates |
| 73 |
of the colors), following the illustrations of Machado et al. (2009). However, |
| 74 |
the paper implicitly relies on a linear RGB space (see page 1294, column 1) where their |
| 75 |
linear matrix transformations for simulating color vision deficiencies are applied. |
| 76 |
Therefore, starting from version 2.1-0 of the package, a new argument \code{linear = TRUE} |
| 77 |
has been added that first maps the provided colors to linearized RGB coordinates, applies |
| 78 |
the color vision deficiency transformation, and then maps back to gamma-corrected sRGB |
| 79 |
coordinates. Optionally, \code{linear = FALSE} can be used to restore the behavior |
| 80 |
from previous versions. For most colors the difference between the two strategies is |
| 81 |
negligible but for some highly-saturated colors it becomes more noticable, e.g., for |
| 82 |
red, purple, or orange. |
| 83 |
} |
| 84 |
\examples{ |
| 85 |
# simulate color-vision deficiency by calling `simulate_cvd` with specified matrix |
| 86 |
simulate_cvd(c("#005000", "blue", "#00BB00"), tritanomaly_cvd["6"][[1]]) |
| 87 |
|
| 88 |
# simulate color-vision deficiency by calling the shortcut high-level function |
| 89 |
tritan(c("#005000", "blue", "#00BB00"), severity = 0.6) |
| 90 |
|
| 91 |
# simulate color-vision deficiency by calling `simulate_cvd` with interpolated cvd matrix |
| 92 |
simulate_cvd(c("#005000", "blue", "#00BB00"), |
| 93 |
interpolate_cvd_transform(tritanomaly_cvd, severity = 0.6)) |
| 94 |
|
| 95 |
# apply CVD directly on wide RGB matrix (with R/G/B channels in rows) |
| 96 |
RGB <- diag(3) * 255 |
| 97 |
rownames(RGB) <- c("R", "G", "B") |
| 98 |
deutan(RGB) |
| 99 |
|
| 100 |
} |
| 101 |
\references{ |
| 102 |
Machado GM, Oliveira MM, Fernandes LAF (2009). |
| 103 |
\dQuote{A Physiologically-Based Model for Simulation of Color Vision Deficiency.} |
| 104 |
\emph{IEEE Transactions on Visualization and Computer Graphics}. \bold{15}(6), 1291--1298. |
| 105 |
\doi{10.1109/TVCG.2009.113} |
| 106 |
Online version with supplements at |
| 107 |
\url{http://www.inf.ufrgs.br/~oliveira/pubs_files/CVD_Simulation/CVD_Simulation.html}. |
| 108 |
|
| 109 |
Zeileis A, Fisher JC, Hornik K, Ihaka R, McWhite CD, Murrell P, Stauffer R, Wilke CO (2020). |
| 110 |
\dQuote{colorspace: A Toolbox for Manipulating and Assessing Colors and Palettes.} |
| 111 |
\emph{Journal of Statistical Software}, \bold{96}(1), 1--49. |
| 112 |
\doi{10.18637/jss.v096.i01} |
| 113 |
} |
| 114 |
\seealso{ |
| 115 |
\code{\link{cvd}} |
| 116 |
} |
| 117 |
\keyword{colorblind} |
| 118 |
\keyword{colors} |
| 119 |
\keyword{cvd} |