diff --git a/PIL/ImageMorph.py b/PIL/ImageMorph.py index dcce63fa4..d2367737f 100644 --- a/PIL/ImageMorph.py +++ b/PIL/ImageMorph.py @@ -123,7 +123,7 @@ class LutBuilder(object): .replace('0', 'Z') .replace('1', '0') .replace('Z', '1')) - res = '%d' % (1-int(res)) + res = 1-int(res) patterns.append((pattern, res)) return patterns @@ -152,8 +152,8 @@ class LutBuilder(object): patterns += self._pattern_permute(pattern, options, result) # # Debugging -# for p,r in patterns: -# print(p,r) +# for p, r in patterns: +# print(p, r) # print('--') # compile the patterns into regular expressions for speed diff --git a/Tests/test_imagemorph.py b/Tests/test_imagemorph.py index c0f6448e6..dac1ae150 100644 --- a/Tests/test_imagemorph.py +++ b/Tests/test_imagemorph.py @@ -184,7 +184,6 @@ class MorphTests(PillowTestCase): self.assertEqual(count, 7) self.assert_img_equal_img_string(Aout, """ - ....... ....... ..1.1.. @@ -194,6 +193,23 @@ class MorphTests(PillowTestCase): ....... """) + def test_negate(self): + # Test 'N' for negate + mop = ImageMorph.MorphOp(patterns=['1:(... ... ...)->0', + 'N:(00. 01. ...)->1']) + count, Aout = mop.apply(self.A) + self.assertEqual(count, 8) + self.assert_img_equal_img_string(Aout, + """ + ....... + ....... + ..1.... + ....... + ....... + ....... + ....... + """) + def test_non_binary_images(self): im = hopper('RGB') mop = ImageMorph.MorphOp(op_name="erosion8")