예제 #1
0
    def test_use_derived_transformation_matrices(self):
        """
        Tests :func:`colour.models.rgb.rgb_colourspace.RGB_Colourspace.range.\
use_derived_transformation_matrices` method.
        """

        p = np.array([0.73470, 0.26530, 0.00000, 1.00000, 0.00010, -0.07700])
        whitepoint = np.array([0.32168, 0.33767])
        RGB_to_XYZ_matrix = np.identity(3)
        XYZ_to_RGB_matrix = np.identity(3)
        colourspace = RGB_Colourspace('RGB Colourspace', p, whitepoint, 'D60',
                                      RGB_to_XYZ_matrix, XYZ_to_RGB_matrix)

        np.testing.assert_array_equal(colourspace.RGB_to_XYZ_matrix,
                                      np.identity(3))
        np.testing.assert_array_equal(colourspace.XYZ_to_RGB_matrix,
                                      np.identity(3))

        self.assertTrue(colourspace.use_derived_transformation_matrices())

        np.testing.assert_almost_equal(
            colourspace.RGB_to_XYZ_matrix,
            np.array(
                [[0.95255240, 0.00000000, 0.00009368],
                 [0.34396645, 0.72816610, -0.07213255],
                 [0.00000000, 0.00000000, 1.00882518]]),
            decimal=7)  # yapf: disable
        np.testing.assert_almost_equal(
            colourspace.XYZ_to_RGB_matrix,
            np.array(
                [[1.04981102, 0.00000000, -0.00009748],
                 [-0.49590302, 1.37331305, 0.09824004],
                 [0.00000000, 0.00000000, 0.99125202]]),
            decimal=7)  # yapf: disable

        colourspace.use_derived_RGB_to_XYZ_matrix = False
        np.testing.assert_array_equal(colourspace.RGB_to_XYZ_matrix,
                                      np.identity(3))
        colourspace.use_derived_XYZ_to_RGB_matrix = False
        np.testing.assert_array_equal(colourspace.XYZ_to_RGB_matrix,
                                      np.identity(3))
