def tcs_colorimetry_data(spd_t, spd_r, spds_tcs, cmfs, chromatic_adaptation=False): """ Returns the *test colour samples* colorimetry data. Parameters ---------- spd_t : SpectralPowerDistribution Test spectral power distribution. spd_r : SpectralPowerDistribution Reference spectral power distribution. spds_tcs : dict *Test colour samples* spectral power distributions. cmfs : XYZ_ColourMatchingFunctions Standard observer colour matching functions. chromatic_adaptation : bool, optional Perform chromatic adaptation. Returns ------- list *Test colour samples* colorimetry data. """ XYZ_t = spectral_to_XYZ(spd_t, cmfs) uv_t = np.ravel(UCS_to_uv(XYZ_to_UCS(XYZ_t))) u_t, v_t = uv_t[0], uv_t[1] XYZ_r = spectral_to_XYZ(spd_r, cmfs) uv_r = np.ravel(UCS_to_uv(XYZ_to_UCS(XYZ_r))) u_r, v_r = uv_r[0], uv_r[1] tcs_data = [] for _key, value in sorted(TCS_INDEXES_TO_NAMES.items()): spd_tcs = spds_tcs.get(value) XYZ_tcs = spectral_to_XYZ(spd_tcs, cmfs, spd_t) xyY_tcs = np.ravel(XYZ_to_xyY(XYZ_tcs)) uv_tcs = np.ravel(UCS_to_uv(XYZ_to_UCS(XYZ_tcs))) u_tcs, v_tcs = uv_tcs[0], uv_tcs[1] if chromatic_adaptation: c = lambda x, y: (4 - x - 10 * y) / y d = lambda x, y: (1.708 * y + 0.404 - 1.481 * x) / y c_t, d_t = c(u_t, v_t), d(u_t, v_t) c_r, d_r = (c(u_r, v_r), d(u_r, v_r)) tcs_c, tcs_d = c(u_tcs, v_tcs), d(u_tcs, v_tcs) u_tcs = ((10.872 + 0.404 * c_r / c_t * tcs_c - 4 * d_r / d_t * tcs_d) / (16.518 + 1.481 * c_r / c_t * tcs_c - d_r / d_t * tcs_d)) v_tcs = (5.52 / (16.518 + 1.481 * c_r / c_t * tcs_c - d_r / d_t * tcs_d)) W_tcs = 25 * xyY_tcs[-1] ** (1 / 3) - 17 U_tcs = 13 * W_tcs * (u_tcs - u_r) V_tcs = 13 * W_tcs * (v_tcs - v_r) tcs_data.append( TCS_ColorimetryData(spd_tcs.name, XYZ_tcs, uv_tcs, np.array([U_tcs, V_tcs, W_tcs]))) return tcs_data
def _tcs_colorimetry_data(test_spd, reference_spd, tsc_spds, cmfs, chromatic_adaptation=False): """ Returns the *test colour samples* colorimetry data. Parameters ---------- test_spd : SpectralPowerDistribution Test spectral power distribution. reference_spd : SpectralPowerDistribution Reference spectral power distribution. tsc_spds : dict Test colour samples. cmfs : XYZ_ColourMatchingFunctions Standard observer colour matching functions. chromatic_adaptation : bool, optional Perform chromatic adaptation. Returns ------- list *Test colour samples* colorimetry data. """ test_XYZ = spectral_to_XYZ(test_spd, cmfs) test_uv = np.ravel(UCS_to_uv(XYZ_to_UCS(test_XYZ))) test_u, test_v = test_uv[0], test_uv[1] reference_XYZ = spectral_to_XYZ(reference_spd, cmfs) reference_uv = np.ravel(UCS_to_uv(XYZ_to_UCS(reference_XYZ))) reference_u, reference_v = reference_uv[0], reference_uv[1] tcs_data = [] for key, value in sorted(TCS_INDEXES_TO_NAMES.items()): tcs_spd = tsc_spds.get(value) tcs_XYZ = spectral_to_XYZ(tcs_spd, cmfs, test_spd) tcs_xyY = np.ravel(XYZ_to_xyY(tcs_XYZ)) tcs_uv = np.ravel(UCS_to_uv(XYZ_to_UCS(tcs_XYZ))) tcs_u, tcs_v = tcs_uv[0], tcs_uv[1] if chromatic_adaptation: c = lambda x, y: (4 - x - 10 * y) / y d = lambda x, y: (1.708 * y + 0.404 - 1.481 * x) / y test_c, test_d = c(test_u, test_v), d(test_u, test_v) reference_c, reference_d = (c(reference_u, reference_v), d(reference_u, reference_v)) tcs_c, tcs_d = c(tcs_u, tcs_v), d(tcs_u, tcs_v) tcs_u = ((10.872 + 0.404 * reference_c / test_c * tcs_c - 4 * reference_d / test_d * tcs_d) / (16.518 + 1.481 * reference_c / test_c * tcs_c - reference_d / test_d * tcs_d)) tcs_v = (5.52 / (16.518 + 1.481 * reference_c / test_c * tcs_c - reference_d / test_d * tcs_d)) tcs_W = 25 * tcs_xyY[-1] ** (1 / 3) - 17 tcs_U = 13 * tcs_W * (tcs_u - reference_u) tcs_V = 13 * tcs_W * (tcs_v - reference_v) tcs_data.append( TSC_COLORIMETRY_DATA_NXYZUVUVW(tcs_spd.name, tcs_XYZ, tcs_uv, np.array([tcs_U, tcs_V, tcs_W]))) return tcs_data
def tcs_colorimetry_data(spd_t, spd_r, spds_tcs, cmfs, chromatic_adaptation=False): """ Returns the *test colour samples* colorimetry data. Parameters ---------- spd_t : SpectralPowerDistribution Test spectral power distribution. spd_r : SpectralPowerDistribution Reference spectral power distribution. spds_tcs : dict *Test colour samples* spectral power distributions. cmfs : XYZ_ColourMatchingFunctions Standard observer colour matching functions. chromatic_adaptation : bool, optional Perform chromatic adaptation. Returns ------- list *Test colour samples* colorimetry data. """ XYZ_t = spectral_to_XYZ(spd_t, cmfs) uv_t = UCS_to_uv(XYZ_to_UCS(XYZ_t)) u_t, v_t = uv_t[0], uv_t[1] XYZ_r = spectral_to_XYZ(spd_r, cmfs) uv_r = UCS_to_uv(XYZ_to_UCS(XYZ_r)) u_r, v_r = uv_r[0], uv_r[1] tcs_data = [] for _key, value in sorted(TCS_INDEXES_TO_NAMES.items()): spd_tcs = spds_tcs[value] XYZ_tcs = spectral_to_XYZ(spd_tcs, cmfs, spd_t) xyY_tcs = XYZ_to_xyY(XYZ_tcs) uv_tcs = UCS_to_uv(XYZ_to_UCS(XYZ_tcs)) u_tcs, v_tcs = uv_tcs[0], uv_tcs[1] if chromatic_adaptation: def c(x, y): """ Computes the :math:`c` term. """ return (4 - x - 10 * y) / y def d(x, y): """ Computes the :math:`d` term. """ return (1.708 * y + 0.404 - 1.481 * x) / y c_t, d_t = c(u_t, v_t), d(u_t, v_t) c_r, d_r = c(u_r, v_r), d(u_r, v_r) tcs_c, tcs_d = c(u_tcs, v_tcs), d(u_tcs, v_tcs) u_tcs = (( 10.872 + 0.404 * c_r / c_t * tcs_c - 4 * d_r / d_t * tcs_d) / (16.518 + 1.481 * c_r / c_t * tcs_c - d_r / d_t * tcs_d)) v_tcs = (5.52 / (16.518 + 1.481 * c_r / c_t * tcs_c - d_r / d_t * tcs_d)) W_tcs = 25 * xyY_tcs[-1] ** (1 / 3) - 17 U_tcs = 13 * W_tcs * (u_tcs - u_r) V_tcs = 13 * W_tcs * (v_tcs - v_r) tcs_data.append( TCS_ColorimetryData(spd_tcs.name, XYZ_tcs, uv_tcs, np.array([U_tcs, V_tcs, W_tcs]))) return tcs_data
def _tcs_colorimetry_data(test_spd, reference_spd, tsc_spds, cmfs, chromatic_adaptation=False): """ Returns the *test colour samples* colorimetry data. Parameters ---------- test_spd : SpectralPowerDistribution Test spectral power distribution. reference_spd : SpectralPowerDistribution Reference spectral power distribution. tsc_spds : dict Test colour samples. cmfs : XYZ_ColourMatchingFunctions Standard observer colour matching functions. chromatic_adaptation : bool, optional Perform chromatic adaptation. Returns ------- list *Test colour samples* colorimetry data. """ test_XYZ = spectral_to_XYZ(test_spd, cmfs) test_uv = np.ravel(UCS_to_uv(XYZ_to_UCS(test_XYZ))) test_u, test_v = test_uv[0], test_uv[1] reference_XYZ = spectral_to_XYZ(reference_spd, cmfs) reference_uv = np.ravel(UCS_to_uv(XYZ_to_UCS(reference_XYZ))) reference_u, reference_v = reference_uv[0], reference_uv[1] tcs_data = [] for key, value in sorted(TCS_INDEXES_TO_NAMES.items()): tcs_spd = tsc_spds.get(value) tcs_XYZ = spectral_to_XYZ(tcs_spd, cmfs, test_spd) tcs_xyY = np.ravel(XYZ_to_xyY(tcs_XYZ)) tcs_uv = np.ravel(UCS_to_uv(XYZ_to_UCS(tcs_XYZ))) tcs_u, tcs_v = tcs_uv[0], tcs_uv[1] if chromatic_adaptation: c = lambda x, y: (4 - x - 10 * y) / y d = lambda x, y: (1.708 * y + 0.404 - 1.481 * x) / y test_c, test_d = c(test_u, test_v), d(test_u, test_v) reference_c, reference_d = (c(reference_u, reference_v), d(reference_u, reference_v)) tcs_c, tcs_d = c(tcs_u, tcs_v), d(tcs_u, tcs_v) tcs_u = ((10.872 + 0.404 * reference_c / test_c * tcs_c - 4 * reference_d / test_d * tcs_d) / (16.518 + 1.481 * reference_c / test_c * tcs_c - reference_d / test_d * tcs_d)) tcs_v = (5.52 / (16.518 + 1.481 * reference_c / test_c * tcs_c - reference_d / test_d * tcs_d)) tcs_W = 25 * tcs_xyY[-1]**(1 / 3) - 17 tcs_U = 13 * tcs_W * (tcs_u - reference_u) tcs_V = 13 * tcs_W * (tcs_v - reference_v) tcs_data.append( TSC_COLORIMETRY_DATA_NXYZUVUVW(tcs_spd.name, tcs_XYZ, tcs_uv, np.array([tcs_U, tcs_V, tcs_W]))) return tcs_data