Example #1
0
    def test_n_dimensional_XYZ_to_LLAB(self):
        """
        Test :func:`colour.appearance.llab.XYZ_to_LLAB` definition
        n-dimensional support.
        """

        XYZ = np.array([19.01, 20.00, 21.78])
        XYZ_0 = np.array([95.05, 100.00, 108.88])
        Y_b = 20
        L = 318.31
        surround = surround = VIEWING_CONDITIONS_LLAB[
            "Reference Samples & Images, Average Surround, Subtending < 4"]
        specification = XYZ_to_LLAB(XYZ, XYZ_0, Y_b, L, surround)

        XYZ = np.tile(XYZ, (6, 1))
        specification = np.tile(specification, (6, 1))
        np.testing.assert_almost_equal(XYZ_to_LLAB(XYZ, XYZ_0, Y_b, L,
                                                   surround),
                                       specification,
                                       decimal=7)

        XYZ_0 = np.tile(XYZ_0, (6, 1))
        np.testing.assert_almost_equal(XYZ_to_LLAB(XYZ, XYZ_0, Y_b, L,
                                                   surround),
                                       specification,
                                       decimal=7)

        XYZ = np.reshape(XYZ, (2, 3, 3))
        XYZ_0 = np.reshape(XYZ_0, (2, 3, 3))
        specification = np.reshape(specification, (2, 3, 8))
        np.testing.assert_almost_equal(XYZ_to_LLAB(XYZ, XYZ_0, Y_b, L,
                                                   surround),
                                       specification,
                                       decimal=7)
Example #2
0
    def test_XYZ_to_LLAB(self):
        """
        Test :func:`colour.appearance.llab.XYZ_to_LLAB` definition.

        Notes
        -----
        -   The test values have been generated from data of the following file
            by *Fairchild (2013)*:
            http://rit-mcsl.org/fairchild//files/AppModEx.xls
        """

        with mock.patch(
                "colour.appearance.llab.MATRIX_RGB_TO_XYZ_LLAB",
                np.around(np.linalg.inv(llab.MATRIX_XYZ_TO_RGB_LLAB),
                          decimals=4),
        ):

            XYZ = np.array([19.01, 20.00, 21.78])
            XYZ_0 = np.array([95.05, 100.00, 108.88])
            Y_b = 20
            L = 318.31
            surround = VIEWING_CONDITIONS_LLAB[
                "Reference Samples & Images, Average Surround, Subtending < 4"]
            np.testing.assert_allclose(
                XYZ_to_LLAB(XYZ, XYZ_0, Y_b, L, surround),
                np.array([37.37, 0.01, 229.5, 0, 0.02, np.nan, -0.01, -0.01]),
                rtol=0.01,
                atol=0.01,
            )

            XYZ = np.array([57.06, 43.06, 31.96])
            L = 31.83
            np.testing.assert_allclose(
                XYZ_to_LLAB(XYZ, XYZ_0, Y_b, L, surround),
                np.array(
                    [61.26, 30.51, 22.3, 0.5, 56.55, np.nan, 52.33, 21.43]),
                rtol=0.01,
                atol=0.01,
            )

            XYZ = np.array([3.53, 6.56, 2.14])
            XYZ_0 = np.array([109.85, 100.00, 35.58])
            L = 318.31
            np.testing.assert_allclose(
                XYZ_to_LLAB(XYZ, XYZ_0, Y_b, L, surround),
                np.array(
                    [16.25, 30.43, 173.8, 1.87, 53.83, np.nan, -53.51, 5.83]),
                rtol=0.01,
                atol=0.01,
            )

            XYZ = np.array([19.01, 20.00, 21.78])
            L = 31.83
            np.testing.assert_allclose(
                XYZ_to_LLAB(XYZ, XYZ_0, Y_b, L, surround),
                np.array(
                    [39.82, 29.34, 271.9, 0.74, 54.59, np.nan, 1.76, -54.56]),
                rtol=0.01,
                atol=0.01,
            )
Example #3
0
    def test_domain_range_scale_XYZ_to_LLAB(self):
        """
        Test :func:`colour.appearance.llab.XYZ_to_LLAB` definition domain
        and range scale support.
        """

        XYZ = np.array([19.01, 20.00, 21.78])
        XYZ_0 = np.array([95.05, 100.00, 108.88])
        Y_b = 20
        L = 318.31
        surround = VIEWING_CONDITIONS_LLAB["ref_average_4_minus"]
        specification = XYZ_to_LLAB(XYZ, XYZ_0, Y_b, L, surround)

        d_r = (
            ("reference", 1, 1),
            ("1", 0.01, np.array([1, 1, 1 / 360, 1, 1, np.nan, 1, 1])),
            ("100", 1, np.array([1, 1, 100 / 360, 1, 1, np.nan, 1, 1])),
        )
        for scale, factor_a, factor_b in d_r:
            with domain_range_scale(scale):
                np.testing.assert_almost_equal(
                    XYZ_to_LLAB(XYZ * factor_a, XYZ_0 * factor_a, Y_b, L,
                                surround),
                    as_float_array(specification) * factor_b,
                    decimal=7,
                )
Example #4
0
    def test_domain_range_scale_XYZ_to_LLAB(self):
        """
        Tests :func:`colour.appearance.llab.XYZ_to_LLAB` definition domain
        and range scale support.
        """

        XYZ = np.array([19.01, 20.00, 21.78])
        XYZ_0 = np.array([95.05, 100.00, 108.88])
        Y_b = 20.0
        L = 318.31
        surround = LLAB_VIEWING_CONDITIONS['ref_average_4_minus']
        specification = XYZ_to_LLAB(XYZ, XYZ_0, Y_b, L, surround)[:5]

        d_r = (
            ('reference', 1, 1),
            (1, 0.01, np.array([1, 1, 1 / 360, 1, 1])),
            (100, 1, np.array([1, 1, 100 / 360, 1, 1])),
        )
        for scale, factor_a, factor_b in d_r:
            with domain_range_scale(scale):
                np.testing.assert_almost_equal(
                    XYZ_to_LLAB(XYZ * factor_a, XYZ_0 * factor_a, Y_b, L,
                                surround)[:5],
                    specification * factor_b,
                    decimal=7)
Example #5
0
    def test_nan_XYZ_to_LLAB(self):
        """
        Tests :func:`colour.appearance.llab.XYZ_to_LLAB` 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)
            XYZ_0 = np.array(case)
            Y_b = case[0]
            L = case[0]
            surround = LLAB_InductionFactors(1, case[0], case[0], case[0])
            XYZ_to_LLAB(XYZ, XYZ_0, Y_b, L, surround)
Example #6
0
    def output_specification_from_data(self, data):
        """
        Returns the *LLAB(l:c)* colour appearance model output specification
        from given data.

        Parameters
        ----------
        data : list
            Fixture data.

        Returns
        -------
        LLAB_Specification
            *LLAB(L:c)* colour appearance model specification.
        """

        XYZ = np.array([data['X'], data['Y'], data['Z']])
        XYZ_0 = np.array([data['X_0'], data['Y_0'], data['Z_0']])

        specification = XYZ_to_LLAB(
            XYZ, XYZ_0, data['Y_b'], data['L'],
            LLAB_InductionFactors(1, data['F_S'], data['F_L'], data['F_C']))
        return specification