pub struct CieLab { /* private fields */ }Implementations§
Source§impl CieLab
impl CieLab
pub fn a(&self) -> f64
pub fn b(&self) -> f64
pub fn l(&self) -> f64
Sourcepub fn rxyz(&self) -> RelXYZ
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.
Sourcepub fn xyz(&self) -> XYZ
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.
Sourcepub fn white_point(&self) -> XYZ
pub fn white_point(&self) -> XYZ
Returns the reference white tristimulus value for this CIE Lab* color.
Sourcepub fn set_white_luminance(self, luminance: f64) -> CieLab
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.
Sourcepub fn ciede(&self, other: &Self) -> Result<f64, Error>
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::RequireSameObserverif the two colors use different standard observers.CmtError::IlluminantMismatchif 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.57Sourcepub fn ciede2000(&self, other: &Self) -> Result<f64, Error>
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::RequireSameObserverif the two colors use different standard observers.CmtError::RequiresSameIlluminantif 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);Sourcepub fn to_array(&self) -> [f64; 3]
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.
Sourcepub fn is_valid(&self) -> bool
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.
pub fn is_black(&self, epsilon: f64) -> bool
Trait Implementations§
Source§impl AbsDiffEq for CieLab
impl AbsDiffEq for CieLab
Source§fn default_epsilon() -> Self::Epsilon
fn default_epsilon() -> Self::Epsilon
Source§fn abs_diff_eq(&self, other: &Self, epsilon: Self::Epsilon) -> bool
fn abs_diff_eq(&self, other: &Self, epsilon: Self::Epsilon) -> bool
Source§fn abs_diff_ne(&self, other: &Rhs, epsilon: Self::Epsilon) -> bool
fn abs_diff_ne(&self, other: &Rhs, epsilon: Self::Epsilon) -> bool
AbsDiffEq::abs_diff_eq.impl Copy for CieLab
impl StructuralPartialEq for CieLab
Auto Trait Implementations§
impl Freeze for CieLab
impl RefUnwindSafe for CieLab
impl Send for CieLab
impl Sync for CieLab
impl Unpin for CieLab
impl UnsafeUnpin for CieLab
impl UnwindSafe for CieLab
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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 moreSource§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.