Skip to main content

CieLab

Struct CieLab 

Source
pub struct CieLab { /* private fields */ }

Implementations§

Source§

impl CieLab

Source

pub fn new(lab: [f64; 3], xyzn: XYZ) -> CieLab

Creates a new CIE Lab* color from the given Lab* values and reference white.

§Arguments
  • lab - The Lab* color values as an array of three f64 values.
  • white_point - The reference white tristimulus value.
§Returns

A new CieLab instance.

Source

pub fn a(&self) -> f64

Source

pub fn b(&self) -> f64

Source

pub fn l(&self) -> f64

Source

pub fn from_rxyz(xyz: RelXYZ) -> CieLab

Creates a new CIE Lab* color from the given XYZ color and reference white.

§Arguments
  • rxyz - The RelXYZ color to convert.
§Returns

A Result containing the CIE Lab* color or an error if the observers do not match.

Source

pub fn rxyz(&self) -> RelXYZ

Converts the CIE L*a*b* color back to XYZ using the reference white.

§Returns

The XYZ color corresponding to the CIE L*a*b* values.

Source

pub fn xyz(&self) -> XYZ

Converts the CIE L*a*b* color back to XYZ using the reference white.

§Returns

The XYZ color corresponding to the CIE L*a*b* values.

Source

pub fn white_point(&self) -> XYZ

Returns the reference white tristimulus value for this CIE Lab* color.

Source

pub fn set_white_luminance(self, luminance: f64) -> CieLab

Sets the reference white luminance for this CIE Lab* color, in units of cd/m².

§Arguments
  • luminance - The desired luminance level for the reference white.
§Returns

A new CieLab instance with the adjusted luminance.

This adjusts the reference white to the specified illuminance level.

§Notes
  • This does not change the L*a*b* values directly; it modifies the reference white to scale the white reference luminance.
  • Typically the value is set to 100 for normalized white luminance, but more advanced models, such as CIECAM16, may use different luminance levels for perceptual accuracy.
Source

pub fn ciede(&self, other: &Self) -> Result<f64, Error>

Computes the Euclidean ΔE*ab color difference between two CIE L*a*b* colors.

This function measures the straight-line distance in L*a*b* space: ΔE = sqrt((L₁−L₂)² + (a₁−a₂)² + (b₁−b₂)²)

§Arguments
  • other – The second Lab color to compare against.
§Returns
  • Ok(de) – The ΔE value if both colors share the same observer and illuminant.
§Errors
  • CmtError::RequireSameObserver if the two colors use different standard observers.
  • CmtError::IlluminantMismatch if they were computed under different illuminants.
§Notes

The plain Euclidean ΔE*ab is commonly used but does not always match perceived differences as well as more advanced formulas (e.g., CIEDE2000, or CIECAM16DE).

§Example
use colorimetry::{lab::CieLab, xyz::{RelXYZ, XYZ}, observer::Observer, Error};

let xyz1 = XYZ::new([36.0, 70.0, 12.0], Observer::Cie1931);
let xyz2 = XYZ::new([35.0, 71.0, 11.0], Observer::Cie1931);
let lab1 = CieLab::from_rxyz(RelXYZ::with_d65(xyz1));
let lab2 = CieLab::from_rxyz(RelXYZ::with_d65(xyz2));
let de = lab1.ciede(&lab2).unwrap();
//  ΔE=6.57
Source

pub fn ciede2000(&self, other: &Self) -> Result<f64, Error>

Computes the CIEDE2000 ΔE color difference between two CIE Lab* colors.

This is a more advanced formula that accounts for perceptual non-uniformities in the Lab* space.

§Arguments
  • other – The second Lab color to compare against.
§Returns
  • Ok(de) – The ΔE value if both colors share the same observer and illuminant.
§Errors
  • CmtError::RequireSameObserver if the two colors use different standard observers.
  • CmtError::RequiresSameIlluminant if they were computed under different illuminants.
§Notes

CIEDE2000 is generally preferred over the plain Euclidean ΔE*ab for color difference calculations, as it better matches human perception of color differences.

§Example
use colorimetry::{observer::Observer::Cie1931, lab::CieLab, Error};

// Sharma et al. (2005) test case 25
let xyz_d65 = Cie1931.xyz_d65();
let lab1 = CieLab::new([60.2574, -34.0099, 36.2677], xyz_d65);
let lab2 = CieLab::new([60.4626, -34.1751, 39.4387], xyz_d65);
let de = lab1.ciede2000(&lab2).unwrap();
approx::assert_abs_diff_eq!(de, 1.2644, epsilon = 1E-4);
Source

pub fn to_array(&self) -> [f64; 3]

Returns the CIE Lab* color values as an array of three f64 values.

§Returns

An array containing the L*, a*, and b* values of the color.

Source

pub fn is_valid(&self) -> bool

Validates the CIE Lab* color values.

§Returns

true if the L*, a*, and b* values are within valid ranges and the round-trip conversion to and from XYZ is consistent; false otherwise.

Source

pub fn is_black(&self, epsilon: f64) -> bool

Trait Implementations§

Source§

impl AbsDiffEq for CieLab

Source§

type Epsilon = f64

Used for specifying relative comparisons.
Source§

fn default_epsilon() -> Self::Epsilon

The default tolerance to use when testing values that are close together. Read more
Source§

fn abs_diff_eq(&self, other: &Self, epsilon: Self::Epsilon) -> bool

A test for equality that uses the absolute difference to compute the approximate equality of two numbers.
Source§

fn abs_diff_ne(&self, other: &Rhs, epsilon: Self::Epsilon) -> bool

The inverse of AbsDiffEq::abs_diff_eq.
Source§

impl AsRef<[f64; 3]> for CieLab

Source§

fn as_ref(&self) -> &[f64; 3]

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl Clone for CieLab

Source§

fn clone(&self) -> CieLab

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Copy for CieLab

Source§

impl Debug for CieLab

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl PartialEq for CieLab

Source§

fn eq(&self, other: &CieLab) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl StructuralPartialEq for CieLab

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> Scalar for T
where T: 'static + Clone + PartialEq + Debug,

Source§

impl<SS, SP> SupersetOf<SS> for SP
where SS: SubsetOf<SP>,

Source§

fn to_subset(&self) -> Option<SS>

The inverse inclusion map: attempts to construct self from the equivalent element of its superset. Read more
Source§

fn is_in_subset(&self) -> bool

Checks if self is actually part of its subset T (and can be converted to it).
Source§

fn to_subset_unchecked(&self) -> SS

Use with care! Same as self.to_subset but without any property checks. Always succeeds.
Source§

fn from_subset(element: &SS) -> SP

The inclusion map: converts self to the equivalent element of its superset.
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<G1, G2> Within<G2> for G1
where G2: Contains<G1>,

Source§

fn is_within(&self, b: &G2) -> bool