Oklab color space explained

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]

Coordinates

Oklab uses the same spatial structure as CIELAB, representing color using three components:

Like CIELCh, Oklch represents colors using:

Achromatic colors

Neutral greys, pure black and the reference white are achromatic, that is,

C=0

,

a=0

,

b=0

, and h is undefined. Assigning any real value to their hue component has no effect on conversions between color spaces.[2]

While pure black is a coordinate singularity in Oklab and Oklch spaces, high-dynamic-range displays can display many chromatic colors (

C>0

) at

L=1

(the lightness of the reference white) due to the extended gamut.

Color differences

The perceptual color difference in Oklab is calculated as the Euclidean distance between the coordinates.[7] [2]

Conversions between color spaces

Conversion to and from Oklch

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}

Conversion from CIE XYZ

Converting from CIE XYZ with a Standard Illuminant D65 involves:[1]

  1. Converting to an LMS color space with a linear map:

\begin{bmatrix}l\m\s\end{bmatrix}=M1\begin{bmatrix}X\Y\Z\end{bmatrix}

  1. Applying a cube root non-linearity:

\begin{bmatrix}l'\m'\s'\end{bmatrix}=\begin{bmatrix}l1/3\m1/3\s1/3\end{bmatrix}

  1. Converting to Oklab with another linear map:

\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}

Conversion from sRGB

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}

Conversion to CIE XYZ and sRGB

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}

Notes and References

  1. Web site: Ottosson . Björn . A perceptual color space for image processing . GitHub Pages . 24 July 2024 . 23 Dec 2020.
  2. CSS Color Module Level 4 . W3C . Candidate recommendation draft . 24 July 2024.
  3. CSS Color Module Level 5 . W3C . Working draft . 25 July 2024.
  4. Web site: Oklab color model . Can I Use . 24 July 2024.
  5. Web site: Sitnik . Andrey . Turner . Travis . OKLCH in CSS: why we moved from RGB and HSL . Evil Martians . 24 July 2024 . 25 January 2023.
  6. Web site: Levien . Raph . An interactive review of Oklab . GitHub Pages . 24 July 2024 . 18 January 2021.
  7. Web site: Lilley . Chris . Better than Lab? Gamut reduction CIE Lab & OKLab . W3C . 24 July 2024 . July 2021.