예제 #2
0
class TestRGB_Colourspace(unittest.TestCase):
    """
    Defines :class:`colour.colour.models.RGB_Colourspace` class units
    tests methods.
    """
    def setUp(self):
        """
        Initialises common tests attributes.
        """

        p = np.array([0.73470, 0.26530, 0.00000, 1.00000, 0.00010, -0.07700])
        whitepoint = np.array([0.32168, 0.33767])
        matrix_RGB_to_XYZ = np.identity(3)
        matrix_XYZ_to_RGB = np.identity(3)
        self._colourspace = RGB_Colourspace('RGB Colourspace', p, whitepoint,
                                            'ACES', matrix_RGB_to_XYZ,
                                            matrix_XYZ_to_RGB, lambda x: x,
                                            lambda x: x)

    def test_required_attributes(self):
        """
        Tests presence of required attributes.
        """

        required_attributes = ('name', 'primaries', 'whitepoint',
                               'whitepoint_name', 'matrix_RGB_to_XYZ',
                               'matrix_XYZ_to_RGB', 'cctf_encoding',
                               'cctf_decoding',
                               'use_derived_matrix_RGB_to_XYZ',
                               'use_derived_matrix_XYZ_to_RGB')

        for attribute in required_attributes:
            self.assertIn(attribute, dir(RGB_Colourspace))

    def test_required_methods(self):
        """
        Tests presence of required methods.
        """

        required_methods = ('__init__', '__str__', '__repr__',
                            'use_derived_transformation_matrices',
                            'chromatically_adapt', 'copy')

        for method in required_methods:
            self.assertIn(method, dir(RGB_Colourspace))

    def test__str__(self):
        """
        Tests :func:`colour.models.rgb.rgb_colourspace.RGB_Colourspace.__str__`
        method.
        """

        # Skipping unit test on Python 2.7.
        if six.PY2:  # pragma: no cover
            return

        self.assertEqual(
            re.sub(' at 0x\\w+>', '', str(self._colourspace)),
            textwrap.dedent("""
    RGB Colourspace
    ---------------

    Primaries          : [[  7.34700000e-01   2.65300000e-01]
                          [  0.00000000e+00   1.00000000e+00]
                          [  1.00000000e-04  -7.70000000e-02]]
    Whitepoint         : [ 0.32168  0.33767]
    Whitepoint Name    : ACES
    Encoding CCTF      : <function TestRGB_Colourspace.setUp.<locals>.<lambda>
    Decoding CCTF      : <function TestRGB_Colourspace.setUp.<locals>.<lambda>
    NPM                : [[ 1.  0.  0.]
                          [ 0.  1.  0.]
                          [ 0.  0.  1.]]
    NPM -1             : [[ 1.  0.  0.]
                          [ 0.  1.  0.]
                          [ 0.  0.  1.]]
    Derived NPM        : [[  9.52552396e-01   0.00000000e+00   9.36786317e-05]
                          [  3.43966450e-01   7.28166097e-01  -7.21325464e-02]
                          [  0.00000000e+00   0.00000000e+00   1.00882518e+00]]
    Derived NPM -1     : [[  1.04981102e+00   0.00000000e+00  -9.74845406e-05]
                          [ -4.95903023e-01   1.37331305e+00   9.82400361e-02]
                          [  0.00000000e+00   0.00000000e+00   9.91252018e-01]]
    Use Derived NPM    : False
    Use Derived NPM -1 : False""")[1:])

    def test__repr__(self):
        """
        Tests :func:`colour.models.rgb.rgb_colourspace.RGB_Colourspace.\
__repr__` method.
        """

        # Skipping unit test on Python 2.7.
        if six.PY2:  # pragma: no cover
            return

        self.assertEqual(
            re.sub(' at 0x\\w+>', '', repr(self._colourspace)),
            textwrap.dedent("""
        RGB_Colourspace(RGB Colourspace,
                        [[  7.34700000e-01,   2.65300000e-01],
                         [  0.00000000e+00,   1.00000000e+00],
                         [  1.00000000e-04,  -7.70000000e-02]],
                        [ 0.32168,  0.33767],
                        ACES,
                        [[ 1.,  0.,  0.],
                         [ 0.,  1.,  0.],
                         [ 0.,  0.,  1.]],
                        [[ 1.,  0.,  0.],
                         [ 0.,  1.,  0.],
                         [ 0.,  0.,  1.]],
                        <function TestRGB_Colourspace.setUp.<locals>.<lambda>,
                        <function TestRGB_Colourspace.setUp.<locals>.<lambda>,
                        False,
                        False)""")[1:])

    def test_use_derived_transformation_matrices(self):
        """
        Tests :func:`colour.models.rgb.rgb_colourspace.RGB_Colourspace.\
use_derived_transformation_matrices` method.
        """

        np.testing.assert_array_equal(self._colourspace.matrix_RGB_to_XYZ,
                                      np.identity(3))
        np.testing.assert_array_equal(self._colourspace.matrix_XYZ_to_RGB,
                                      np.identity(3))

        self.assertTrue(
            self._colourspace.use_derived_transformation_matrices())

        np.testing.assert_almost_equal(
            self._colourspace.matrix_RGB_to_XYZ,
            np.array([
                [0.95255240, 0.00000000, 0.00009368],
                [0.34396645, 0.72816610, -0.07213255],
                [0.00000000, 0.00000000, 1.00882518],
            ]),
            decimal=7)
        np.testing.assert_almost_equal(
            self._colourspace.matrix_XYZ_to_RGB,
            np.array([
                [1.04981102, 0.00000000, -0.00009748],
                [-0.49590302, 1.37331305, 0.09824004],
                [0.00000000, 0.00000000, 0.99125202],
            ]),
            decimal=7)

        self._colourspace.use_derived_matrix_RGB_to_XYZ = False
        np.testing.assert_array_equal(self._colourspace.matrix_RGB_to_XYZ,
                                      np.identity(3))
        self._colourspace.use_derived_matrix_XYZ_to_RGB = False
        np.testing.assert_array_equal(self._colourspace.matrix_XYZ_to_RGB,
                                      np.identity(3))

    def test_chromatically_adapt(self):
        """
        Tests :func:`colour.models.rgb.rgb_colourspace.RGB_Colourspace.\
chromatically_adapt` method.
        """

        whitepoint_t = np.array([0.31270, 0.32900])
        colourspace = self._colourspace.chromatically_adapt(
            whitepoint_t, 'D50', 'Bradford')

        np.testing.assert_array_almost_equal(colourspace.primaries,
                                             np.array([
                                                 [0.73485524, 0.26422533],
                                                 [-0.00617091, 1.01131496],
                                                 [0.01596756, -0.06423550],
                                             ]),
                                             decimal=7)
        np.testing.assert_array_almost_equal(colourspace.whitepoint,
                                             whitepoint_t,
                                             decimal=7)

        self.assertEqual(colourspace.whitepoint_name, 'D50')

        np.testing.assert_array_almost_equal(colourspace.primaries,
                                             chromatically_adapted_primaries(
                                                 self._colourspace.primaries,
                                                 self._colourspace.whitepoint,
                                                 whitepoint_t, 'Bradford'),
                                             decimal=7)

        np.testing.assert_array_almost_equal(colourspace.matrix_RGB_to_XYZ,
                                             normalised_primary_matrix(
                                                 colourspace.primaries,
                                                 colourspace.whitepoint),
                                             decimal=7)

        np.testing.assert_array_almost_equal(colourspace.matrix_XYZ_to_RGB,
                                             np.linalg.inv(
                                                 normalised_primary_matrix(
                                                     colourspace.primaries,
                                                     colourspace.whitepoint)),
                                             decimal=7)

    def test_copy(self):
        """
        Tests :func:`colour.models.rgb.rgb_colourspace.RGB_Colourspace.copy`
        method.
        """

        self.assertIsNot(self._colourspace.copy(), self)
