diff --git a/src/bob/io/base/__init__.py b/src/bob/io/base/__init__.py index 99be55ad0a19d5d63db753c5daa2c1b6abe2e1f5..6dd12cda098d48642c1225d7bb3e0dfb1f1f3088 100644 --- a/src/bob/io/base/__init__.py +++ b/src/bob/io/base/__init__.py @@ -112,6 +112,10 @@ def open_file(filename) -> np.ndarray: if img.shape[-1] == 1: img = img.squeeze(-1) + # PBMs return a boolean array; Convert it to 0 or 255 values + if extension.lower() == ".pbm" and img.dtype == bool: + img = img.astype(np.uint8) * 255 + img = check_gray(img) return img if img.ndim == 2 else to_bob(img) else: diff --git a/tests/test_image_support.py b/tests/test_image_support.py index ad7ef82b44e57d69e727003e6d09cfe00be253eb..3e2970dcfb9b3eaa93308faebf426f98abd7e1c9 100644 --- a/tests/test_image_support.py +++ b/tests/test_image_support.py @@ -106,7 +106,7 @@ def test_netpbm(): transcode(datafile("test.pgm", __name__)) # indexed, works fine transcode(datafile("test.ppm", __name__)) # indexed, works fine transcode(datafile("test_2.pgm", __name__)) # indexed, works fine - # transcode(datafile("test_2.ppm", __name__)) # indexed, works fine ----> THIS DOES NOT WORK + transcode(datafile("test_2.ppm", __name__)) # indexed, works fine transcode(datafile("test_spaces.pgm", __name__)) # indexed, works fine # transcode(datafile("test.jpg", __name__)) # does not work @@ -153,6 +153,6 @@ def test_image_exceptions(): # Real GRAY PNG image transcode(datafile("read_png_gray.png", __name__)) - # Trucated JPEG + # Truncated JPEG # THIS TEST FAILS # transcode(datafile("truncated_jpeg.jpg", __name__))