Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changed ImageMorph incorrect mode errors to ValueError #5414

Merged
merged 1 commit into from
Apr 23, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 7 additions & 7 deletions Tests/test_imagemorph.py
Original file line number Diff line number Diff line change
Expand Up @@ -235,19 +235,19 @@ def test_negate():
)


def test_non_binary_images():
def test_incorrect_mode():
im = hopper("RGB")
mop = ImageMorph.MorphOp(op_name="erosion8")

with pytest.raises(Exception) as e:
with pytest.raises(ValueError) as e:
mop.apply(im)
assert str(e.value) == "Image must be binary, meaning it must use mode L"
with pytest.raises(Exception) as e:
assert str(e.value) == "Image mode must be L"
with pytest.raises(ValueError) as e:
mop.match(im)
assert str(e.value) == "Image must be binary, meaning it must use mode L"
with pytest.raises(Exception) as e:
assert str(e.value) == "Image mode must be L"
with pytest.raises(ValueError) as e:
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():
Expand Down
6 changes: 3 additions & 3 deletions src/PIL/ImageMorph.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ def apply(self, image):
raise Exception("No operator loaded")

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)
count = _imagingmorph.apply(bytes(self.lut), image.im.id, outimage.im.id)
return count, outimage
Expand All @@ -211,7 +211,7 @@ def match(self, image):
raise Exception("No operator loaded")

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)

def get_on_pixels(self, image):
Expand All @@ -221,7 +221,7 @@ def get_on_pixels(self, image):
of all matching pixels. See :ref:`coordinate-system`."""

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)

def load_lut(self, filename):
Expand Down