def test_application(self): im = Image.new('RGB', (10, 10)) lut_numpy = resize_lut(identity_table(5), 4) self.assertEqual(lut_numpy.table.__class__.__name__, 'ndarray') im.filter(lut_numpy) with disable_numpy(operations): lut_native = resize_lut(identity_table(5), 4) self.assertEqual(lut_native.table.__class__.__name__, 'list') im.filter(lut_native) with disable_numpy(generators): args = identity_table(5) self.assertEqual(args.table.__class__.__name__, 'list') lut_numpy = resize_lut(args, 4) self.assertEqual(lut_numpy.table.__class__.__name__, 'ndarray') im.filter(lut_numpy) args = identity_table(5) self.assertEqual(args.table.__class__.__name__, 'ndarray') with disable_numpy(operations): lut_native = resize_lut(args, 4) self.assertEqual(lut_native.table.__class__.__name__, 'list') im.filter(lut_native)
def test_correctness_linear(self): res_numpy = resize_lut(self.lut9_in, 7) self.assertAlmostEqualLuts(res_numpy, self.lut7_in, 6) with disable_numpy(operations): res_native = resize_lut(self.lut9_in, 7) self.assertAlmostEqualLuts(res_native, res_numpy)
def test_correct_args(self): result = resize_lut(identity_table((3, 4, 5), target_mode='RGB'), (6, 7, 8)) self.assertEqual(tuple(result.size), (6, 7, 8)) self.assertEqual(result.mode, 'RGB') self.assertEqual(result.channels, 3) result = resize_lut(self.lut5_4c, 3) self.assertEqual(tuple(result.size), (3, 3, 3)) self.assertEqual(result.mode, None) self.assertEqual(result.channels, 4) with disable_numpy(operations): result = resize_lut(self.lut5_4c, 3) self.assertEqual(tuple(result.size), (3, 3, 3)) self.assertEqual(result.mode, None) self.assertEqual(result.channels, 4)
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 = resize_lut(lut4, (5, 5, 3), interp=Image.CUBIC) self.assertEqual(len(w), 0) linear = resize_lut(lut4, (5, 5, 3)) self.assertNotEqualLutTables(cubic, linear) with warnings.catch_warnings(record=True) as w: cubic = resize_lut(lut3, (5, 5, 4), interp=Image.CUBIC) self.assertEqual(len(w), 1) self.assertIn('Cubic interpolation', "{}".format(w[0].message)) linear = resize_lut(lut3, (5, 5, 4)) self.assertEqualLuts(cubic, linear)
def test_correctness_cubic(self): result = resize_lut(self.lut9_in, 7, interp=Image.CUBIC) self.assertAlmostEqualLuts(result, self.lut7_in, 7)
def test_wrong_args(self): with self.assertRaisesRegexp(ValueError, "interpolations"): result = resize_lut(identity_table(4), 5, interp=Image.NEAREST)