"""
Chromatic Adaptation by Reflectance Reconstruction
================================================================
Predicts how tristimulus values will change when moving from
one illuminant to another, given the white points of the two
illuminants.
Version 2020_01_24 Scott Allen Burns
"""
from method_2 import method_2
def adaptation(d, cmfs_s, cmfs_d, XYZ_s):
"""
Predicts how tristimulus values will change when moving from
one illuminant to another, given the white points of the two
illuminants. Optionally, a degree of adaptation (0-1) can be
specified (in the adaptation_prep function).
Parameters
----------
d: nxn array of finite differencing constants, obtained
from function adaptation_prep_XYZ or adaptation_prep_xy.
(n is the number of wavelength bins (rows) used in the
CMFs.)
cmfs_s: nx3 array of source-illuminant-referenced CMFs,
obtained from function adaptation_prep_XYZ or
adaptation_prep_xy.
cmfs_d: nx3 array of destination-illuminant-referenced CMFs,
obtained from function adaptation_prep_XYZ or
adaptation_prep_xy.
XYZ_s: a three element vector of source-illuminant-referenced
tristimulus values in the 0 <= Y <= 1 convention range.
Returns
-------
XYZ_d: a three element vector of destination-illuminant-referenced
tristimulus values in the 0 <= Y <= 1 convention range,
estimating what the effect of the illuminant would be.
Notes
-----
This chromatic adaptation transform (CAT) is based on smoothest
reflectance reconstruction (References [1] and [2]) and is
developed and compared to existing CATs (Bradford, CAT02, CAT16)
in Reference [3].
References
----------
[1] Burns SA. Numerical methods for smoothest reflectance
reconstruction. Color Research & Application, Vol 45,
No 1, 2020, pp 8-21.
[2] Generating Reflectance Curves from sRGB Triplets, 2015
http://scottburns.us/reflectance-curves-from-srgb/#LLSS
[3] Burns SA. Chromatic adaptation transform by spectral
reconstruction. Color Research & Application, Vol 44,
No 5, 2019, pp 682-693.
Acknowledgements
----------------
Thanks to Adam J. Burns and Mark (kram1032) for assistance
with translating from MATLAB to Python.
"""
rho = method_2(d, cmfs_s, XYZ_s)
XYZ_d = cmfs_d.T.dot(rho)
XYZ_d = XYZ_d * XYZ_s[1] / XYZ_d[1]
return XYZ_d