1 \documentclass{article}
2 \usepackage{url,amsmath,mathtools}
3 \usepackage[landscape]{geometry}
4 \title{Colour conversions for DCP creation}
5 \author{Carl Hetherington, Dennis Couzin}
12 The process of conversion from RGB to XYZ is:
15 \item Convert to linear RGB (i.e.\ apply a gamma curve, or at least an approximation to one).
16 \item Convert to XYZ (preserving the white point).
17 \item Adjust the white point.
18 \item Normalize values.
19 \item Convert to non-linear XYZ (i.e.\ apply a gamma curve)
23 \section{Convert to linear RGB}
25 This is done using either a `pure' gamma function, so that for some colour value $C_i$ the output colour $C_o$ is given by
31 or a modified function of the form
36 \frac{C_i}{K} & C_i \leq C_t \\
37 \left( \frac{C_i + A}{1 + A} \right)^\zeta & C_i > C_t
42 where $K$, $A$, $C_t$ and $\zeta$ are constants. This modified function approximates a `pure' gamma function but changes the output for small inputs.
45 \section{Convert to XYZ}
47 This is done by multiplying the colours by a $3\times{}3$ matrix.
48 This matrix depends on the chromaticities of the RGB primaries and the
49 white point. Note that these are the same for BT709 and sRGB, so the
50 corresponding matrices are the same.
52 The chromaticities for sRGB and BT709 are shown in
53 Table~\ref{tab:chromaticities}. The white point is ($x = 0.3127$, $y
54 = 0.329$); this is called D65.
58 \begin{tabular}{|l|l|l|}
70 \caption{RGB chromaticities for sRGB and BT709}
71 \label{tab:chromaticities}
77 D &= \left|\begin{matrix} R_x - W_x & W_x - B_x \\ R_y - W_y & W_y - B_y \end{matrix} \right| \\
78 E &= \left|\begin{matrix} W_x - G_x & R_x - W_x \\ W_y - G_y & R_y - W_y \end{matrix} \right| \\
79 F &= \left|\begin{matrix} W_x - G_x & W_x - B_x \\ W_y - G_y & W_y - B_y \end{matrix} \right| \\
80 P &= R_y + G_y \frac{D}{F} + B_y \frac{E}{F}
86 \item $R_x$, $R_y$: red point; $R_z = 1 - R_x - R_y$
87 \item $G_x$, $G_y$: green point; $G_z = 1 - G_x - G_y$
88 \item $B_x$, $B_y$: blue point; $B_z = 1 - B_x - B_y$
89 \item $W_x$, $W_y$: white point
92 Then the conversion matrix $\mathbf{C}$ is as follows:
95 \mathbf{C} &= \frac{1}{P} \left[\begin{matrix}
96 R_x & G_x\dfrac{D}{F} & B_x\dfrac{E}{F} \\[2ex]
97 R_y & G_y\dfrac{D}{F} & B_y\dfrac{E}{F} \\[2ex]
98 R_z & G_z\dfrac{D}{F} & B_z\dfrac{E}{F} \\[2ex]
99 \end{matrix}\right] = \left[\begin{matrix}
100 0.4123908 & 0.3575843 & 0.1804808 \\
101 0.2126390 & 0.7151687 & 0.0721923 \\
102 0.0193308 & 0.1191948 & 0.9505322 \\
106 Then to convert RGB to XYZ we do
109 \left[\begin{matrix} X \\ Y \\ Z \\ \end{matrix}\right] &= \mathbf{C} \left[\begin{matrix} R \\ G \\ B \\ \end{matrix}\right]
111 \left[\begin{matrix} X \\ Y \\ Z \\ \end{matrix}\right] &= \left[\begin{matrix}
112 0.4123908 & 0.3575843 & 0.1804808 \\
113 0.2126390 & 0.7151687 & 0.0721923 \\
114 0.0193308 & 0.1191948 & 0.9505322 \\
115 \end{matrix}\right] \left[\begin{matrix} R \\ G \\ B \\ \end{matrix}\right]
118 Note: there is also a CIE definition of the D65 white point as ($x =
119 0.31272$, $y = 0.32903$), which we do not use.
122 \section{Adjust the white point}
124 If required we can adjust the white point of the colours from one
125 white point $\mathbf{S_1}$ to another $\mathbf{S_2}$. This is done by multiplication by
126 a Bradford matrix, $\mathbf{B}$. To calculate it, we start with the
127 Bradford chromatic adaption transform matrix $\mathbf{M}$, taken from
128 S\"usstrunk et al., \textit{Chromatic adaption performance of
129 different RGB sensors}, IS\&T/SPIE Electronic Imaging, SPIE
133 \mathbf{M} &= \left[\begin{matrix}
134 0.8951 & 0.2664 & -0.1614 \\
135 -0.7502 & 1.7135 & 0.0367 \\
136 0.0389 & -0.0685 & 1.0296 \\
140 The inverse of $\mathbf{M}$ is
142 \mathbf{M}^{-1} &= \left[\begin{matrix}
143 0.9869929055 & -0.1470542564 & 0.1599626517 \\
144 0.4323052697 & 0.5183602715 & 0.0492912282 \\
145 -0.0085286646 & 0.0400428217 & 0.9684866958 \\
149 Next, compute $\mathbf{G}$ and $\mathbf{H}$ as follows
152 \mathbf{G} &= \mathbf{M} \left[\begin{matrix} \dfrac{S_{1x}}{S_{1y}} \\[2ex] 1 \\ \dfrac{1 - S_{1x} - S_{1y}}{S_{1y}} \\[2ex] \end{matrix}\right] \\
153 \mathbf{H} &= \mathbf{M} \left[\begin{matrix} \dfrac{S_{2x}}{S_{2y}} \\[2ex] 1 \\ \dfrac{1 - S_{2x} - S_{2y}}{S_{2y}} \\[2ex] \end{matrix}\right]
156 Then the Bradford matrix $\mathbf{B}$ is given by
159 \mathbf{B} &= \mathbf{M}^{-1}
160 \left(\left[\begin{matrix} \dfrac{H_1}{G_1} & 0 & 0 \\ 0 & \dfrac{H_2}{G_2} & 0 \\ 0 & 0 & \dfrac{H_3}{G_3} \\ \end{matrix}\right] \mathbf{M}\right) \\
164 \section{Normalize values}
166 Here we just multiply all colour values by the constant $N$ where
169 N &= \frac{48}{52.37}
173 \section{Convert to non-linear XYZ}
175 This is a gamma correction of $1/2.6$, so that for some colour value $C_i$ the output colour $C_o$ is given by
182 \section{Converting from a colour matrix to chromaticities}
184 To get back from a colour matrix $\mathbf{C}$ to the chromaticities:
187 R_x &= \frac{C_{11}}{C_{11} + C_{21} + C_{31}} \\
188 R_y &= \frac{C_{21}}{C_{11} + C_{21} + C_{31}} \\
189 G_x &= \frac{C_{12}}{C_{12} + C_{22} + C_{32}} \\
190 G_y &= \frac{C_{22}}{C_{12} + C_{22} + C_{32}} \\
191 B_x &= \frac{C_{13}}{C_{13} + C_{23} + C_{33}} \\
192 B_y &= \frac{C_{23}}{C_{13} + C_{23} + C_{33}} \\
193 W_x &= \frac{C_{11} + C_{12} + C_{13}}{C_{11} + C_{12} + C_{13} + C_{21} + C_{22} + C_{23} + C_{31} + C_{32} + C_{33}} \\
194 W_y &= \frac{C_{21} + C_{22} + C_{23}}{C_{11} + C_{12} + C_{13} + C_{21} + C_{22} + C_{23} + C_{31} + C_{32} + C_{33}}