예제 #3
0
class TestRGB_Colourspace(unittest.TestCase):
    """
    Defines :class:`colour.colour.models.RGB_Colourspace` class units
    tests methods.
    """

    def setUp(self):
        """
        Initialises common tests attributes.
        """

        p = np.array([0.73470, 0.26530, 0.00000, 1.00000, 0.00010, -0.07700])
        whitepoint = np.array([0.32168, 0.33767])
        RGB_to_XYZ_matrix = np.identity(3)
        XYZ_to_RGB_matrix = np.identity(3)
        self._colourspace = RGB_Colourspace(
            'RGB Colourspace', p, whitepoint, 'D60', RGB_to_XYZ_matrix,
            XYZ_to_RGB_matrix, lambda x: x, lambda x: x)

    def test_required_attributes(self):
        """
        Tests presence of required attributes.
        """

        required_attributes = ('name', 'primaries', 'whitepoint', 'illuminant',
                               'RGB_to_XYZ_matrix', 'XYZ_to_RGB_matrix',
                               'encoding_cctf', 'decoding_cctf',
                               'use_derived_RGB_to_XYZ_matrix',
                               'use_derived_XYZ_to_RGB_matrix')

        for attribute in required_attributes:
            self.assertIn(attribute, dir(RGB_Colourspace))

    def test_required_methods(self):
        """
        Tests presence of required methods.
        """

        required_methods = ('__str__', '__repr__',
                            'use_derived_transformation_matrices')

        for method in required_methods:
            self.assertIn(method, dir(RGB_Colourspace))

    def test__str__(self):
        """
        Tests :func:`colour.models.rgb.rgb_colourspace.RGB_Colourspace.__str__`
        method.
        """

        # Skipping unit test on Python 2.7.
        if six.PY2:
            return

        self.assertEqual(
            re.sub(' at 0x\w+>', '', str(self._colourspace)),
            textwrap.dedent("""
    RGB Colourspace
    ---------------

    Primaries          : [[  7.34700000e-01   2.65300000e-01]
                          [  0.00000000e+00   1.00000000e+00]
                          [  1.00000000e-04  -7.70000000e-02]]
    Whitepoint         : [ 0.32168  0.33767]
    Whitepoint Name    : D60
    Encoding CCTF      : <function TestRGB_Colourspace.setUp.<locals>.<lambda>
    Decoding CCTF      : <function TestRGB_Colourspace.setUp.<locals>.<lambda>
    NPM                : [[ 1.  0.  0.]
                          [ 0.  1.  0.]
                          [ 0.  0.  1.]]
    NPM -1             : [[ 1.  0.  0.]
                          [ 0.  1.  0.]
                          [ 0.  0.  1.]]
    Derived NPM        : [[  9.52552396e-01   0.00000000e+00   9.36786317e-05]
                          [  3.43966450e-01   7.28166097e-01  -7.21325464e-02]
                          [  0.00000000e+00   0.00000000e+00   1.00882518e+00]]
    Derived NPM -1     : [[  1.04981102e+00   0.00000000e+00  -9.74845406e-05]
                          [ -4.95903023e-01   1.37331305e+00   9.82400361e-02]
                          [  0.00000000e+00   0.00000000e+00   9.91252018e-01]]
    Use Derived NPM    : False
    Use Derived NPM -1 : False""")[1:])

    def test__repr__(self):
        """
        Tests :func:`colour.models.rgb.rgb_colourspace.RGB_Colourspace.\
__repr__` method.
        """

        # Skipping unit test on Python 2.7.
        if six.PY2:
            return

        self.assertEqual(
            re.sub(' at 0x\w+>', '', repr(self._colourspace)),
            textwrap.dedent("""
        RGB_Colourspace(RGB Colourspace,
                        [[  7.34700000e-01,   2.65300000e-01],
                         [  0.00000000e+00,   1.00000000e+00],
                         [  1.00000000e-04,  -7.70000000e-02]],
                        [ 0.32168,  0.33767],
                        D60,
                        [[ 1.,  0.,  0.],
                         [ 0.,  1.,  0.],
                         [ 0.,  0.,  1.]],
                        [[ 1.,  0.,  0.],
                         [ 0.,  1.,  0.],
                         [ 0.,  0.,  1.]],
                        <function TestRGB_Colourspace.setUp.<locals>.<lambda>,
                        <function TestRGB_Colourspace.setUp.<locals>.<lambda>,
                        False,
                        False)""")[1:])

    def test_use_derived_transformation_matrices(self):
        """
        Tests :func:`colour.models.rgb.rgb_colourspace.RGB_Colourspace.range.\
use_derived_transformation_matrices` method.
        """

        np.testing.assert_array_equal(self._colourspace.RGB_to_XYZ_matrix,
                                      np.identity(3))
        np.testing.assert_array_equal(self._colourspace.XYZ_to_RGB_matrix,
                                      np.identity(3))

        self.assertTrue(
            self._colourspace.use_derived_transformation_matrices())

        np.testing.assert_almost_equal(
            self._colourspace.RGB_to_XYZ_matrix,
            np.array([
                [0.95255240, 0.00000000, 0.00009368],
                [0.34396645, 0.72816610, -0.07213255],
                [0.00000000, 0.00000000, 1.00882518],
            ]),
            decimal=7)
        np.testing.assert_almost_equal(
            self._colourspace.XYZ_to_RGB_matrix,
            np.array([
                [1.04981102, 0.00000000, -0.00009748],
                [-0.49590302, 1.37331305, 0.09824004],
                [0.00000000, 0.00000000, 0.99125202],
            ]),
            decimal=7)

        self._colourspace.use_derived_RGB_to_XYZ_matrix = False
        np.testing.assert_array_equal(self._colourspace.RGB_to_XYZ_matrix,
                                      np.identity(3))
        self._colourspace.use_derived_XYZ_to_RGB_matrix = False
        np.testing.assert_array_equal(self._colourspace.XYZ_to_RGB_matrix,
                                      np.identity(3))
