mirror of
https://github.com/python-pillow/Pillow.git
synced 2026-01-10 10:41:18 +03:00
Allow 1 mode images in MorphOp get_on_pixels()
This commit is contained in:
parent
ca21683316
commit
9b7200d2b4
|
|
@ -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)
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -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())
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user