diff --git a/bob/io/base/__init__.py b/bob/io/base/__init__.py index c095d4f77006598b28e02e092f9b2c51d547662d..99d4e6ff0881cb17fa0ab14c1d62a9f166e1215e 100644 --- a/bob/io/base/__init__.py +++ b/bob/io/base/__init__.py @@ -4,7 +4,9 @@ import h5py import imageio from .utils import to_bob, to_matplotlib, opencvbgr_to_bob, bob_to_opencvbgr, imshow +import logging +logger = logging.getLogger(__name__) import os @@ -84,6 +86,8 @@ def open_file(filename): return img extension = os.path.splitext(filename)[1] # get the extension + # logger.error("############") + # logger.error(filename) if extension in hdf5_extensions: with h5py.File(filename, "r") as f: @@ -99,8 +103,9 @@ def open_file(filename): # PNGs have a 4th channel, which we don't want # Alpha channels for instance have to be ignored - if extension.lower() == ".png": - img = img[:, :, 0:3] + if img.ndim > 2: + if extension.lower() == ".png": + img = img[:, :, 0:3] img = check_gray(img) return img if img.ndim == 2 else to_bob(img) diff --git a/bob/io/base/test/data/read_png_gray.png b/bob/io/base/test/data/read_png_gray.png new file mode 100755 index 0000000000000000000000000000000000000000..950b19052d1a847e350568aeca5527a2e46f0714 Binary files /dev/null and b/bob/io/base/test/data/read_png_gray.png differ diff --git a/bob/io/base/test/test_image_support.py b/bob/io/base/test/test_image_support.py index 437169912ff226a588a30e2285b7e9b21d8977bf..6c096b7e4df3e03851c02f5ca34e715a3318161a 100644 --- a/bob/io/base/test/test_image_support.py +++ b/bob/io/base/test/test_image_support.py @@ -150,3 +150,10 @@ def test_image_load(): nose.tools.assert_raises( RuntimeError, lambda x: load(os.path.splitext(x)[0] + ".unknown"), full_file ) + + +def test_image_exceptions(): + # This tests some image exceptions I found + + # Real PNG image + transcode(datafile("read_png_gray.png", __name__))