Hypothetical: Convert between XYZ colorspaces (given 2 data sets and 2 illuminants.)
- User
Hypothetical: Convert between XYZ colorspaces (given 2 data sets and 2 illuminants.)
- Assistant
Hypothetical: Convert between XYZ colorspaces (given 2 data sets and 2 illuminants.)
Sure! To provide a clear explanation, I'll outline the typical steps involved in converting between two XYZ color spaces that are defined with respect to different illuminants (reference whites). You mentioned "given 2 data sets and 2 illuminants," so I will assume you have:
The goal: Convert colors from the XYZ space of Illuminant 1 to the XYZ space of Illuminant 2 (or vice versa).
Given:
You must have the XYZ coordinates of the white points for both illuminants. For example:
| Illuminant | X | Y | Z |
|---|---|---|---|
| D65 | 0.95047 | 1.00000 | 1.08883 |
| D50 | 0.96422 | 1.00000 | 0.82521 |
Common CATs:
Bradford is the typical choice due to its good performance perceptually.
The Bradford matrix ( M ) and its inverse ( M^{-1} ) are predefined:
[ M = \begin{bmatrix} 0.8951 & 0.2664 & -0.1614 \ -0.7502 & 1.7135 & 0.0367 \ 0.0389 & -0.0685 & 1.0296 \end{bmatrix} ] [ M^{-1} = \begin{bmatrix} 0.9869929 & -0.1470543 & 0.1599627 \ 0.4323053 & 0.5183603 & 0.0492912 \ -0.0085287 & 0.0400428 & 0.9684867 \end{bmatrix} ]
Using matrix ( M ):
[ \mathbf{LMS}_1 = M \times \mathbf{W}_1 ] [ \mathbf{LMS}_2 = M \times \mathbf{W}_2 ]
[ D = \begin{bmatrix} \frac{L_2}{L_1} & 0 & 0 \ 0 & \frac{M_2}{M_1} & 0 \ 0 & 0 & \frac{S_2}{S_1} \end{bmatrix} ]
For any input XYZ vector ( \mathbf{Xyz}_1 ):
[ \mathbf{LMS} = M \times \mathbf{Xyz}_1 ]
[ \mathbf{LMS}' = D \times \mathbf{LMS} ]
[ \mathbf{Xyz}_2 = M^{-1} \times \mathbf{LMS}' ]
[ \mathbf{Xyz}_2 = M^{-1} \times D \times M \times \mathbf{Xyz}_1 ]
Convert from Illuminant D65 to D50:
Apply the above steps to get ( \mathbf{Xyz}_{D50} ).
import numpy as np
def adapt_xyz(XYZ, source_white, target_white):
# Bradford transform matrices
M = np.array([[0.8951, 0.2664, -0.1614],
[-0.7502, 1.7135, 0.0367],
[0.0389, -0.0685, 1.0296]])
M_inv = np.linalg.inv(M)
# Convert source and target whites to LMS
LMS_source = np.dot(M, source_white)
LMS_target = np.dot(M, target_white)
# Diagonal adaptation matrix
D = np.diag(LMS_target / LMS_source)
# Convert input color to LMS
LMS = np.dot(M, XYZ)
# Adapt LMS values
LMS_adapted = np.dot(D, LMS)
# Convert back to XYZ
XYZ_adapted = np.dot(M_inv, LMS_adapted)
return XYZ_adapted
# Example usage:
XYZ_D65 = np.array([0.3, 0.4, 0.2])
D65_white = np.array([0.95047, 1.00000, 1.08883])
D50_white = np.array([0.96422, 1.00000, 0.82521])
XYZ_D50 = adapt_xyz(XYZ_D65, D65_white, D50_white)
print("Adapted XYZ (D65 -> D50):", XYZ_D50)
If you provide your two data sets and their corresponding illuminants, I can perform (or guide you through) the actual numerical conversion.
Because XYZ is relative to a reference white, the same numeric values will look different under different illuminants. Chromatic adaptation ensures that the color appearance is preserved after conversion.
If you want me to convert data you provide or have additional questions, just ask!
Not yet included in a published release.