Skip to main content

Module chromatic_adaptation

Module chromatic_adaptation 

Source
Expand description

Convert colors from one reference white point to another

Chromatic adaptation is the ability to adjust the appearance of colors to changes in illumination. This happens naturally in our body’s visual system, and can be emulated with a “chromatic adaptation transform” (CAT).

This library implements a one-step adaptation transform, known as the von Kries method. It’s provided as AdaptFromUnclamped or AdaptIntoUnclamped for convenience, or adaptation_matrix for control and reusability. All of them can be customized with different LMS matrices.

The provided LMS matrices are:

  • Bradford - A “spectrally sharpened” matrix, which may improve chromatic adaptation. This is the default for AdaptFromUnclamped and AdaptIntoUnclamped.
  • VonKries - Produces cone-describing LMS values, as opposed to many other matrices, but may perform worse than other matrices.
  • UnitMatrix - Included for completeness, but generally considered a bad option. Also called “XYZ scaling” or “wrong von Kries”.
use palette::{
    Xyz, white_point::{A, C},
    chromatic_adaptation::AdaptIntoUnclamped,
};
use approx::assert_relative_eq;

let input = Xyz::<A, f32>::new(0.315756, 0.162732, 0.015905);

//Will convert Xyz<A, f32> to Xyz<C, f32> using Bradford chromatic adaptation;
let output: Xyz<C, f32> = input.adapt_into_unclamped();

let expected = Xyz::new(0.257963, 0.139776, 0.058825);
assert_relative_eq!(output, expected, epsilon = 0.0001);

Structs§

ConeResponseMatricesDeprecated
Holds the matrix coefficients for the chromatic adaptation methods

Enums§

MethodDeprecated
Chromatic adaptation methods implemented in the library

Traits§

AdaptFromDeprecated
Trait to convert color from one reference white point to another
AdaptFromUnclamped
A trait for unchecked conversion of one color from another via chromatic adaptation.
AdaptIntoDeprecated
Trait to convert color with one reference white point into another
AdaptIntoUnclamped
A trait for unchecked conversion of one color into another via chromatic adaptation.
TransformMatrixDeprecated
Generates a conversion matrix to convert the Xyz tristimulus values from one illuminant to another (source_wp to destination_wp)

Functions§

adaptation_matrix
Construct a one-step chromatic adaptation matrix.
diagonal_matrix
Construct a diagonal matrix for full adaptation of Lms colors.