Oklab color space: Difference between revisions
m Moved conversion to/from Oklch up |
m →Conversion to and from Oklch: Simpler column view Tag: Reverted |
||
Line 28: | Line 28: | ||
===Conversion to and from Oklch=== |
===Conversion to and from Oklch=== |
||
Like CIELCh, the [[Cartesian coordinate system|Cartesian coordinates]] ''a'' and ''b'' are converted to the [[Polar coordinate system|polar coordinates]] ''C'' and ''h'' as follows: |
|||
{{columns-start}} |
|||
Conversion to [[Polar coordinate system|polar coordinates]] (Oklch): |
|||
<math> |
<math> |
||
Line 36: | Line 38: | ||
\end{align} |
\end{align} |
||
</math> |
</math> |
||
{{column}} |
|||
Conversion to [[Cartesian coordinate system|Cartesian coordinates]] (Oklab): |
|||
<math> |
<math> |
||
Line 45: | Line 47: | ||
\end{align} |
\end{align} |
||
</math> |
</math> |
||
{{columns-end}} |
|||
===Conversion from CIE XYZ=== |
===Conversion from CIE XYZ=== |
Revision as of 12:49, 25 July 2024
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 2020, Oklab and its cylindrical counterpart, Oklch, have been included in the CSS Color Level 4 draft for device-independent web colors.[2] They are supported by recent versions of major web browsers[3] and allow the specification of wide-gamut P3 colors.[4]
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, and simplifies the creation of color schemes and smoother color gradients.[1][4][5]
Coordinates
Oklab uses the same spatial structure as CIELAB, representing color using three components:
- L for perceptual lightness, ranging from 0 (pure black) to 1 (reference white, if achromatic), often denoted as a percentage
- a and b for opponent channels of the four unique hues, unbounded but in practice ranging from −0.5 to +0.5
- a for green (negative) to red (positive)
- b for blue (negative) to yellow (positive)
Like CIELCh, Oklch represents colors using:
- L for perceptual lightness
- C for chroma representing chromatic intensity, with values from 0 (achromatic) with no upper limit, but in practice not exceeding +0.5
- h for hue angle in a color wheel, typically denoted in decimal degrees
Achromatic colors
Neutral greys, pure black and the reference white are achromatic, that is, , , , 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 () at (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 (L, a, b) coordinates.[6][2]
Conversion to and from Oklch
Conversion to polar coordinates (Oklch):
Conversion to Cartesian coordinates (Oklab):
Conversion from CIE XYZ
Converting from CIE XYZ with a Standard Illuminant D65 involves:[1]
- Converting to an LMS color space with a linear map:
- Applying a cube-root non-linearity:
- Converting to Oklab with another linear map:
Given:
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]
Conversion to CIE XYZ and sRGB
Converting to CIE XYZ and sRGB simply involves applying the respective inverse functions in reverse order:[1]
References
- ^ a b c d e Ottosson, Björn (23 Dec 2020). "A perceptual color space for image processing". GitHub Pages. Retrieved 24 July 2024.
- ^ a b c CSS Color Module Level 4 (Candidate recommendation draft). W3C. Retrieved 24 July 2024.
- ^ "Oklab color model". Can I Use. Retrieved 24 July 2024.
- ^ a b Sitnik, Andrey; Turner, Travis (25 January 2023). "OKLCH in CSS: why we moved from RGB and HSL". Evil Martians. Retrieved 24 July 2024.
- ^ Levien, Raph (18 January 2021). "An interactive review of Oklab". GitHub Pages. Retrieved 24 July 2024.
- ^ Lilley, Chris (July 2021). "Better than Lab? Gamut reduction CIE Lab & OKLab". W3C. Retrieved 24 July 2024.