Esempio n. 1
0
    def test_application(self):
        im = Image.new('RGB', (10, 10))

        lut_numpy = transform_lut(identity_table(5), identity_table(5))
        self.assertEqual(lut_numpy.table.__class__.__name__, 'ndarray')
        im.filter(lut_numpy)

        with disable_numpy(operations):
            lut_native = transform_lut(identity_table(5), identity_table(5))
        self.assertEqual(lut_native.table.__class__.__name__, 'list')
        im.filter(lut_native)

        with disable_numpy(generators):
            args = identity_table(5), identity_table(5)
        self.assertEqual(args[0].table.__class__.__name__, 'list')
        lut_numpy = transform_lut(*args)
        self.assertEqual(lut_numpy.table.__class__.__name__, 'ndarray')
        im.filter(lut_numpy)

        args = identity_table(5), identity_table(5)
        self.assertEqual(args[0].table.__class__.__name__, 'ndarray')
        with disable_numpy(operations):
            lut_native = transform_lut(*args)
        self.assertEqual(lut_native.table.__class__.__name__, 'list')
        im.filter(lut_native)
Esempio n. 2
0
    def test_correct_args(self):
        result = transform_lut(identity_table((3, 4, 5), target_mode='RGB'),
                               identity_table((6, 7, 8), target_mode='HSV'))
        self.assertEqual(tuple(result.size), (3, 4, 5))
        self.assertEqual(result.mode, 'HSV')
        self.assertEqual(result.channels, 3)

        result = transform_lut(identity_table(3), self.lut5_4c)
        self.assertEqual(tuple(result.size), (3, 3, 3))
        self.assertEqual(result.mode, None)
        self.assertEqual(result.channels, 4)

        with disable_numpy(operations):
            result = transform_lut(identity_table(3), self.lut5_4c)
        self.assertEqual(tuple(result.size), (3, 3, 3))
        self.assertEqual(result.mode, None)
        self.assertEqual(result.channels, 4)

        result = transform_lut(identity_table(4, target_mode='RGB'),
                               identity_table(5),
                               target_size=(6, 7, 8))
        self.assertEqual(tuple(result.size), (6, 7, 8))
        self.assertEqual(result.mode, 'RGB')
        self.assertEqual(result.channels, 3)

        with disable_numpy(operations):
            result = transform_lut(identity_table(4, target_mode='RGB'),
                                   identity_table(5),
                                   target_size=(6, 7, 8))
        self.assertEqual(tuple(result.size), (6, 7, 8))
        self.assertEqual(result.mode, 'RGB')
        self.assertEqual(result.channels, 3)
Esempio n. 3
0
    def test_target_size_correctness_linear(self):
        res_numpy = transform_lut(self.lut7_out, self.lut7_in, target_size=9)
        self.assertAlmostEqualLuts(res_numpy, self.identity9, 4)

        with disable_numpy(operations):
            res_native = transform_lut(self.lut7_out,
                                       self.lut7_in,
                                       target_size=9)
        self.assertAlmostEqualLuts(res_native, res_numpy)
Esempio n. 4
0
    def test_identity_cubic(self):
        result = transform_lut(self.lut7_in,
                               self.identity9,
                               interp=Image.CUBIC)
        self.assertAlmostEqualLuts(result, self.lut7_in)

        result = transform_lut(self.identity7,
                               self.lut9_in,
                               interp=Image.CUBIC)
        self.assertAlmostEqualLuts(result, self.lut7_in, 7)
Esempio n. 5
0
    def test_wrong_args(self):
        with self.assertRaisesRegexp(ValueError, "only 3-channel cubes"):
            result = transform_lut(self.lut5_4c, identity_table(3))

        with self.assertRaisesRegexp(ValueError, "only 3-channel cubes"):
            result = transform_lut(self.lut5_4c,
                                   identity_table(3),
                                   target_size=5)

        with self.assertRaisesRegexp(ValueError, "interpolations"):
            result = transform_lut(identity_table(4),
                                   identity_table(4),
                                   interp=Image.NEAREST)
