diff --git a/skimage/io/collection.py b/skimage/io/collection.py index 4a74048efa8..6bf91f76a76 100644 --- a/skimage/io/collection.py +++ b/skimage/io/collection.py @@ -219,7 +219,8 @@ def concatenate(self): class ImageCollection(object): """Load and manage a collection of image files. - Note that files are always stored in alphabetical order. + Note that files are always stored in alphabetical order. Also note that + slicing returns a new ImageCollection, *not* a view into the data. Parameters ---------- @@ -286,7 +287,7 @@ def imread_convert(f): (128, 128, 3) >>> ic = io.ImageCollection('/tmp/work/*.png:/tmp/other/*.jpg') - + """ def __init__(self, load_pattern, conserve_memory=True, load_func=None): """Load and manage a collection of images.""" @@ -330,7 +331,7 @@ def __getitem__(self, n): Parameters ---------- n : int or slice - The image number to be returned, or a slice selecting the images + The image number to be returned, or a slice selecting the images and ordering to be returned in a new ImageCollection. Returns @@ -342,10 +343,10 @@ def __getitem__(self, n): """ if hasattr(n, '__index__'): n = n.__index__() - + if type(n) not in [int, slice]: raise TypeError('slicing must be with an int or slice object') - + if type(n) is int: n = self._check_imgnum(n) idx = n % len(self.data) @@ -356,15 +357,15 @@ def __getitem__(self, n): self._cached = n return self.data[idx] - else: - # A slice object was provided, so create a new ImageCollection - # object. Any loaded image data in the original ImageCollection - # will be copied by reference to the new object. Image data + else: + # A slice object was provided, so create a new ImageCollection + # object. Any loaded image data in the original ImageCollection + # will be copied by reference to the new object. Image data # loaded after this creation is not linked. fidx = range(len(self.files))[n] new_ic = copy(self) - new_ic._files = [self.files[i] for i in fidx] - if self.conserve_memory: + new_ic._files = [self.files[i] for i in fidx] + if self.conserve_memory: if self._cached in fidx: new_ic._cached = fidx.index(self._cached) new_ic.data = np.copy(self.data)