Oklab and Oklch | |
Status: | Recommendation draft |
Organization: | W3C |
Committee: | CSS Working Group |
Series: | CSS Color |
Predecessor: | CIELAB color space |
Domain: | Color model |
License: | Public domain |
The Oklab color space is a uniform color space for device independent color designed to improve perceptual uniformity, hue and lightness prediction, color blending, and usability while ensuring numerical stability and ease of implementation.[1] Introduced by Björn Ottosson in December 2020, Oklab and its cylindrical counterpart, Oklch, have been included in the CSS Color Level 4 and Level 5 drafts for device-independent web colors since December 2021.[2] [3] They are supported by recent versions of major web browsers[4] and allow the specification of wide-gamut P3 colors.[5]
Oklab's model is fitted with improved color appearance data: CAM16 data for lightness and chroma, and IPT data for hue. The new fit addresses issues such as unexpected hue and lightness changes in blue colors present in the CIELAB color space, simplifying the creation of color schemes and smoother color gradients.[1] [5] [6]
Oklab uses the same spatial structure as CIELAB, representing color using three components:
Like CIELCh, Oklch represents colors using:
Neutral greys, pure black and the reference white are achromatic, that is,
C=0
a=0
b=0
While pure black is a coordinate singularity in Oklab and Oklch spaces, high-dynamic-range displays can display many chromatic colors (
C>0
L=1
The perceptual color difference in Oklab is calculated as the Euclidean distance between the coordinates.[7] [2]
Like CIELCh, the Cartesian coordinates a and b are converted to the polar coordinates C and h as follows:
\begin{align} C&=\sqrt{a2+b2}\\ h&=\operatorname{atan2}(b,a) \end{align}
And the polar coordinates are converted to the Cartesian coordinates as follows:
\begin{align} a&=C\cos(h)\\ b&=C\sin(h) \end{align}
Converting from CIE XYZ with a Standard Illuminant D65 involves:[1]
\begin{bmatrix}l\ m\ s\end{bmatrix}=M1\begin{bmatrix}X\ Y\ Z\end{bmatrix}
\begin{bmatrix}l'\ m'\ s'\end{bmatrix}=\begin{bmatrix}l1/3\ m1/3\ s1/3\end{bmatrix}
\begin{bmatrix}L\ a\ b\end{bmatrix}=M2\begin{bmatrix}l'\ m'\ s'\end{bmatrix}
Given:
\begin{align} M1&=\begin{bmatrix} 0.8189330101&\phantom{-}0.3618667424&-0.1288597137\\ 0.0329845436&\phantom{-}0.9293118715&\phantom{-}0.0361456387\\ 0.0482003018&\phantom{-}0.2643662691&\phantom{-}0.6338517070 \end{bmatrix}\\ M2&=\begin{bmatrix} 0.2104542553&\phantom{-}0.7936177850&-0.0040720468\\ 1.9779984951&-2.4285922050&\phantom{-}0.4505937099\\ 0.0259040371&\phantom{-}0.7827717662&-0.8086757660 \end{bmatrix} \end{align}
Converting from sRGB requires first converting from sRGB to CIE XYZ with a Standard Illuminant D65. As the last step of this conversion is a linear map from linear RGB to CIE XYZ, the reference implementation directly employs the multiplied matrix representing the composition of the two linear maps:[1]
\begin{bmatrix}l\ m\ s\end{bmatrix}= \begin{bmatrix} 0.4122214708&0.5363325363&0.0514459929\\ 0.2119034982&0.6806995451&0.1073969566\\ 0.0883024619&0.2817188376&0.6299787005 \end{bmatrix} \begin{bmatrix}Rlinear\ Glinear\ Blinear\end{bmatrix}
Converting to CIE XYZ and sRGB simply involves applying the respective inverse functions in reverse order:[1]
\begin{align} \begin{bmatrix}l'\ m'\ s'\end{bmatrix}&=
-1 | |
M | |
2 |
\begin{bmatrix}L\ a\ b\end{bmatrix}\\ \begin{bmatrix}l\ m\ s\end{bmatrix}&=\begin{bmatrix}\left(l'\right)3\ \left(m'\right)3\ \left(s'\right)3\end{bmatrix}\\ \begin{bmatrix}X\ Y\ Z\end{bmatrix}&=
-1 | |
M | |
1 |
\begin{bmatrix}l'\ m'\ s'\end{bmatrix} \end{align}