예제 #4
0
class TestRGB_Colourspace(unittest.TestCase):
    """
    Defines :class:`colour.colour.models.RGB_Colourspace` class units
    tests methods.
    """

    def setUp(self):
        """
        Initialises common tests attributes.
        """

        p = np.array([0.73470, 0.26530, 0.00000, 1.00000, 0.00010, -0.07700])
        whitepoint = np.array([0.32168, 0.33767])
        RGB_to_XYZ_matrix = np.identity(3)
        XYZ_to_RGB_matrix = np.identity(3)
        self._colourspace = RGB_Colourspace(
            'RGB Colourspace', p, whitepoint, 'ACES', RGB_to_XYZ_matrix,
            XYZ_to_RGB_matrix, lambda x: x, lambda x: x)

    def test_required_attributes(self):
        """
        Tests presence of required attributes.
        """

        required_attributes = ('name', 'primaries', 'whitepoint',
                               'whitepoint_name', 'RGB_to_XYZ_matrix',
                               'XYZ_to_RGB_matrix', 'encoding_cctf',
                               'decoding_cctf',
                               'use_derived_RGB_to_XYZ_matrix',
                               'use_derived_XYZ_to_RGB_matrix')

        for attribute in required_attributes:
            self.assertIn(attribute, dir(RGB_Colourspace))

    def test_required_methods(self):
        """
        Tests presence of required methods.
        """

        required_methods = ('__str__', '__repr__',
                            'use_derived_transformation_matrices',
                            'chromatically_adapt', 'copy')

        for method in required_methods:
            self.assertIn(method, dir(RGB_Colourspace))

    def test__str__(self):
        """
        Tests :func:`colour.models.rgb.rgb_colourspace.RGB_Colourspace.__str__`
        method.
        """

        # Skipping unit test on Python 2.7.
        if six.PY2:
            return

        self.assertEqual(
            re.sub(' at 0x\\w+>', '', str(self._colourspace)),
            textwrap.dedent("""
    RGB Colourspace
    ---------------

    Primaries          : [[  7.34700000e-01   2.65300000e-01]
                          [  0.00000000e+00   1.00000000e+00]
                          [  1.00000000e-04  -7.70000000e-02]]
    Whitepoint         : [ 0.32168  0.33767]
    Whitepoint Name    : ACES
    Encoding CCTF      : <function TestRGB_Colourspace.setUp.<locals>.<lambda>
    Decoding CCTF      : <function TestRGB_Colourspace.setUp.<locals>.<lambda>
    NPM                : [[ 1.  0.  0.]
                          [ 0.  1.  0.]
                          [ 0.  0.  1.]]
    NPM -1             : [[ 1.  0.  0.]
                          [ 0.  1.  0.]
                          [ 0.  0.  1.]]
    Derived NPM        : [[  9.52552396e-01   0.00000000e+00   9.36786317e-05]
                          [  3.43966450e-01   7.28166097e-01  -7.21325464e-02]
                          [  0.00000000e+00   0.00000000e+00   1.00882518e+00]]
    Derived NPM -1     : [[  1.04981102e+00   0.00000000e+00  -9.74845406e-05]
                          [ -4.95903023e-01   1.37331305e+00   9.82400361e-02]
                          [  0.00000000e+00   0.00000000e+00   9.91252018e-01]]
    Use Derived NPM    : False
    Use Derived NPM -1 : False""")[1:])

    def test__repr__(self):
        """
        Tests :func:`colour.models.rgb.rgb_colourspace.RGB_Colourspace.\
__repr__` method.
        """

        # Skipping unit test on Python 2.7.
        if six.PY2:
            return

        self.assertEqual(
            re.sub(' at 0x\\w+>', '', repr(self._colourspace)),
            textwrap.dedent("""
        RGB_Colourspace(RGB Colourspace,
                        [[  7.34700000e-01,   2.65300000e-01],
                         [  0.00000000e+00,   1.00000000e+00],
                         [  1.00000000e-04,  -7.70000000e-02]],
                        [ 0.32168,  0.33767],
                        ACES,
                        [[ 1.,  0.,  0.],
                         [ 0.,  1.,  0.],
                         [ 0.,  0.,  1.]],
                        [[ 1.,  0.,  0.],
                         [ 0.,  1.,  0.],
                         [ 0.,  0.,  1.]],
                        <function TestRGB_Colourspace.setUp.<locals>.<lambda>,
                        <function TestRGB_Colourspace.setUp.<locals>.<lambda>,
                        False,
                        False)""")[1:])

    def test_use_derived_transformation_matrices(self):
        """
        Tests :func:`colour.models.rgb.rgb_colourspace.RGB_Colourspace.\
use_derived_transformation_matrices` method.
        """

        np.testing.assert_array_equal(self._colourspace.RGB_to_XYZ_matrix,
                                      np.identity(3))
        np.testing.assert_array_equal(self._colourspace.XYZ_to_RGB_matrix,
                                      np.identity(3))

        self.assertTrue(
            self._colourspace.use_derived_transformation_matrices())

        np.testing.assert_almost_equal(
            self._colourspace.RGB_to_XYZ_matrix,
            np.array([
                [0.95255240, 0.00000000, 0.00009368],
                [0.34396645, 0.72816610, -0.07213255],
                [0.00000000, 0.00000000, 1.00882518],
            ]),
            decimal=7)
        np.testing.assert_almost_equal(
            self._colourspace.XYZ_to_RGB_matrix,
            np.array([
                [1.04981102, 0.00000000, -0.00009748],
                [-0.49590302, 1.37331305, 0.09824004],
                [0.00000000, 0.00000000, 0.99125202],
            ]),
            decimal=7)

        self._colourspace.use_derived_RGB_to_XYZ_matrix = False
        np.testing.assert_array_equal(self._colourspace.RGB_to_XYZ_matrix,
                                      np.identity(3))
        self._colourspace.use_derived_XYZ_to_RGB_matrix = False
        np.testing.assert_array_equal(self._colourspace.XYZ_to_RGB_matrix,
                                      np.identity(3))

    def test_chromatically_adapt(self):
        """
        Tests :func:`colour.models.rgb.rgb_colourspace.RGB_Colourspace.\
chromatically_adapt` method.
        """

        whitepoint_t = np.array([0.31270, 0.32900])
        colourspace = self._colourspace.chromatically_adapt(
            whitepoint_t, 'D50', 'Bradford')

        np.testing.assert_array_almost_equal(
            colourspace.primaries,
            np.array([
                [0.73485524, 0.26422533],
                [-0.00617091, 1.01131496],
                [0.01596756, -0.06423550],
            ]),
            decimal=7)
        np.testing.assert_array_almost_equal(
            colourspace.whitepoint, whitepoint_t, decimal=7)

        self.assertEqual(colourspace.whitepoint_name, 'D50')

        np.testing.assert_array_almost_equal(
            colourspace.primaries,
            chromatically_adapted_primaries(self._colourspace.primaries,
                                            self._colourspace.whitepoint,
                                            whitepoint_t, 'Bradford'),
            decimal=7)

        np.testing.assert_array_almost_equal(
            colourspace.RGB_to_XYZ_matrix,
            normalised_primary_matrix(colourspace.primaries,
                                      colourspace.whitepoint),
            decimal=7)

        np.testing.assert_array_almost_equal(
            colourspace.XYZ_to_RGB_matrix,
            np.linalg.inv(
                normalised_primary_matrix(colourspace.primaries,
                                          colourspace.whitepoint)),
            decimal=7)

    def test_copy(self):
        """
        Tests :func:`colour.models.rgb.rgb_colourspace.RGB_Colourspace.copy`
        method.
        """

        self.assertIsNot(self._colourspace.copy(), self)