jaxlayerlumos.colors.transform
Color space transformation functions for spectral data.
This module provides functions for converting spectral data to various color spaces including CIE XYZ, xyY chromaticity coordinates, sRGB, and CIE Lab. It implements standard color space transformations used in color science and display applications.
- jaxlayerlumos.colors.transform.XYZ_to_Lab(XYZ, str_illuminant='d65')
Convert CIE XYZ to CIE Lab color space.
This function converts CIE XYZ tristimulus values to CIE Lab color space, which is perceptually uniform and widely used in color science.
- Parameters:
XYZ (jnp.ndarray) – CIE XYZ tristimulus values [X, Y, Z].
str_illuminant (str, optional) – Reference illuminant for white point. Currently only supports “d65”. Defaults to “d65”.
- Returns:
- CIE Lab values [L, a, b] where L is lightness and a, b are
chromaticity coordinates.
- Return type:
jnp.ndarray
- Raises:
ValueError – If the illuminant is not supported.
Note
L represents lightness (0 = black, 1 = white)
a represents red-green chromaticity (positive = red, negative = green)
b represents yellow-blue chromaticity (positive = yellow, negative = blue)
The transformation uses the D65 white point reference values
- jaxlayerlumos.colors.transform.XYZ_to_sRGB(XYZ, use_clipping=False)
Convert CIE XYZ to sRGB color space.
This function converts CIE XYZ tristimulus values to sRGB color space using the standard transformation matrix and gamma correction.
- Parameters:
XYZ (jnp.ndarray) – CIE XYZ tristimulus values [X, Y, Z].
use_clipping (bool, optional) – Whether to clip RGB values to [0, 1]. Defaults to False.
- Returns:
sRGB values [R, G, B] in the range [0, 1].
- Return type:
jnp.ndarray
Note
The transformation includes gamma correction (2.4 power law) and the standard sRGB transformation matrix.
- jaxlayerlumos.colors.transform.XYZ_to_xyY(XYZ)
Convert CIE XYZ to xyY chromaticity coordinates.
This function converts CIE XYZ tristimulus values to xyY chromaticity coordinates, where x and y represent the chromaticity and Y represents the luminance.
- Parameters:
XYZ (jnp.ndarray) – CIE XYZ tristimulus values [X, Y, Z].
- Returns:
xyY chromaticity coordinates [x, y, Y].
- Return type:
jnp.ndarray
Note
The chromaticity coordinates x and y are normalized so that x + y + z = 1, where z = 1 - x - y.
- jaxlayerlumos.colors.transform.spectrum_to_XYZ(wavelengths, values, str_color_space='cie1931', str_illuminant='d65')
Convert spectral data to CIE XYZ tristimulus values.
This function calculates the CIE XYZ tristimulus values from spectral reflectance or transmittance data using color matching functions and an illuminant.
- Parameters:
wavelengths (jnp.ndarray) – Wavelengths in meters.
values (jnp.ndarray) – Spectral values (reflectance, transmittance, etc.).
str_color_space (str, optional) – Color space for color matching functions. Defaults to “cie1931”.
str_illuminant (str, optional) – Illuminant name. Defaults to “d65”.
- Returns:
CIE XYZ tristimulus values [X, Y, Z].
- Return type:
jnp.ndarray
Note
The calculation uses trapezoidal integration over the spectral range. Y represents luminance and is normalized to the illuminant.