Allow 1 mode images in MorphOp get_on_pixels()

This commit is contained in:
Andrew Murray 2025-12-23 12:50:26 +11:00
parent ca21683316
commit 9b7200d2b4
2 changed files with 8 additions and 7 deletions

View File

@ -188,9 +188,10 @@ def test_corner() -> None:
assert len(coords) == 4
assert tuple(coords) == ((2, 2), (4, 2), (2, 4), (4, 4))
coords = mop.get_on_pixels(Aout)
assert len(coords) == 4
assert tuple(coords) == ((2, 2), (4, 2), (2, 4), (4, 4))
for image in (Aout, Aout.convert("1")):
coords = mop.get_on_pixels(image)
assert len(coords) == 4
assert tuple(coords) == ((2, 2), (4, 2), (2, 4), (4, 4))
def test_mirroring() -> None:
@ -239,7 +240,7 @@ def test_incorrect_mode() -> None:
mop.apply(im)
with pytest.raises(ValueError, match="Image mode must be L"):
mop.match(im)
with pytest.raises(ValueError, match="Image mode must be L"):
with pytest.raises(ValueError, match="Image mode must be 1 or L"):
mop.get_on_pixels(im)

View File

@ -232,13 +232,13 @@ class MorphOp:
return _imagingmorph.match(bytes(self.lut), image.getim())
def get_on_pixels(self, image: Image.Image) -> list[tuple[int, int]]:
"""Get a list of all turned on pixels in a binary image
"""Get a list of all turned on pixels in a 1 or L mode image.
Returns a list of tuples of (x,y) coordinates
of all matching pixels. See :ref:`coordinate-system`."""
if image.mode != "L":
msg = "Image mode must be L"
if image.mode not in ("1", "L"):
msg = "Image mode must be 1 or L"
raise ValueError(msg)
return _imagingmorph.get_on_pixels(image.getim())