Color.Lab
(Color v0.4.0)
Copy Markdown
CIE 1976 L*a*b* color space.
Conversions between L*a*b* and XYZ use the formulas published by
Bruce Lindbloom (http://www.brucelindbloom.com/index.html?Math.html)
with the exact CIE constants ε = 216/24389 and κ = 24389/27. The
approximate 0.008856 / 7.787 forms found in many online references are
not used.
Summary
Types
Functions
Converts a CIE XYZ color to an L*a*b* color.
Arguments
xyzis aColor.XYZstruct. Its:illuminantand:observer_anglefields select the reference white.
Returns
- A
Color.Labstruct tagged with the same illuminant and observer angle as the inputxyz.
Examples
iex> xyz = %Color.XYZ{x: 0.95047, y: 1.0, z: 1.08883, illuminant: :D65, observer_angle: 2}
iex> {:ok, lab} = Color.Lab.from_xyz(xyz)
iex> {Float.round(lab.l, 3), Float.round(lab.a, 3), Float.round(lab.b, 3)}
{100.0, 0.0, 0.0}
Converts an L*a*b* color to a CIE XYZ color.
Arguments
labis aColor.Labstruct.optionsis a keyword list.
Options
:illuminantoverrides the reference-white illuminant from thelabstruct. Defaults tolab.illuminant.:observer_angleoverrides the observer angle (2or10). Defaults tolab.observer_angle.
Returns
- A
Color.XYZstruct whoseYis on the same scale as the reference white (typicallyY ∈ [0, 1]).
Examples
iex> {:ok, xyz} = Color.Lab.to_xyz(%Color.Lab{l: 100.0, a: 0.0, b: 0.0})
iex> {Float.round(xyz.x, 4), Float.round(xyz.y, 4), Float.round(xyz.z, 4)}
{0.9505, 1.0, 1.0888}