From e531e57124a71739f834c23ea930cfb40cb823d3 Mon Sep 17 00:00:00 2001 From: Steven Silvester Date: Wed, 25 Mar 2015 22:22:06 -0500 Subject: [PATCH 1/3] Only index tif and gif files in collection --- skimage/io/collection.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/skimage/io/collection.py b/skimage/io/collection.py index aab7cb86..cdcb31d6 100644 --- a/skimage/io/collection.py +++ b/skimage/io/collection.py @@ -201,7 +201,7 @@ class ImageCollection(object): if fname.lower().endswith(('.tiff', '.tif')): img = TiffFile(fname) index += [(fname, i) for i in range(len(img.pages))] - else: + elif fname.lower().endswith('gif'): im = Image.open(fname) try: # this will raise an IOError if the file is not readable @@ -221,6 +221,8 @@ class ImageCollection(object): i += 1 if hasattr(im, 'fp') and im.fp: im.fp.close() + else: + index += (fname, 0) self._frame_index = index return len(index) From ad8c94fcaf6c6225ab1ac9686a64417652dd777c Mon Sep 17 00:00:00 2001 From: Steven Silvester Date: Mon, 30 Mar 2015 21:41:44 -0500 Subject: [PATCH 2/3] Fix handling of non-gif and tiff files --- skimage/io/collection.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/skimage/io/collection.py b/skimage/io/collection.py index cdcb31d6..b36c95f4 100644 --- a/skimage/io/collection.py +++ b/skimage/io/collection.py @@ -135,7 +135,7 @@ class ImageCollection(object): ic = ImageCollection('/tmp/*.png', load_func=imread_convert) For files with multiple images, the images will be flattened into a list - and added to the list of available images. In this case, ``load_func`` + and added to the list of available images. In this case, ``load_func`` should accept the keyword argument ``img_num``. Examples @@ -222,7 +222,7 @@ class ImageCollection(object): if hasattr(im, 'fp') and im.fp: im.fp.close() else: - index += (fname, 0) + index += [(fname, 0)] self._frame_index = index return len(index) From 62e82ccf49d37307e3fcabd137eae32f9cd596b2 Mon Sep 17 00:00:00 2001 From: Steven Silvester Date: Tue, 31 Mar 2015 20:54:57 -0500 Subject: [PATCH 3/3] Do not read in the whole array --- skimage/io/collection.py | 34 ++++++++++++++-------------------- 1 file changed, 14 insertions(+), 20 deletions(-) diff --git a/skimage/io/collection.py b/skimage/io/collection.py index b36c95f4..8812740e 100644 --- a/skimage/io/collection.py +++ b/skimage/io/collection.py @@ -201,29 +201,23 @@ class ImageCollection(object): if fname.lower().endswith(('.tiff', '.tif')): img = TiffFile(fname) index += [(fname, i) for i in range(len(img.pages))] - elif fname.lower().endswith('gif'): - im = Image.open(fname) + else: try: - # this will raise an IOError if the file is not readable - im.getdata()[0] - except IOError: - site = "http://pillow.readthedocs.org/en/latest/installation.html#external-libraries" - raise ValueError( - 'Could not load "%s"\nPlease see documentation at: %s' % (fname, site)) - else: - i = 0 - while True: - try: - im.seek(i) - except EOFError: - break - index.append((fname, i)) - i += 1 + im = Image.open(fname) + im.seek(0) + except (IOError, OSError): + index.append([fname, i]) + continue + i = 0 + while True: + try: + im.seek(i) + except EOFError: + break + index.append((fname, i)) + i += 1 if hasattr(im, 'fp') and im.fp: im.fp.close() - else: - index += [(fname, 0)] - self._frame_index = index return len(index)