diff --git a/src/bob/io/base/__init__.py b/src/bob/io/base/__init__.py index 6b0b20d8d7b2007b1843880d5282158d21f6085e..99be55ad0a19d5d63db753c5daa2c1b6abe2e1f5 100644 --- a/src/bob/io/base/__init__.py +++ b/src/bob/io/base/__init__.py @@ -104,11 +104,13 @@ def open_file(filename) -> np.ndarray: img = imageio.imread(filename) - # PNGs have a 4th channel, which we don't want + # PNGs have an additional channel, which we don't want # Alpha channels for instance have to be ignored if img.ndim > 2: - if extension.lower() == ".png": - img = img[:, :, 0:3] + if extension.lower() == ".png" and img.shape[-1] in (2, 4): + img = img[:, :, :-1] + if img.shape[-1] == 1: + img = img.squeeze(-1) img = check_gray(img) return img if img.ndim == 2 else to_bob(img)