mirror of
https://github.com/python-pillow/Pillow.git
synced 2024-12-24 17:06:16 +03:00
Check that images are L mode in ImageMorph methods
This commit is contained in:
parent
bbc6f7d6bb
commit
9026b81439
|
@ -198,6 +198,9 @@ class MorphOp(object):
|
||||||
if self.lut is None:
|
if self.lut is None:
|
||||||
raise Exception('No operator loaded')
|
raise Exception('No operator loaded')
|
||||||
|
|
||||||
|
if image.mode != 'L':
|
||||||
|
raise Exception('Image must be binary, meaning it must use mode L')
|
||||||
|
return
|
||||||
outimage = Image.new(image.mode, image.size, None)
|
outimage = Image.new(image.mode, image.size, None)
|
||||||
count = _imagingmorph.apply(
|
count = _imagingmorph.apply(
|
||||||
bytes(self.lut), image.im.id, outimage.im.id)
|
bytes(self.lut), image.im.id, outimage.im.id)
|
||||||
|
@ -212,6 +215,9 @@ class MorphOp(object):
|
||||||
if self.lut is None:
|
if self.lut is None:
|
||||||
raise Exception('No operator loaded')
|
raise Exception('No operator loaded')
|
||||||
|
|
||||||
|
if image.mode != 'L':
|
||||||
|
raise Exception('Image must be binary, meaning it must use mode L')
|
||||||
|
return
|
||||||
return _imagingmorph.match(bytes(self.lut), image.im.id)
|
return _imagingmorph.match(bytes(self.lut), image.im.id)
|
||||||
|
|
||||||
def get_on_pixels(self, image):
|
def get_on_pixels(self, image):
|
||||||
|
@ -220,6 +226,9 @@ class MorphOp(object):
|
||||||
Returns a list of tuples of (x,y) coordinates
|
Returns a list of tuples of (x,y) coordinates
|
||||||
of all matching pixels."""
|
of all matching pixels."""
|
||||||
|
|
||||||
|
if image.mode != 'L':
|
||||||
|
raise Exception('Image must be binary, meaning it must use mode L')
|
||||||
|
return
|
||||||
return _imagingmorph.get_on_pixels(image.im.id)
|
return _imagingmorph.get_on_pixels(image.im.id)
|
||||||
|
|
||||||
def load_lut(self, filename):
|
def load_lut(self, filename):
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
# Test the ImageMorphology functionality
|
# Test the ImageMorphology functionality
|
||||||
from helper import unittest, PillowTestCase
|
from helper import unittest, PillowTestCase, hopper
|
||||||
|
|
||||||
from PIL import Image
|
from PIL import Image
|
||||||
from PIL import ImageMorph
|
from PIL import ImageMorph
|
||||||
|
@ -168,6 +168,14 @@ class MorphTests(PillowTestCase):
|
||||||
self.assertEqual(len(coords), 4)
|
self.assertEqual(len(coords), 4)
|
||||||
self.assertEqual(tuple(coords), ((2, 2), (4, 2), (2, 4), (4, 4)))
|
self.assertEqual(tuple(coords), ((2, 2), (4, 2), (2, 4), (4, 4)))
|
||||||
|
|
||||||
|
def test_non_binary_images(self):
|
||||||
|
im = hopper('RGB')
|
||||||
|
mop = ImageMorph.MorphOp(op_name="erosion8")
|
||||||
|
|
||||||
|
self.assertRaises(Exception, lambda: mop.apply(im))
|
||||||
|
self.assertRaises(Exception, lambda: mop.match(im))
|
||||||
|
self.assertRaises(Exception, lambda: mop.get_on_pixels(im))
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
unittest.main()
|
unittest.main()
|
||||||
|
|
Loading…
Reference in New Issue
Block a user