def test_n_dimensional_XYZ_to_xyY(self): """ Tests :func:`colour.models.cie_xyy.XYZ_to_xyY` definition n-dimensions support. """ XYZ = np.array([0.07049534, 0.10080000, 0.09558313]) illuminant = np.array([0.34570, 0.35850]) xyY = np.array([0.26414772, 0.37770001, 0.10080000]) np.testing.assert_almost_equal(XYZ_to_xyY(XYZ, illuminant), xyY, decimal=7) XYZ = np.tile(XYZ, (6, 1)) xyY = np.tile(xyY, (6, 1)) np.testing.assert_almost_equal(XYZ_to_xyY(XYZ, illuminant), xyY, decimal=7) illuminant = np.tile(illuminant, (6, 1)) np.testing.assert_almost_equal(XYZ_to_xyY(XYZ, illuminant), xyY, decimal=7) XYZ = np.reshape(XYZ, (2, 3, 3)) illuminant = np.reshape(illuminant, (2, 3, 2)) xyY = np.reshape(xyY, (2, 3, 3)) np.testing.assert_almost_equal(XYZ_to_xyY(XYZ, illuminant), xyY, decimal=7)
def test_n_dimensional_XYZ_to_xyY(self): """ Tests :func:`colour.models.cie_xyy.XYZ_to_xyY` definition n-dimensions support. """ XYZ = np.array([0.20654008, 0.12197225, 0.05136952]) illuminant = np.array([0.31270, 0.32900]) xyY = np.array([0.54369557, 0.32107944, 0.12197225]) np.testing.assert_almost_equal( XYZ_to_xyY(XYZ, illuminant), xyY, decimal=7) XYZ = np.tile(XYZ, (6, 1)) xyY = np.tile(xyY, (6, 1)) np.testing.assert_almost_equal( XYZ_to_xyY(XYZ, illuminant), xyY, decimal=7) illuminant = np.tile(illuminant, (6, 1)) np.testing.assert_almost_equal( XYZ_to_xyY(XYZ, illuminant), xyY, decimal=7) XYZ = np.reshape(XYZ, (2, 3, 3)) illuminant = np.reshape(illuminant, (2, 3, 2)) xyY = np.reshape(xyY, (2, 3, 3)) np.testing.assert_almost_equal( XYZ_to_xyY(XYZ, illuminant), xyY, decimal=7)
def chromatically_adapted_primaries( primaries: ArrayLike, whitepoint_t: ArrayLike, whitepoint_r: ArrayLike, chromatic_adaptation_transform: Union[Literal["Bianco 2010", "Bianco PC 2010", "Bradford", "CAT02 Brill 2008", "CAT02", "CAT16", "CMCCAT2000", "CMCCAT97", "Fairchild", "Sharp", "Von Kries", "XYZ Scaling", ], str, ] = "CAT02", ) -> NDArray: """ Chromatically adapt given *primaries* :math:`xy` chromaticity coordinates from test ``whitepoint_t`` to reference ``whitepoint_r``. Parameters ---------- primaries Primaries :math:`xy` chromaticity coordinates. whitepoint_t Test illuminant / whitepoint :math:`xy` chromaticity coordinates. whitepoint_r Reference illuminant / whitepoint :math:`xy` chromaticity coordinates. chromatic_adaptation_transform *Chromatic adaptation* transform. Returns ------- :class:`numpy.ndarray` Chromatically adapted primaries :math:`xy` chromaticity coordinates. Examples -------- >>> p = np.array([0.64, 0.33, 0.30, 0.60, 0.15, 0.06]) >>> w_t = np.array([0.31270, 0.32900]) >>> w_r = np.array([0.34570, 0.35850]) >>> chromatic_adaptation_transform = 'Bradford' >>> chromatically_adapted_primaries(p, w_t, w_r, ... chromatic_adaptation_transform) ... # doctest: +ELLIPSIS array([[ 0.6484414..., 0.3308533...], [ 0.3211951..., 0.5978443...], [ 0.1558932..., 0.0660492...]]) """ primaries = np.reshape(primaries, (3, 2)) XYZ_a = chromatic_adaptation_VonKries( xy_to_XYZ(primaries), xy_to_XYZ(whitepoint_t), xy_to_XYZ(whitepoint_r), chromatic_adaptation_transform, ) P_a = XYZ_to_xyY(XYZ_a)[..., 0:2] return P_a
def test_nan_XYZ_to_xyY(self): """Test :func:`colour.models.cie_xyy.XYZ_to_xyY` definition nan support.""" cases = [-1.0, 0.0, 1.0, -np.inf, np.inf, np.nan] cases = set(permutations(cases * 3, r=3)) for case in cases: XYZ = np.array(case) illuminant = np.array(case[0:2]) XYZ_to_xyY(XYZ, illuminant)
def XYZ_to_UVW( XYZ, illuminant=ILLUMINANTS['CIE 1931 2 Degree Standard Observer']['D50']): """ Converts from *CIE XYZ* tristimulus values to *CIE 1964 U\*V\*W\** colourspace. Parameters ---------- XYZ : array_like *CIE XYZ* tristimulus values. illuminant : array_like, optional Reference *illuminant* *xy* chromaticity coordinates or *CIE xyY* colourspace array. Returns ------- ndarray *CIE 1964 U\*V\*W\** colourspace array. Warning ------- The input domain and output range of that definition are non standard! Notes ----- - Input *CIE XYZ* tristimulus values are in domain [0, 100]. - Input *illuminant* *xy* chromaticity coordinates or *CIE xyY* colourspace array are in domain [0, :math:`\infty`]. - Output *CIE 1964 U\*V\*W\** colourspace array is in range [0, 100]. References ---------- - :cite:`Wikipediacj` Examples -------- >>> import numpy as np >>> XYZ = np.array([0.07049534, 0.10080000, 0.09558313]) * 100 >>> XYZ_to_UVW(XYZ) # doctest: +ELLIPSIS array([-28.0579733..., -0.8819449..., 37.0041149...]) """ xyY = XYZ_to_xyY(XYZ, xyY_to_xy(illuminant)) _x, _y, Y = tsplit(xyY) u, v = tsplit(UCS_to_uv(XYZ_to_UCS(XYZ))) u_0, v_0 = tsplit(UCS_to_uv(XYZ_to_UCS(xyY_to_XYZ(xy_to_xyY(illuminant))))) W = 25 * Y**(1 / 3) - 17 U = 13 * W * (u - u_0) V = 13 * W * (v - v_0) UVW = tstack((U, V, W)) return UVW
def chromatically_adapted_primaries(primaries, whitepoint_t, whitepoint_r, chromatic_adaptation_transform='CAT02'): """ Chromatically adapts given *primaries* :math:`xy` chromaticity coordinates from test `whitepoint_t` to reference `whitepoint_r`. Parameters ---------- primaries : array_like, (3, 2) Primaries :math:`xy` chromaticity coordinates. whitepoint_t : array_like Test illuminant / whitepoint :math:`xy` chromaticity coordinates. whitepoint_r : array_like Reference illuminant / whitepoint :math:`xy` chromaticity coordinates. chromatic_adaptation_transform : unicode, optional **{'CAT02', 'XYZ Scaling', 'Von Kries', 'Bradford', 'Sharp', 'Fairchild, 'CMCCAT97', 'CMCCAT2000', 'CAT02_BRILL_CAT', 'Bianco', 'Bianco PC'}**, *Chromatic adaptation* transform. Returns ------- ndarray Chromatically adapted primaries :math:`xy` chromaticity coordinates. Examples -------- >>> p = np.array([0.64, 0.33, 0.30, 0.60, 0.15, 0.06]) >>> whitepoint_t = np.array([0.31271, 0.32902]) >>> whitepoint_r = np.array([0.34567, 0.35850]) >>> chromatic_adaptation_transform = 'Bradford' >>> chromatically_adapted_primaries( # doctest: +ELLIPSIS ... p, ... whitepoint_t, ... whitepoint_r, ... chromatic_adaptation_transform) array([[ 0.6484318..., 0.3308548...], [ 0.3211603..., 0.5978620...], [ 0.1558860..., 0.0660431...]]) """ primaries = np.reshape(primaries, (3, 2)) XYZ_a = chromatic_adaptation_VonKries( xy_to_XYZ(primaries), xy_to_XYZ(whitepoint_t), xy_to_XYZ(whitepoint_r), chromatic_adaptation_transform) P_a = XYZ_to_xyY(XYZ_a)[..., 0:2] return P_a
def test_domain_range_scale_XYZ_to_xyY(self): """ Tests :func:`colour.models.cie_xyy.XYZ_to_xyY` definition domain and range scale support. """ XYZ = np.array([0.20654008, 0.12197225, 0.05136952]) xyY = XYZ_to_xyY(XYZ) XYZ = np.tile(XYZ, (6, 1)).reshape(2, 3, 3) xyY = np.tile(xyY, (6, 1)).reshape(2, 3, 3) d_r = (('reference', 1, 1), (1, 1, 1), ( 100, 100, np.array([1, 1, 100]), )) for scale, factor_a, factor_b in d_r: with domain_range_scale(scale): np.testing.assert_almost_equal( XYZ_to_xyY(XYZ * factor_a), xyY * factor_b, decimal=7)
def test_XYZ_to_xyY(self): """Test :func:`colour.models.cie_xyy.XYZ_to_xyY` definition.""" np.testing.assert_almost_equal( XYZ_to_xyY(np.array([0.20654008, 0.12197225, 0.05136952])), np.array([0.54369557, 0.32107944, 0.12197225]), decimal=7, ) np.testing.assert_almost_equal( XYZ_to_xyY(np.array([0.14222010, 0.23042768, 0.10495772])), np.array([0.29777735, 0.48246446, 0.23042768]), decimal=7, ) np.testing.assert_almost_equal( XYZ_to_xyY(np.array([0.07818780, 0.06157201, 0.28099326])), np.array([0.18582823, 0.14633764, 0.06157201]), decimal=7, ) np.testing.assert_almost_equal( XYZ_to_xyY(np.array([0.00000000, 0.00000000, 1.00000000])), np.array([0.00000000, 0.00000000, 0.00000000]), decimal=7, ) np.testing.assert_almost_equal( XYZ_to_xyY( np.array([ [0.20654008, 0.12197225, 0.05136952], [0.00000000, 0.00000000, 0.00000000], [0.00000000, 1.00000000, 0.00000000], ])), np.array([ [0.54369557, 0.32107944, 0.12197225], [0.31270000, 0.32900000, 0.00000000], [0.00000000, 1.00000000, 1.00000000], ]), decimal=7, )
def chromatically_adapted_primaries(primaries, whitepoint_t, whitepoint_r, chromatic_adaptation_transform='CAT02'): """ Chromatically adapts given *primaries* :math:`xy` chromaticity coordinates from test ``whitepoint_t`` to reference ``whitepoint_r``. Parameters ---------- primaries : array_like, (3, 2) Primaries :math:`xy` chromaticity coordinates. whitepoint_t : array_like Test illuminant / whitepoint :math:`xy` chromaticity coordinates. whitepoint_r : array_like Reference illuminant / whitepoint :math:`xy` chromaticity coordinates. chromatic_adaptation_transform : unicode, optional **{'CAT02', 'XYZ Scaling', 'Von Kries', 'Bradford', 'Sharp', 'Fairchild', 'CMCCAT97', 'CMCCAT2000', 'CAT02 Brill 2008', 'Bianco 2010', 'Bianco PC 2010'}**, *Chromatic adaptation* transform. Returns ------- ndarray Chromatically adapted primaries :math:`xy` chromaticity coordinates. Examples -------- >>> p = np.array([0.64, 0.33, 0.30, 0.60, 0.15, 0.06]) >>> w_t = np.array([0.31270, 0.32900]) >>> w_r = np.array([0.34570, 0.35850]) >>> chromatic_adaptation_transform = 'Bradford' >>> chromatically_adapted_primaries(p, w_t, w_r, ... chromatic_adaptation_transform) ... # doctest: +ELLIPSIS array([[ 0.6484414..., 0.3308533...], [ 0.3211951..., 0.5978443...], [ 0.1558932..., 0.0660492...]]) """ primaries = np.reshape(primaries, (3, 2)) XYZ_a = chromatic_adaptation_VonKries(xy_to_XYZ(primaries), xy_to_XYZ(whitepoint_t), xy_to_XYZ(whitepoint_r), chromatic_adaptation_transform) P_a = XYZ_to_xyY(XYZ_a)[..., 0:2] return P_a
def XYZ_to_UVW(XYZ, illuminant=ILLUMINANTS.get( 'CIE 1931 2 Degree Standard Observer').get('D50')): """ Converts from *CIE XYZ* colourspace to *CIE 1964 U\*V*\W\** colourspace. Parameters ---------- XYZ : array_like, (3,) *CIE XYZ* colourspace matrix. illuminant : array_like, optional Reference *illuminant* chromaticity coordinates. Returns ------- ndarray, (3,) *CIE 1964 U\*V*\W\** colourspace matrix. Notes ----- - Input *CIE XYZ* colourspace matrix is in domain [0, 100]. - Output *CIE UVW* colourspace matrix is in domain [0, 100]. Warning ------- The input / output domains of that definition are non standard! Examples -------- >>> XYZ = np.array([11.80583421, 10.34, 5.15089229]) >>> XYZ_to_UVW(XYZ) # doctest: +ELLIPSIS array([ 24.2543371..., 7.2205484..., 37.4645000...]) """ x, y, Y = np.ravel(XYZ_to_xyY(XYZ, illuminant)) u, v = np.ravel(UCS_to_uv(XYZ_to_UCS(XYZ))) u0, v0 = np.ravel(UCS_to_uv(XYZ_to_UCS(xy_to_XYZ(illuminant)))) W = 25 * Y**(1 / 3) - 17 U = 13 * W * (u - u0) V = 13 * W * (v - v0) return np.array([U, V, W])
def test_XYZ_to_xyY(self): """ Tests :func:`colour.models.cie_xyy.XYZ_to_xyY` definition. """ np.testing.assert_almost_equal( XYZ_to_xyY(np.array([0.07049534, 0.10080000, 0.09558313])), np.array([0.26414772, 0.37770001, 0.10080000]), decimal=7) np.testing.assert_almost_equal( XYZ_to_xyY(np.array([0.47097710, 0.34950000, 0.11301649])), np.array([0.50453169, 0.37440000, 0.34950000]), decimal=7) np.testing.assert_almost_equal( XYZ_to_xyY(np.array([0.25506814, 0.19150000, 0.08849752])), np.array([0.47670437, 0.35790000, 0.19150000]), decimal=7) np.testing.assert_almost_equal( XYZ_to_xyY(np.array([0.00000000, 0.00000000, 0.00000000])), np.array([0.34570000, 0.35850000, 0.00000000]), decimal=7) np.testing.assert_almost_equal( XYZ_to_xyY(np.array([0.00000000, 0.00000000, 1.00000000])), np.array([0.00000000, 0.00000000, 0.00000000]), decimal=7) np.testing.assert_almost_equal( XYZ_to_xyY( np.array([ [0.07049534, 0.10080000, 0.09558313], [0.00000000, 0.00000000, 0.00000000], [0.00000000, 0.00000000, 1.00000000], ])), np.array([ [0.26414772, 0.37770001, 0.10080000], [0.34570000, 0.35850000, 0.00000000], [0.00000000, 0.00000000, 0.00000000], ]), decimal=7)
def XYZ_to_colourspace_model(XYZ, illuminant, model, **kwargs): """ Converts from *CIE XYZ* tristimulus values to given colourspace model. Parameters ---------- XYZ : array_like *CIE XYZ* tristimulus values. illuminant : array_like *CIE XYZ* tristimulus values *illuminant* *xy* chromaticity coordinates. model : unicode **{'CIE XYZ', 'CIE xyY', 'CIE xy', 'CIE Lab', 'CIE LCHab', 'CIE Luv', 'CIE Luv uv', 'CIE LCHuv', 'CIE UCS', 'CIE UCS uv', 'CIE UVW', 'DIN 99', 'Hunter Lab', 'Hunter Rdab', 'IPT', 'JzAzBz, 'OSA UCS', 'hdr-CIELAB', 'hdr-IPT'}**, Colourspace model to convert the *CIE XYZ* tristimulus values to. Other Parameters ---------------- \\**kwargs : dict, optional Keywords arguments. Returns ------- ndarray Colourspace model values. Examples -------- >>> import numpy as np >>> XYZ = np.array([0.20654008, 0.12197225, 0.05136952]) >>> W = np.array([0.31270, 0.32900]) >>> XYZ_to_colourspace_model( # doctest: +ELLIPSIS ... XYZ, W, 'CIE XYZ') array([ 0.2065400..., 0.1219722..., 0.0513695...]) >>> XYZ_to_colourspace_model( # doctest: +ELLIPSIS ... XYZ, W, 'CIE xyY') array([ 0.5436955..., 0.3210794..., 0.1219722...]) >>> XYZ_to_colourspace_model( # doctest: +ELLIPSIS ... XYZ, W, 'CIE xy') array([ 0.5436955..., 0.3210794...]) >>> XYZ_to_colourspace_model( # doctest: +ELLIPSIS ... XYZ, W, 'CIE Lab') array([ 0.4152787..., 0.5263858..., 0.2692317...]) >>> XYZ_to_colourspace_model( # doctest: +ELLIPSIS ... XYZ, W, 'CIE LCHab') array([ 0.4152787..., 0.5912425..., 0.0752458...]) >>> XYZ_to_colourspace_model( # doctest: +ELLIPSIS ... XYZ, W, 'CIE Luv') array([ 0.4152787..., 0.9683626..., 0.1775210...]) >>> XYZ_to_colourspace_model( # doctest: +ELLIPSIS ... XYZ, W, 'CIE Luv uv') array([ 0.3772021..., 0.5012026...]) >>> XYZ_to_colourspace_model( # doctest: +ELLIPSIS ... XYZ, W, 'CIE LCHuv') array([ 0.4152787..., 0.9844997..., 0.0288560...]) >>> XYZ_to_colourspace_model( # doctest: +ELLIPSIS ... XYZ, W, 'CIE UCS uv') array([ 0.3772021..., 0.3341350...]) >>> XYZ_to_colourspace_model( # doctest: +ELLIPSIS ... XYZ, W, 'CIE UVW') array([ 0.9455035..., 0.1155536..., 0.4054757...]) >>> XYZ_to_colourspace_model( # doctest: +ELLIPSIS ... XYZ, W, 'DIN 99') array([ 0.5322822..., 0.2841634..., 0.0389839...]) >>> XYZ_to_colourspace_model( # doctest: +ELLIPSIS ... XYZ, W, 'Hunter Lab') array([ 0.3492452..., 0.4703302..., 0.1439330...]) >>> XYZ_to_colourspace_model( # doctest: +ELLIPSIS ... XYZ, W, 'Hunter Rdab') array([ 0.1219722..., 0.5709032..., 0.1747109...]) >>> XYZ_to_colourspace_model( # doctest: +ELLIPSIS ... XYZ, W, 'IPT') array([ 0.3842619..., 0.3848730..., 0.1888683...]) >>> XYZ_to_colourspace_model( # doctest: +ELLIPSIS ... XYZ, W, 'JzAzBz') array([ 0.0053504..., 0.0092430..., 0.0052600...]) >>> XYZ_to_colourspace_model( # doctest: +ELLIPSIS ... XYZ, W, 'OSA UCS') array([-0.0300499..., 0.0299713..., -0.0966784...]) >>> XYZ_to_colourspace_model( # doctest: +ELLIPSIS ... XYZ, W, 'hdr-CIELAB') array([ 0.5187002..., 0.6047633..., 0.3214551...]) >>> XYZ_to_colourspace_model( # doctest: +ELLIPSIS ... XYZ, W, 'hdr-IPT') array([ 0.4839376..., 0.4244990..., 0.2201954...]) """ with domain_range_scale(1): values = None if model == 'CIE XYZ': values = XYZ elif model == 'CIE xyY': values = XYZ_to_xyY(XYZ, illuminant) elif model == 'CIE xy': values = XYZ_to_xy(XYZ, illuminant) elif model == 'CIE Lab': values = XYZ_to_Lab(XYZ, illuminant) elif model == 'CIE LCHab': values = Lab_to_LCHab(XYZ_to_Lab(XYZ, illuminant)) elif model == 'CIE Luv': values = XYZ_to_Luv(XYZ, illuminant) elif model == 'CIE Luv uv': values = Luv_to_uv(XYZ_to_Luv(XYZ, illuminant), illuminant) elif model == 'CIE LCHuv': values = Luv_to_LCHuv(XYZ_to_Luv(XYZ, illuminant)) elif model == 'CIE UCS': values = XYZ_to_UCS(XYZ) elif model == 'CIE UCS uv': values = UCS_to_uv(XYZ_to_UCS(XYZ)) elif model == 'CIE UVW': values = XYZ_to_UVW(XYZ, illuminant) elif model == 'DIN 99': values = Lab_to_DIN99(XYZ_to_Lab(XYZ, illuminant)) elif model == 'Hunter Lab': values = XYZ_to_Hunter_Lab(XYZ, xy_to_XYZ(illuminant)) elif model == 'Hunter Rdab': values = XYZ_to_Hunter_Rdab(XYZ, xy_to_XYZ(illuminant)) elif model == 'IPT': values = XYZ_to_IPT(XYZ) elif model == 'JzAzBz': values = XYZ_to_JzAzBz(XYZ) elif model == 'OSA UCS': values = XYZ_to_OSA_UCS(XYZ) elif model == 'hdr-CIELAB': values = XYZ_to_hdr_CIELab(XYZ, illuminant, **kwargs) elif model == 'hdr-IPT': values = XYZ_to_hdr_IPT(XYZ, **kwargs) if values is None: raise ValueError( '"{0}" not found in colourspace models: "{1}".'.format( model, ', '.join(COLOURSPACE_MODELS))) return values
def XYZ_to_colourspace_model(XYZ, illuminant, model, **kwargs): """ Converts from *CIE XYZ* tristimulus values to given colourspace model. Parameters ---------- XYZ : array_like *CIE XYZ* tristimulus values. illuminant : array_like Reference *illuminant* *CIE xy* chromaticity coordinates or *CIE xyY* colourspace array. model : unicode **{'CIE XYZ', 'CIE xyY', 'CIE xy', 'CIE Lab', 'CIE LCHab', 'CIE Luv', 'CIE Luv uv', 'CIE LCHuv', 'CIE UCS', 'CIE UCS uv', 'CIE UVW', 'DIN 99', 'Hunter Lab', 'Hunter Rdab', 'IPT', 'JzAzBz, 'OSA UCS', 'hdr-CIELAB', 'hdr-IPT'}**, Colourspace model to convert the *CIE XYZ* tristimulus values to. Other Parameters ---------------- \\**kwargs : dict, optional Keywords arguments. Returns ------- ndarray Colourspace model values. Warnings -------- This definition is is deprecated and will be removed in a future release. :func:`colour.convert` definition should be used instead. Examples -------- >>> import numpy as np >>> XYZ = np.array([0.20654008, 0.12197225, 0.05136952]) >>> W = np.array([0.31270, 0.32900]) >>> XYZ_to_colourspace_model( # doctest: +ELLIPSIS ... XYZ, W, 'CIE XYZ') array([ 0.2065400..., 0.1219722..., 0.0513695...]) >>> XYZ_to_colourspace_model( # doctest: +ELLIPSIS ... XYZ, W, 'CIE xyY') array([ 0.5436955..., 0.3210794..., 0.1219722...]) >>> XYZ_to_colourspace_model( # doctest: +ELLIPSIS ... XYZ, W, 'CIE xy') array([ 0.5436955..., 0.3210794...]) >>> XYZ_to_colourspace_model( # doctest: +ELLIPSIS ... XYZ, W, 'CIE Lab') array([ 0.4152787..., 0.5263858..., 0.2692317...]) >>> XYZ_to_colourspace_model( # doctest: +ELLIPSIS ... XYZ, W, 'CIE LCHab') array([ 0.4152787..., 0.5912425..., 0.0752458...]) >>> XYZ_to_colourspace_model( # doctest: +ELLIPSIS ... XYZ, W, 'CIE Luv') array([ 0.4152787..., 0.9683626..., 0.1775210...]) >>> XYZ_to_colourspace_model( # doctest: +ELLIPSIS ... XYZ, W, 'CIE Luv uv') array([ 0.3772021..., 0.5012026...]) >>> XYZ_to_colourspace_model( # doctest: +ELLIPSIS ... XYZ, W, 'CIE LCHuv') array([ 0.4152787..., 0.9844997..., 0.0288560...]) >>> XYZ_to_colourspace_model( # doctest: +ELLIPSIS ... XYZ, W, 'CIE UCS') array([ 0.1376933..., 0.1219722..., 0.1053731...]) >>> XYZ_to_colourspace_model( # doctest: +ELLIPSIS ... XYZ, W, 'CIE UCS uv') array([ 0.3772021..., 0.3341350...]) >>> XYZ_to_colourspace_model( # doctest: +ELLIPSIS ... XYZ, W, 'CIE UVW') array([ 0.9455035..., 0.1155536..., 0.4054757...]) >>> XYZ_to_colourspace_model( # doctest: +ELLIPSIS ... XYZ, W, 'DIN 99') array([ 0.5322822..., 0.2841634..., 0.0389839...]) >>> XYZ_to_colourspace_model( # doctest: +ELLIPSIS ... XYZ, W, 'Hunter Lab') array([ 0.3492452..., 0.4703302..., 0.1439330...]) >>> XYZ_to_colourspace_model( # doctest: +ELLIPSIS ... XYZ, W, 'Hunter Rdab') array([ 0.1219722..., 0.5709032..., 0.1747109...]) >>> XYZ_to_colourspace_model( # doctest: +ELLIPSIS ... XYZ, W, 'IPT') array([ 0.3842619..., 0.3848730..., 0.1888683...]) >>> XYZ_to_colourspace_model( # doctest: +ELLIPSIS ... XYZ, W, 'JzAzBz') array([ 0.0053504..., 0.0092430..., 0.0052600...]) >>> XYZ_to_colourspace_model( # doctest: +ELLIPSIS ... XYZ, W, 'OSA UCS') array([-0.0300499..., 0.0299713..., -0.0966784...]) >>> XYZ_to_colourspace_model( # doctest: +ELLIPSIS ... XYZ, W, 'hdr-CIELAB') array([ 0.5187002..., 0.6047633..., 0.3214551...]) >>> XYZ_to_colourspace_model( # doctest: +ELLIPSIS ... XYZ, W, 'hdr-IPT') array([ 0.4839376..., 0.4244990..., 0.2201954...]) >>> try: ... XYZ_to_colourspace_model(XYZ, W, 'Undefined') ... except ValueError as error: ... print(error) "Undefined" not found in colourspace models: "CIE XYZ, CIE xyY, CIE Lab, \ CIE LCHab, CIE Luv, CIE Luv uv, CIE LCHuv, CIE UCS, CIE UCS uv, CIE UVW, \ DIN 99, Hunter Lab, Hunter Rdab, IPT, JzAzBz, OSA UCS, hdr-CIELAB, hdr-IPT". """ from colour.models import ( Lab_to_DIN99, Lab_to_LCHab, Luv_to_LCHuv, Luv_to_uv, UCS_to_uv, XYZ_to_IPT, XYZ_to_Hunter_Lab, XYZ_to_Hunter_Rdab, XYZ_to_Lab, XYZ_to_Luv, XYZ_to_OSA_UCS, XYZ_to_UCS, XYZ_to_UVW, XYZ_to_hdr_CIELab, XYZ_to_hdr_IPT, XYZ_to_JzAzBz, XYZ_to_xy, XYZ_to_xyY, xy_to_XYZ) with domain_range_scale(1): values = None if model == 'CIE XYZ': values = XYZ elif model == 'CIE xyY': values = XYZ_to_xyY(XYZ, illuminant) elif model == 'CIE xy': values = XYZ_to_xy(XYZ, illuminant) elif model == 'CIE Lab': values = XYZ_to_Lab(XYZ, illuminant) elif model == 'CIE LCHab': values = Lab_to_LCHab(XYZ_to_Lab(XYZ, illuminant)) elif model == 'CIE Luv': values = XYZ_to_Luv(XYZ, illuminant) elif model == 'CIE Luv uv': values = Luv_to_uv(XYZ_to_Luv(XYZ, illuminant), illuminant) elif model == 'CIE LCHuv': values = Luv_to_LCHuv(XYZ_to_Luv(XYZ, illuminant)) elif model == 'CIE UCS': values = XYZ_to_UCS(XYZ) elif model == 'CIE UCS uv': values = UCS_to_uv(XYZ_to_UCS(XYZ)) elif model == 'CIE UVW': values = XYZ_to_UVW(XYZ, illuminant) elif model == 'DIN 99': values = Lab_to_DIN99(XYZ_to_Lab(XYZ, illuminant)) elif model == 'Hunter Lab': values = XYZ_to_Hunter_Lab(XYZ, xy_to_XYZ(illuminant)) elif model == 'Hunter Rdab': values = XYZ_to_Hunter_Rdab(XYZ, xy_to_XYZ(illuminant)) elif model == 'IPT': values = XYZ_to_IPT(XYZ) elif model == 'JzAzBz': values = XYZ_to_JzAzBz(XYZ) elif model == 'OSA UCS': values = XYZ_to_OSA_UCS(XYZ) elif model == 'hdr-CIELAB': values = XYZ_to_hdr_CIELab(XYZ, illuminant, **kwargs) elif model == 'hdr-IPT': values = XYZ_to_hdr_IPT(XYZ, **kwargs) if values is None: raise ValueError( '"{0}" not found in colourspace models: "{1}".'.format( model, ', '.join(COLOURSPACE_MODELS))) return values
def XYZ_to_reference_colourspace(XYZ, illuminant, reference_colourspace): """ Converts from *CIE XYZ* tristimulus values to given reference colourspace. Parameters ---------- XYZ : array_like *CIE XYZ* tristimulus values. illuminant : array_like *CIE XYZ* tristimulus values *illuminant* *xy* chromaticity coordinates. reference_colourspace : unicode **{'CIE XYZ', 'CIE xyY', 'CIE xy', 'CIE Lab', 'CIE Luv', 'CIE Luv uv', 'CIE UCS', 'CIE UCS uv', 'CIE UVW', 'IPT'}**, Reference colourspace to convert the *CIE XYZ* tristimulus values to. Returns ------- ndarray Reference colourspace values. Examples -------- >>> import numpy as np >>> XYZ = np.array([0.07049534, 0.10080000, 0.09558313]) >>> W = np.array([0.34567, 0.35850]) >>> XYZ_to_reference_colourspace( # doctest: +ELLIPSIS ... XYZ, W, 'CIE XYZ') array([ 0.0704953..., 0.1008 , 0.0955831...]) >>> XYZ_to_reference_colourspace( # doctest: +ELLIPSIS ... XYZ, W, 'CIE xyY') array([ 0.2641477..., 0.3777000..., 0.1008 ]) >>> XYZ_to_reference_colourspace( # doctest: +ELLIPSIS ... XYZ, W, 'CIE xy') array([ 0.2641477..., 0.3777000...]) >>> XYZ_to_reference_colourspace( # doctest: +ELLIPSIS ... XYZ, W, 'CIE Lab') array([-23.6230288..., -4.4141703..., 37.9856291...]) >>> XYZ_to_reference_colourspace( # doctest: +ELLIPSIS ... XYZ, W, 'CIE LCHab') array([ 24.0319036..., 190.5841597..., 37.9856291...]) >>> XYZ_to_reference_colourspace( # doctest: +ELLIPSIS ... XYZ, W, 'CIE Luv') array([-28.7922944..., -1.3558195..., 37.9856291...]) >>> XYZ_to_reference_colourspace( # doctest: +ELLIPSIS ... XYZ, W, 'CIE Luv uv') array([ 0.1508531..., 0.4853297...]) >>> XYZ_to_reference_colourspace( # doctest: +ELLIPSIS ... XYZ, W, 'CIE LCHuv') array([ 28.82419932, 182.69604747, 37.9856291 ]) >>> XYZ_to_reference_colourspace( # doctest: +ELLIPSIS ... XYZ, W, 'CIE UCS uv') array([ 0.1508531..., 0.32355314...]) >>> XYZ_to_reference_colourspace( # doctest: +ELLIPSIS ... XYZ, W, 'CIE UVW') array([-28.0483277..., -0.8805242..., 37.0041149...]) >>> XYZ_to_reference_colourspace( # doctest: +ELLIPSIS ... XYZ, W, 'IPT') array([-0.1111479..., 0.0159474..., 0.3657112...]) """ value = None if reference_colourspace == 'CIE XYZ': value = XYZ if reference_colourspace == 'CIE xyY': value = XYZ_to_xyY(XYZ, illuminant) if reference_colourspace == 'CIE xy': # Used for Chromaticity Diagram. value = XYZ_to_xy(XYZ, illuminant) if reference_colourspace == 'CIE Lab': L, a, b = tsplit(XYZ_to_Lab(XYZ, illuminant)) value = tstack((a, b, L)) if reference_colourspace == 'CIE LCHab': L, CH, ab = tsplit(Lab_to_LCHab(XYZ_to_Lab(XYZ, illuminant))) value = tstack((CH, ab, L)) if reference_colourspace == 'CIE Luv': L, u, v = tsplit(XYZ_to_Luv(XYZ, illuminant)) value = tstack((u, v, L)) if reference_colourspace == 'CIE Luv uv': # Used for Chromaticity Diagram. u, v = tsplit(Luv_to_uv(XYZ_to_Luv(XYZ, illuminant), illuminant)) value = tstack((u, v)) if reference_colourspace == 'CIE LCHuv': L, CH, uv = tsplit(Luv_to_LCHuv(XYZ_to_Luv(XYZ, illuminant))) value = tstack((CH, uv, L)) if reference_colourspace == 'CIE UCS': value = XYZ_to_UCS(XYZ) if reference_colourspace == 'CIE UCS uv': # Used for Chromaticity Diagram. u, v = tsplit(UCS_to_uv(XYZ_to_UCS(XYZ))) value = tstack((u, v)) if reference_colourspace == 'CIE UVW': value = XYZ_to_UVW(XYZ * 100, illuminant) if reference_colourspace == 'IPT': I, P, T = tsplit(XYZ_to_IPT(XYZ)) value = tstack((P, T, I)) if value is None: raise ValueError(('"{0}" not found in reference colourspace models: ' '"{1}".').format(reference_colourspace, ', '.join(REFERENCE_COLOURSPACES))) return value
def tcs_colorimetry_data( sd_t: SpectralDistribution, sd_r: SpectralDistribution, sds_tcs: Dict[str, SpectralDistribution], cmfs: MultiSpectralDistributions, chromatic_adaptation: Boolean = False, ) -> Tuple[TCS_ColorimetryData, ...]: """ Return the *test colour samples* colorimetry data. Parameters ---------- sd_t Test spectral distribution. sd_r Reference spectral distribution. sds_tcs *Test colour samples* spectral distributions. cmfs Standard observer colour matching functions. chromatic_adaptation Perform chromatic adaptation. Returns ------- :class:`tuple` *Test colour samples* colorimetry data. """ XYZ_t = sd_to_XYZ(sd_t, cmfs) uv_t = UCS_to_uv(XYZ_to_UCS(XYZ_t)) u_t, v_t = uv_t[0], uv_t[1] XYZ_r = sd_to_XYZ(sd_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(INDEXES_TO_NAMES_TCS.items()): sd_tcs = sds_tcs[value] XYZ_tcs = sd_to_XYZ(sd_tcs, cmfs, sd_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: FloatingOrNDArray, y: FloatingOrNDArray ) -> FloatingOrNDArray: """Compute the :math:`c` term.""" return (4 - x - 10 * y) / y def d( x: FloatingOrNDArray, y: FloatingOrNDArray ) -> FloatingOrNDArray: """Compute 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 * spow(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( sd_tcs.name, XYZ_tcs, uv_tcs, np.array([U_tcs, V_tcs, W_tcs]) ) ) return tuple(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 XYZ_to_colourspace_model(XYZ, illuminant, model): """ Converts from *CIE XYZ* tristimulus values to given colourspace model. Parameters ---------- XYZ : array_like *CIE XYZ* tristimulus values. illuminant : array_like *CIE XYZ* tristimulus values *illuminant* *xy* chromaticity coordinates. model : unicode **{'CIE XYZ', 'CIE xyY', 'CIE xy', 'CIE Lab', 'CIE LCHab', 'CIE Luv', 'CIE Luv uv', 'CIE LCHuv', 'CIE UCS', 'CIE UCS uv', 'CIE UVW', 'IPT', 'Hunter Lab', 'Hunter Rdab'}**, Colourspace model to convert the *CIE XYZ* tristimulus values to. Returns ------- ndarray Colourspace model values. Examples -------- >>> import numpy as np >>> XYZ = np.array([0.07049534, 0.10080000, 0.09558313]) >>> W = np.array([0.34570, 0.35850]) >>> XYZ_to_colourspace_model( # doctest: +ELLIPSIS ... XYZ, W, 'CIE XYZ') array([ 0.0704953..., 0.1008 , 0.0955831...]) >>> XYZ_to_colourspace_model( # doctest: +ELLIPSIS ... XYZ, W, 'CIE xyY') array([ 0.2641477..., 0.3777000..., 0.1008 ]) >>> XYZ_to_colourspace_model( # doctest: +ELLIPSIS ... XYZ, W, 'CIE xy') array([ 0.2641477..., 0.3777000...]) >>> XYZ_to_colourspace_model( # doctest: +ELLIPSIS ... XYZ, W, 'CIE Lab') array([ 37.9856291..., -23.6290768..., -4.4174661...]) >>> XYZ_to_colourspace_model( # doctest: +ELLIPSIS ... XYZ, W, 'CIE LCHab') array([ 37.9856291..., 24.0384542..., 190.5892337...]) >>> XYZ_to_colourspace_model( # doctest: +ELLIPSIS ... XYZ, W, 'CIE Luv') array([ 37.9856291..., -28.8021959..., -1.3580070...]) >>> XYZ_to_colourspace_model( # doctest: +ELLIPSIS ... XYZ, W, 'CIE Luv uv') array([ 0.1508531..., 0.4853297...]) >>> XYZ_to_colourspace_model( # doctest: +ELLIPSIS ... XYZ, W, 'CIE LCHuv') array([ 37.9856291..., 28.8341927..., 182.6994640...]) >>> XYZ_to_colourspace_model( # doctest: +ELLIPSIS ... XYZ, W, 'CIE UCS uv') array([ 0.1508531..., 0.32355314...]) >>> XYZ_to_colourspace_model( # doctest: +ELLIPSIS ... XYZ, W, 'CIE UVW') array([-28.0579733..., -0.8819449..., 37.0041149...]) >>> XYZ_to_colourspace_model( # doctest: +ELLIPSIS ... XYZ, W, 'IPT') array([ 0.3657112..., -0.1111479..., 0.0159474...]) >>> XYZ_to_colourspace_model( # doctest: +ELLIPSIS ... XYZ, W, 'Hunter Lab') array([ 31.7490157..., -15.1351736..., -2.7709606...]) >>> XYZ_to_colourspace_model( # doctest: +ELLIPSIS ... XYZ, W, 'Hunter Rdab') array([ 10.08..., -18.7019271..., -3.4239649...]) """ values = None if model == 'CIE XYZ': values = XYZ elif model == 'CIE xyY': values = XYZ_to_xyY(XYZ, illuminant) elif model == 'CIE xy': values = XYZ_to_xy(XYZ, illuminant) elif model == 'CIE Lab': values = XYZ_to_Lab(XYZ, illuminant) elif model == 'CIE LCHab': values = Lab_to_LCHab(XYZ_to_Lab(XYZ, illuminant)) elif model == 'CIE Luv': values = XYZ_to_Luv(XYZ, illuminant) elif model == 'CIE Luv uv': values = Luv_to_uv(XYZ_to_Luv(XYZ, illuminant), illuminant) elif model == 'CIE LCHuv': values = Luv_to_LCHuv(XYZ_to_Luv(XYZ, illuminant)) elif model == 'CIE UCS': values = XYZ_to_UCS(XYZ) elif model == 'CIE UCS uv': values = UCS_to_uv(XYZ_to_UCS(XYZ)) elif model == 'CIE UVW': values = XYZ_to_UVW(XYZ * 100, illuminant) elif model == 'IPT': values = XYZ_to_IPT(XYZ) elif model == 'Hunter Lab': values = XYZ_to_Hunter_Lab(XYZ * 100, xy_to_XYZ(illuminant) * 100) elif model == 'Hunter Rdab': values = XYZ_to_Hunter_Rdab(XYZ * 100, xy_to_XYZ(illuminant) * 100) if values is None: raise ValueError( '"{0}" not found in colourspace models: "{1}".'.format( model, ', '.join(COLOURSPACE_MODELS))) return values
def tcs_colorimetry_data(sd_t, sd_r, sds_tcs, cmfs, chromatic_adaptation=False): """ Returns the *test colour samples* colorimetry data. Parameters ---------- sd_t : SpectralDistribution Test spectral distribution. sd_r : SpectralDistribution Reference spectral distribution. sds_tcs : dict *Test colour samples* spectral 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 = sd_to_XYZ(sd_t, cmfs) uv_t = UCS_to_uv(XYZ_to_UCS(XYZ_t)) u_t, v_t = uv_t[0], uv_t[1] XYZ_r = sd_to_XYZ(sd_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()): sd_tcs = sds_tcs[value] XYZ_tcs = sd_to_XYZ(sd_tcs, cmfs, sd_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 * spow(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(sd_tcs.name, XYZ_tcs, uv_tcs, np.array([U_tcs, V_tcs, W_tcs]))) return tcs_data
def XYZ_to_OSA_UCS(XYZ): """ Converts from *CIE XYZ* tristimulus values under the *CIE 1964 10 Degree Standard Observer* to *OSA UCS* colourspace. The lightness axis, *L* is usually in range [-9, 5] and centered around middle gray (Munsell N/6). The yellow-blue axis, *j* is usually in range [-15, 15]. The red-green axis, *g* is usually in range [-20, 15]. Parameters ---------- XYZ : array_like *CIE XYZ* tristimulus values under the *CIE 1964 10 Degree Standard Observer*. Returns ------- ndarray *OSA UCS* :math:`Ljg` lightness, jaune (yellowness), and greenness. Notes ----- +------------+-----------------------+--------------------+ | **Domain** | **Scale - Reference** | **Scale - 1** | +============+=======================+====================+ | ``XYZ`` | [0, 100] | [0, 1] | +------------+-----------------------+--------------------+ +------------+-----------------------+--------------------+ | **Range** | **Scale - Reference** | **Scale - 1** | +============+=======================+====================+ | ``Ljg`` | ``L`` : [-100, 100] | ``L`` : [-1, 1] | | | | | | | ``j`` : [-100, 100] | ``j`` : [-1, 1] | | | | | | | ``g`` : [-100, 100] | ``g`` : [-1, 1] | +------------+-----------------------+--------------------+ - *OSA UCS* uses the *CIE 1964 10 Degree Standard Observer*. References ---------- :cite:`Cao2013`, :cite:`Moroney2003` Examples -------- >>> import numpy as np >>> XYZ = np.array([0.20654008, 0.12197225, 0.05136952]) * 100 >>> XYZ_to_OSA_UCS(XYZ) # doctest: +ELLIPSIS array([-3.0049979..., 2.9971369..., -9.6678423...]) """ XYZ = to_domain_100(XYZ) x, y, Y = tsplit(XYZ_to_xyY(XYZ)) Y_0 = Y * (4.4934 * x**2 + 4.3034 * y**2 - 4.276 * x * y - 1.3744 * x - 2.5643 * y + 1.8103) o_3 = 1 / 3 Y_0_es = spow(Y_0, o_3) - 2 / 3 # Gracefully handles Y_0 < 30. Y_0_s = Y_0 - 30 Lambda = 5.9 * (Y_0_es + 0.042 * spow(Y_0_s, o_3)) RGB = dot_vector(M_XYZ_TO_RGB_OSA_UCS, XYZ) RGB_3 = spow(RGB, 1 / 3) C = Lambda / (5.9 * Y_0_es) L = (Lambda - 14.4) / spow(2, 1 / 2) j = C * np.dot(RGB_3, np.array([1.7, 8, -9.7])) g = C * np.dot(RGB_3, np.array([-13.7, 17.7, -4])) Ljg = tstack([L, j, g]) return from_range_100(Ljg)
def XYZ_to_UVW( XYZ, illuminant=ILLUMINANTS['CIE 1931 2 Degree Standard Observer']['D65']): """ Converts from *CIE XYZ* tristimulus values to *CIE 1964 U\\*V\\*W\\** colourspace. Parameters ---------- XYZ : array_like *CIE XYZ* tristimulus values. illuminant : array_like, optional Reference *illuminant* *xy* chromaticity coordinates or *CIE xyY* colourspace array. Returns ------- ndarray *CIE 1964 U\\*V\\*W\\** colourspace array. Warning ------- The input domain and output range of that definition are non standard! Notes ----- +----------------+-----------------------+-----------------+ | **Domain** | **Scale - Reference** | **Scale - 1** | +================+=======================+=================+ | ``XYZ`` | [0, 1] | [0, 1] | +----------------+-----------------------+-----------------+ | ``illuminant`` | [0, 1] | [0, 1] | +----------------+-----------------------+-----------------+ +----------------+-----------------------+-----------------+ | **Range** | **Scale - Reference** | **Scale - 1** | +================+=======================+=================+ | ``UVW`` | ``U`` : [-100, 100] | ``U`` : [-1, 1] | | | | | | | ``V`` : [-100, 100] | ``V`` : [-1, 1] | | | | | | | ``W`` : [0, 100] | ``W`` : [0, 1] | +----------------+-----------------------+-----------------+ References ---------- :cite:`Wikipedia2008a` Examples -------- >>> import numpy as np >>> XYZ = np.array([0.20654008, 0.12197225, 0.05136952]) * 100 >>> XYZ_to_UVW(XYZ) # doctest: +ELLIPSIS array([ 94.5503572..., 11.5553652..., 40.5475740...]) """ XYZ = to_domain_100(XYZ) xy = xyY_to_xy(illuminant) xyY = XYZ_to_xyY(XYZ, xy) _x, _y, Y = tsplit(xyY) u, v = tsplit(UCS_to_uv(XYZ_to_UCS(XYZ))) u_0, v_0 = tsplit(xy_to_UCS_uv(xy)) W = 25 * spow(Y, 1 / 3) - 17 U = 13 * W * (u - u_0) V = 13 * W * (v - v_0) UVW = tstack([U, V, W]) return from_range_100(UVW)
Notes ----- - *X-Rite* data is given as *CIE L\\*a\\*b\\** colourspace values under *CIE Illuminant D Series D50* for the *CIE 1931 2 Degree Standard Observer*. DATA_COLORCHECKER24_BEFORE_NOV2014 : ndarray """ DATA_COLORCHECKER24_BEFORE_NOV2014 = OrderedDict( zip( SAMPLE_LABELS_COLORCHECKER_CLASSIC, XYZ_to_xyY( Lab_to_XYZ( list(DATA_COLORCHECKER24_BEFORE_NOV2014.values()), CCS_ILLUMINANTS['CIE 1931 2 Degree Standard Observer'] ['ICC D50'])))) CCS_ILLUMINANT_COLORCHECKER24_BEFORE_NOV2014 = ( CCS_ILLUMINANTS['CIE 1931 2 Degree Standard Observer']['ICC D50']) """ *ColorChecker24 - Before November 2014* illuminant. CCS_ILLUMINANT_COLORCHECKER24_BEFORE_NOV2014 : ndarray """ CCS_COLORCHECKER24_BEFORE_NOV2014 = ColourChecker( 'ColorChecker24 - Before November 2014', DATA_COLORCHECKER24_BEFORE_NOV2014, CCS_ILLUMINANT_COLORCHECKER24_BEFORE_NOV2014)
*ColorChecker24 - Before November 2014* illuminant. Notes ----- - *X-Rite* data is given as *CIE L\\*a\\*b\\** colourspace values under *CIE Illuminant D Series D50* for the *CIE 1931 2 Degree Standard Observer*. COLORCHECKER24_BEFORE_NOV2014_LAB_DATA : ndarray """ COLORCHECKER24_BEFORE_NOV2014_DATA = OrderedDict( zip( COLORCHECKER24_BEFORE_NOV2014_LAB_DATA.keys(), XYZ_to_xyY( Lab_to_XYZ( list(COLORCHECKER24_BEFORE_NOV2014_LAB_DATA.values()), ILLUMINANTS['CIE 1931 2 Degree Standard Observer']['D50'])))) COLORCHECKER24_BEFORE_NOV2014_ILLUMINANT = ( ILLUMINANTS['CIE 1931 2 Degree Standard Observer']['D50']) """ *ColorChecker24 - Before November 2014* illuminant. COLORCHECKER24_BEFORE_NOV2014_ILLUMINANT : ndarray """ COLORCHECKER24_BEFORE_NOV2014 = ColourChecker( 'ColorChecker24 - Before November 2014', COLORCHECKER24_BEFORE_NOV2014_DATA, COLORCHECKER24_BEFORE_NOV2014_ILLUMINANT) """
np.array([51.038, -28.631, -28.638]), np.array([96.539, -0.425, 1.186]), np.array([81.257, -0.638, -0.335]), np.array([66.766, -0.734, -0.504]), np.array([50.867, -0.153, -0.27]), np.array([35.656, -0.421, -1.231]), np.array([20.461, -0.079, -0.973]), ], )) DATA_COLORCHECKER24_BEFORE_NOV2014: Dict = dict( zip( SAMPLE_LABELS_COLORCHECKER_CLASSIC, XYZ_to_xyY( Lab_to_XYZ( list(DATA_COLORCHECKER24_BEFORE_NOV2014_CIE_LAB.values()), CCS_ILLUMINANTS["CIE 1931 2 Degree Standard Observer"] ["ICC D50"], )), )) CCS_ILLUMINANT_COLORCHECKER24_BEFORE_NOV2014: NDArray = CCS_ILLUMINANTS[ "CIE 1931 2 Degree Standard Observer"]["ICC D50"] """*ColorChecker24 - Before November 2014* illuminant.""" CCS_COLORCHECKER24_BEFORE_NOV2014: ColourChecker = ColourChecker( "ColorChecker24 - Before November 2014", DATA_COLORCHECKER24_BEFORE_NOV2014, CCS_ILLUMINANT_COLORCHECKER24_BEFORE_NOV2014, ) """ Reference *ColorChecker Classic* data from *X-Rite (2015)*.