Esempio n. 6
0
    def test_correctness_linear(self):
        res_numpy = transform_lut(self.lut7_in, self.lut7_out)
        self.assertAlmostEqualLuts(res_numpy, self.identity7, 4)

        with disable_numpy(operations):
            res_native = transform_lut(self.lut7_in, self.lut7_out)
        self.assertAlmostEqualLuts(res_native, res_numpy)

        res_numpy = transform_lut(self.lut7_out, self.lut7_in)
        self.assertAlmostEqualLuts(res_numpy, self.identity7, 6)

        with disable_numpy(operations):
            res_native = transform_lut(self.lut7_out, self.lut7_in)
        self.assertAlmostEqualLuts(res_native, res_numpy)
Esempio n. 7
0
    def test_identity_linear(self):
        res_numpy = transform_lut(self.lut7_in, self.identity9)
        self.assertAlmostEqualLuts(res_numpy, self.lut7_in)

        with disable_numpy(operations):
            res_native = transform_lut(self.lut7_in, self.identity9)
        self.assertAlmostEqualLuts(res_native, res_numpy)

        res_numpy = transform_lut(self.identity9, self.lut7_in)
        self.assertAlmostEqualLuts(res_numpy, self.lut9_in, 4)

        with disable_numpy(operations):
            res_native = transform_lut(self.identity9, self.lut7_in)
        self.assertAlmostEqualLuts(res_native, res_numpy)
Esempio n. 8
0
    def test_fallback_to_linear(self):
        lut3 = ImageFilter.Color3DLUT.generate((5, 5, 3), lambda r, g, b:
                                               (r**1.5, g**1.5, b**1.5))
        lut4 = ImageFilter.Color3DLUT.generate((5, 5, 4), lambda r, g, b:
                                               (r**1.5, g**1.5, b**1.5))

        with warnings.catch_warnings(record=True) as w:
            cubic = transform_lut(identity_table((5, 5, 3)),
                                  lut4,
                                  interp=Image.CUBIC)
            self.assertEqual(len(w), 0)
        linear = transform_lut(identity_table((5, 5, 3)), lut4)
        self.assertNotEqualLutTables(cubic, linear)

        with warnings.catch_warnings(record=True) as w:
            cubic = transform_lut(identity_table((5, 5, 4)),
                                  lut3,
                                  interp=Image.CUBIC)
            self.assertEqual(len(w), 1)
            self.assertIn('Cubic interpolation', "{}".format(w[0].message))
        linear = transform_lut(identity_table((5, 5, 4)), lut3)
        self.assertEqualLuts(cubic, linear)

        with warnings.catch_warnings(record=True) as w:
            cubic = transform_lut(identity_table((5, 5, 3)),
                                  lut4,
                                  target_size=(5, 5, 4),
                                  interp=Image.CUBIC)
            self.assertEqual(len(w), 1)
            self.assertIn('Cubic interpolation', "{}".format(w[0].message))
        linear = transform_lut(identity_table((5, 5, 3)),
                               lut4,
                               target_size=(5, 5, 4))
        self.assertEqualLuts(cubic, linear)
Esempio n. 9
0
 def test_target_size_correctness_cubic(self):
     result = transform_lut(self.lut7_out,
                            self.lut7_in,
                            target_size=9,
                            interp=Image.CUBIC)
     self.assertAlmostEqualLuts(result, self.identity9, 4)
Esempio n. 10
0
    def test_correctness_cubic(self):
        result = transform_lut(self.lut7_in, self.lut7_out, interp=Image.CUBIC)
        self.assertAlmostEqualLuts(result, self.identity7, 4)

        result = transform_lut(self.lut7_out, self.lut7_in, interp=Image.CUBIC)
        self.assertAlmostEqualLuts(result, self.identity7, 7)