Beispiel #1
0
    def test_n_dimensional_RGB_to_YCbCr(self):
        """
        Tests :func:`colour.models.rgb.ycbcr.RGB_to_YCbCr` definition
        n-dimensional arrays support.
        """

        RGB = np.array([0.75, 0.5, 0.25])
        YCbCr = RGB_to_YCbCr(RGB)

        RGB = np.tile(RGB, 4)
        RGB = np.reshape(RGB, (4, 3))
        YCbCr = np.tile(YCbCr, 4)
        YCbCr = np.reshape(YCbCr, (4, 3))
        np.testing.assert_almost_equal(RGB_to_YCbCr(RGB), YCbCr)

        RGB = np.tile(RGB, 4)
        RGB = np.reshape(RGB, (4, 4, 3))
        YCbCr = np.tile(YCbCr, 4)
        YCbCr = np.reshape(YCbCr, (4, 4, 3))
        np.testing.assert_almost_equal(RGB_to_YCbCr(RGB), YCbCr)

        RGB = np.tile(RGB, 4)
        RGB = np.reshape(RGB, (4, 4, 4, 3))
        YCbCr = np.tile(YCbCr, 4)
        YCbCr = np.reshape(YCbCr, (4, 4, 4, 3))
        np.testing.assert_almost_equal(RGB_to_YCbCr(RGB), YCbCr)
Beispiel #2
0
    def test_RGB_to_YCbCr(self):
        """
        Tests :func:`colour.models.rgb.ycbcr.RGB_to_YCbCr` definition.
        """

        np.testing.assert_almost_equal(
            RGB_to_YCbCr(np.array([0.75, 0.75, 0.0])),
            np.array([0.66035745, 0.17254902, 0.53216593]),
            decimal=7)

        np.testing.assert_almost_equal(RGB_to_YCbCr(
            np.array([0.25, 0.5, 0.75]),
            K=WEIGHTS_YCBCR['ITU-R BT.601'],
            out_int=True,
            out_legal=True,
            out_bits=10),
                                       np.array([461, 662, 382]),
                                       decimal=7)

        np.testing.assert_almost_equal(
            RGB_to_YCbCr(np.array([0.0, 0.75, 0.75]),
                         K=WEIGHTS_YCBCR['ITU-R BT.2020'],
                         out_int=False,
                         out_legal=False),
            np.array([0.55297500, 0.10472255, -0.37500000]),
            decimal=7)

        np.testing.assert_almost_equal(
            RGB_to_YCbCr(np.array([0.75, 0.0, 0.75]),
                         K=WEIGHTS_YCBCR['ITU-R BT.709'],
                         out_range=(16 / 255, 235 / 255, 15.5 / 255,
                                    239.5 / 255)),
            np.array([0.24618980, 0.75392897, 0.79920662]),
            decimal=7)
Beispiel #3
0
    def test_domain_range_scale_RGB_to_YCbCr(self):
        """
        Tests :func:`colour.models.rgb.prismatic.RGB_to_YCbCr` definition
        domain and range scale support.
        """

        RGB = np.array([0.75, 0.5, 0.25])
        YCbCr = RGB_to_YCbCr(RGB)

        d_r = (('reference', 1), (1, 1), (100, 100))
        for scale, factor in d_r:
            with domain_range_scale(scale):
                np.testing.assert_almost_equal(
                    RGB_to_YCbCr(RGB * factor), YCbCr * factor, decimal=7)
Beispiel #4
0
    def test_nan_RGB_to_YCbCr(self):
        """
        Tests :func:`colour.models.rgb.ycbcr.RGB_to_YCbCr` 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:
            RGB = np.array(case)
            RGB_to_YCbCr(RGB)