Merge pull request #5414 from radarhere/morph

Changed ImageMorph incorrect mode errors to ValueError
This commit is contained in:
Hugo van Kemenade 2021-04-23 16:52:55 +03:00 committed by GitHub
commit b09a9210d4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 10 deletions

View File

@ -235,19 +235,19 @@ def test_negate():
) )
def test_non_binary_images(): def test_incorrect_mode():
im = hopper("RGB") im = hopper("RGB")
mop = ImageMorph.MorphOp(op_name="erosion8") mop = ImageMorph.MorphOp(op_name="erosion8")
with pytest.raises(Exception) as e: with pytest.raises(ValueError) as e:
mop.apply(im) mop.apply(im)
assert str(e.value) == "Image must be binary, meaning it must use mode L" assert str(e.value) == "Image mode must be L"
with pytest.raises(Exception) as e: with pytest.raises(ValueError) as e:
mop.match(im) mop.match(im)
assert str(e.value) == "Image must be binary, meaning it must use mode L" assert str(e.value) == "Image mode must be L"
with pytest.raises(Exception) as e: with pytest.raises(ValueError) as e:
mop.get_on_pixels(im) mop.get_on_pixels(im)
assert str(e.value) == "Image must be binary, meaning it must use mode L" assert str(e.value) == "Image mode must be L"
def test_add_patterns(): def test_add_patterns():

View File

@ -196,7 +196,7 @@ class MorphOp:
raise Exception("No operator loaded") raise Exception("No operator loaded")
if image.mode != "L": if image.mode != "L":
raise Exception("Image must be binary, meaning it must use mode L") raise ValueError("Image mode must be L")
outimage = Image.new(image.mode, image.size, None) outimage = Image.new(image.mode, image.size, None)
count = _imagingmorph.apply(bytes(self.lut), image.im.id, outimage.im.id) count = _imagingmorph.apply(bytes(self.lut), image.im.id, outimage.im.id)
return count, outimage return count, outimage
@ -211,7 +211,7 @@ class MorphOp:
raise Exception("No operator loaded") raise Exception("No operator loaded")
if image.mode != "L": if image.mode != "L":
raise Exception("Image must be binary, meaning it must use mode L") raise ValueError("Image mode must be L")
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):
@ -221,7 +221,7 @@ class MorphOp:
of all matching pixels. See :ref:`coordinate-system`.""" of all matching pixels. See :ref:`coordinate-system`."""
if image.mode != "L": if image.mode != "L":
raise Exception("Image must be binary, meaning it must use mode L") raise ValueError("Image mode must be L")
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):