def test_n_dimensional_xyY_to_xy(self): """ Tests :func:`colour.models.cie_xyy.xyY_to_xy` definition n-dimensions support. """ xyY = np.array([0.26414772, 0.37770001, 1.]) xy = np.array([0.26414772236966133, 0.37770000704815188]) np.testing.assert_almost_equal( xyY_to_xy(xyY), xy, decimal=7) xyY = np.tile(xyY, (6, 1)) xy = np.tile(xy, (6, 1)) np.testing.assert_almost_equal( xyY_to_xy(xyY), xy, decimal=7) xyY = np.reshape(xyY, (2, 3, 3)) xy = np.reshape(xy, (2, 3, 2)) np.testing.assert_almost_equal( xyY_to_xy(xyY), xy, decimal=7)
def test_xyY_to_xy(self): """Test :func:`colour.models.cie_xyy.xyY_to_xy` definition.""" np.testing.assert_almost_equal( xyY_to_xy(np.array([0.54369557, 0.32107944, 0.12197225])), np.array([0.54369557, 0.32107944]), decimal=7, ) np.testing.assert_almost_equal( xyY_to_xy(np.array([0.29777735, 0.48246446, 0.23042768])), np.array([0.29777735, 0.48246446]), decimal=7, ) np.testing.assert_almost_equal( xyY_to_xy(np.array([0.18582823, 0.14633764, 0.06157201])), np.array([0.18582823, 0.14633764]), decimal=7, ) np.testing.assert_almost_equal( xyY_to_xy(np.array([0.31270, 0.32900])), np.array([0.31270000, 0.32900000]), decimal=7, )
def test_nan_xyY_to_xy(self): """Test :func:`colour.models.cie_xyy.xyY_to_xy` definition nan support.""" cases = [-1.0, 0.0, 1.0, -np.inf, np.inf, np.nan] cases = set(permutations(cases * 3, r=2)) for case in cases: xyY = np.array(case) xyY_to_xy(xyY)
def test_nan_xyY_to_xy(self): """ Tests :func:`colour.models.cie_xyy.xyY_to_xy` definition nan support. """ cases = [-1.0, 0.0, 1.0, -np.inf, np.inf, np.nan] cases = set(permutations(cases * 3, r=2)) for case in cases: xyY = np.array(case) xyY_to_xy(xyY)
def test_domain_range_scale_xyY_to_xy(self): """ Tests :func:`colour.models.cie_xyy.xyY_to_xy` definition domain and range scale support. """ xyY = np.array([0.54369557, 0.32107944, 0.12197225]) xy = xyY_to_xy(xyY) xyY = np.tile(xyY, (6, 1)).reshape(2, 3, 3) xy = np.tile(xy, (6, 1)).reshape(2, 3, 2) d_r = (('reference', 1, 1), (1, 1, 1), (100, np.array([1, 1, 100]), 1)) for scale, factor_a, factor_b in d_r: with domain_range_scale(scale): np.testing.assert_almost_equal( xyY_to_xy(xyY * factor_a), xy * factor_b, decimal=7)
def test_n_dimensional_xyY_to_xy(self): """ Tests :func:`colour.models.cie_xyy.xyY_to_xy` definition n-dimensional support. """ xyY = np.array([0.54369557, 0.32107944, 0.12197225]) xy = xyY_to_xy(xyY) xyY = np.tile(xyY, (6, 1)) xy = np.tile(xy, (6, 1)) np.testing.assert_almost_equal(xyY_to_xy(xyY), xy, decimal=7) xyY = np.reshape(xyY, (2, 3, 3)) xy = np.reshape(xy, (2, 3, 2)) np.testing.assert_almost_equal(xyY_to_xy(xyY), xy, decimal=7)
def test_n_dimensional_xyY_to_xy(self): """ Tests :func:`colour.models.cie_xyy.xyY_to_xy` definition n-dimensions support. """ xyY = np.array([0.26414772, 0.37770001, 1.0]) xy = np.array([0.26414772236966133, 0.37770000704815188]) np.testing.assert_almost_equal(xyY_to_xy(xyY), xy, decimal=7) xyY = np.tile(xyY, (6, 1)) xy = np.tile(xy, (6, 1)) np.testing.assert_almost_equal(xyY_to_xy(xyY), xy, decimal=7) xyY = np.reshape(xyY, (2, 3, 3)) xy = np.reshape(xy, (2, 3, 2)) np.testing.assert_almost_equal(xyY_to_xy(xyY), xy, decimal=7)
def test_xyY_to_xy(self): """ Tests :func:`colour.models.cie_xyy.xyY_to_xy` definition. """ np.testing.assert_almost_equal( xyY_to_xy(np.array([0.26414772, 0.37770001, 1.00000000])), np.array([0.26414772, 0.37770001]), decimal=7 ) np.testing.assert_almost_equal( xyY_to_xy(np.array([0.50453169, 0.37440000, 1.00000000])), np.array([0.50453169, 0.3744]), decimal=7 ) np.testing.assert_almost_equal( xyY_to_xy(np.array([0.47670437, 0.35790000, 1.00000000])), np.array([0.47670437, 0.3579]), decimal=7 ) np.testing.assert_almost_equal(xyY_to_xy(np.array([0.34567, 0.35850])), np.array([0.34567, 0.3585]), decimal=7)
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 XYZ_to_UVW(XYZ, illuminant=ILLUMINANTS.get( 'CIE 1931 2 Degree Standard Observer').get('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. 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 UVW* colourspace array is in range [0, 100]. Warning ------- The input / output domains of that definition are non standard! 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 test_xyY_to_xy(self): """ Tests :func:`colour.models.cie_xyy.xyY_to_xy` definition. """ np.testing.assert_almost_equal(xyY_to_xy( np.array([0.26414772, 0.37770001, 1.00000000])), np.array([0.26414772, 0.37770001]), decimal=7) np.testing.assert_almost_equal(xyY_to_xy( np.array([0.50453169, 0.37440000, 1.00000000])), np.array([0.50453169, 0.37440000]), decimal=7) np.testing.assert_almost_equal(xyY_to_xy( np.array([0.47670437, 0.35790000, 1.00000000])), np.array([0.47670437, 0.35790000]), decimal=7) np.testing.assert_almost_equal(xyY_to_xy(np.array([0.34570, 0.35850])), np.array([0.34570000, 0.35850000]), decimal=7)
def test_xyY_to_xy(self): """ Tests :func:`colour.models.cie_xyy.xyY_to_xy` definition. """ np.testing.assert_almost_equal( xyY_to_xy(np.array([0.54369557, 0.32107944, 0.12197225])), np.array([0.54369557, 0.32107944]), decimal=7) np.testing.assert_almost_equal( xyY_to_xy(np.array([0.29777735, 0.48246446, 0.23042768])), np.array([0.29777735, 0.48246446]), decimal=7) np.testing.assert_almost_equal( xyY_to_xy(np.array([0.18582823, 0.14633764, 0.06157201])), np.array([0.18582823, 0.14633764]), decimal=7) np.testing.assert_almost_equal( xyY_to_xy(np.array([0.31270, 0.32900])), np.array([0.31270000, 0.32900000]), decimal=7)
def UVW_to_XYZ( UVW, illuminant=ILLUMINANTS['CIE 1931 2 Degree Standard Observer']['D65']): """ Converts *CIE 1964 U\\*V\\*W\\** colourspace to *CIE XYZ* tristimulus values. Parameters ---------- UVW : array_like *CIE 1964 U\\*V\\*W\\** colourspace array. illuminant : array_like, optional Reference *illuminant* *xy* chromaticity coordinates or *CIE xyY* colourspace array. Returns ------- ndarray *CIE XYZ* tristimulus values. Warning ------- The input domain and output range of that definition are non standard! Notes ----- +----------------+-----------------------+-----------------+ | **Domain** | **Scale - Reference** | **Scale - 1** | +================+=======================+=================+ | ``UVW`` | ``U`` : [-100, 100] | ``U`` : [-1, 1] | | | | | | | ``V`` : [-100, 100] | ``V`` : [-1, 1] | | | | | | | ``W`` : [0, 100] | ``W`` : [0, 1] | +----------------+-----------------------+-----------------+ | ``illuminant`` | [0, 1] | [0, 1] | +----------------+-----------------------+-----------------+ +----------------+-----------------------+-----------------+ | **Range** | **Scale - Reference** | **Scale - 1** | +================+=======================+=================+ | ``XYZ`` | [0, 1] | [0, 1] | +----------------+-----------------------+-----------------+ References ---------- :cite:`Wikipedia2008a` Examples -------- >>> import numpy as np >>> UVW = np.array([94.55035725, 11.55536523, 40.54757405]) >>> UVW_to_XYZ(UVW) array([ 20.654008, 12.197225, 5.136952]) """ U, V, W = tsplit(to_domain_100(UVW)) u_0, v_0 = tsplit(xy_to_UCS_uv(xyY_to_xy(illuminant))) Y = ((W + 17) / 25) ** 3 u = U / (13 * W) + u_0 v = V / (13 * W) + v_0 x, y = tsplit(UCS_uv_to_xy(tstack([u, v]))) XYZ = xyY_to_XYZ(tstack([x, y, Y])) return from_range_100(XYZ)
def UVW_to_XYZ( UVW, illuminant=ILLUMINANTS['CIE 1931 2 Degree Standard Observer']['D65']): """ Converts *CIE 1964 U\\*V\\*W\\** colourspace to *CIE XYZ* tristimulus values. Parameters ---------- UVW : array_like *CIE 1964 U\\*V\\*W\\** colourspace array. illuminant : array_like, optional Reference *illuminant* *xy* chromaticity coordinates or *CIE xyY* colourspace array. Returns ------- ndarray *CIE XYZ* tristimulus values. Warning ------- The input domain and output range of that definition are non standard! Notes ----- +----------------+-----------------------+-----------------+ | **Domain** | **Scale - Reference** | **Scale - 1** | +================+=======================+=================+ | ``UVW`` | ``U`` : [-100, 100] | ``U`` : [-1, 1] | | | | | | | ``V`` : [-100, 100] | ``V`` : [-1, 1] | | | | | | | ``W`` : [0, 100] | ``W`` : [0, 1] | +----------------+-----------------------+-----------------+ | ``illuminant`` | [0, 1] | [0, 1] | +----------------+-----------------------+-----------------+ +----------------+-----------------------+-----------------+ | **Range** | **Scale - Reference** | **Scale - 1** | +================+=======================+=================+ | ``XYZ`` | [0, 1] | [0, 1] | +----------------+-----------------------+-----------------+ References ---------- :cite:`Wikipedia2008a` Examples -------- >>> import numpy as np >>> UVW = np.array([94.55035725, 11.55536523, 40.54757405]) >>> UVW_to_XYZ(UVW) array([ 20.654008, 12.197225, 5.136952]) """ U, V, W = tsplit(to_domain_100(UVW)) u_0, v_0 = tsplit(xy_to_UCS_uv(xyY_to_xy(illuminant))) Y = ((W + 17) / 25)**3 u = U / (13 * W) + u_0 v = V / (13 * W) + v_0 x, y = tsplit(UCS_uv_to_xy(tstack([u, v]))) XYZ = xyY_to_XYZ(tstack([x, y, Y])) return from_range_100(XYZ)
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)