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 {\displaystyle C=0} , a = 0 {\displaystyle a=0} , b = 0 {\displaystyle b=0} , and h is undefined. Assigning any real value to their hue component has no effect on conversions between color spaces.13
The perceptual color difference in Oklab is calculated as the Euclidean distance between the (L, a, b) coordinates.1415
Like CIELCh, the Cartesian coordinates a and b are converted to the polar coordinates C and h as follows:
C = a 2 + b 2 h = atan2 ( b , a ) {\displaystyle {\begin{aligned}C&={\sqrt {a^{2}+b^{2}}}\\h&=\operatorname {atan2} (b,a)\end{aligned}}}
And the polar coordinates are converted to the Cartesian coordinates as follows:
a = C cos ( h ) b = C sin ( h ) {\displaystyle {\begin{aligned}a&=C\cos(h)\\b&=C\sin(h)\end{aligned}}}
Converting from CIE XYZ with a Standard Illuminant D65 involves:16
Given:
M 1 = [ 0.8189330101 − 0.3618667424 − 0.1288597137 0.0329845436 − 0.9293118715 − 0.0361456387 0.0482003018 − 0.2643662691 − 0.6338517070 ] M 2 = [ 0.2104542553 − 0.7936177850 − 0.0040720468 1.9779984951 − 2.4285922050 − 0.4505937099 0.0259040371 − 0.7827717662 − 0.8086757660 ] {\displaystyle {\begin{aligned}\mathbf {M} _{1}&={\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}}\\\mathbf {M} _{2}&={\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{aligned}}}
See also: SRGB § From sRGB to CIE XYZ
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:18
Converting to CIE XYZ and sRGB simply involves applying the respective inverse functions in reverse order:19
[ l ′ m ′ s ′ ] = M 2 − 1 [ L a b ] [ l m s ] = [ ( l ′ ) 3 ( m ′ ) 3 ( s ′ ) 3 ] [ X Y Z ] = M 1 − 1 [ l m s ] {\displaystyle {\begin{aligned}{\begin{bmatrix}l'\\m'\\s'\end{bmatrix}}&=\mathbf {M} _{2}^{-1}{\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}}&=\mathbf {M} _{1}^{-1}{\begin{bmatrix}l\\m\\s\end{bmatrix}}\end{aligned}}}
However, it is not suitable for image blending or processing, for which the gamma-expanded linear RGB color space is more appropriate.[4][5] /wiki/Blend_modes ↩
Ottosson, Björn (23 Dec 2020). "A perceptual color space for image processing". GitHub Pages. Retrieved 24 July 2024. https://bottosson.github.io/posts/oklab/ ↩
CSS Color Module Level 4 (Candidate recommendation draft). W3C. Retrieved 24 July 2024. https://www.w3.org/TR/css-color-4/ ↩
CSS Color Module Level 5 (Working draft). W3C. Retrieved 25 July 2024. https://www.w3.org/TR/css-color-5/ ↩
"Oklab color model". Can I Use. Retrieved 24 July 2024. https://caniuse.com/mdn-css_types_color_oklab ↩
Sitnik, Andrey; Turner, Travis (25 January 2023). "OKLCH in CSS: why we moved from RGB and HSL". Evil Martians. Retrieved 24 July 2024. https://evilmartians.com/chronicles/oklch-in-css-why-quit-rgb-hsl ↩
Levien, Raph (18 January 2021). "An interactive review of Oklab". GitHub Pages. Retrieved 24 July 2024. https://raphlinus.github.io/color/2021/01/18/oklab-critique.html ↩
Lilley, Chris (July 2021). "Better than Lab? Gamut reduction CIE Lab & OKLab". W3C. Retrieved 24 July 2024. https://www.w3.org/Graphics/Color/Workshop/slides/talk/lilley ↩
The (l,m,s) space used here is not the same as the LMS color space, but rather an arbitrary space that was found numerically to best fit the color appearance data. /wiki/LMS_color_space ↩