Skip to content

Commit

Permalink
DOC: Add note about ImageCollection slicing.
Browse files Browse the repository at this point in the history
Also, clean up some whitespace issues.
  • Loading branch information
tonysyu committed Aug 5, 2012
1 parent 816d6e3 commit a05c3c6
Showing 1 changed file with 12 additions and 11 deletions.
23 changes: 12 additions & 11 deletions skimage/io/collection.py
Expand Up @@ -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
----------
Expand Down Expand Up @@ -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."""
Expand Down Expand Up @@ -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
Expand All @@ -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)
Expand All @@ -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)
Expand Down

0 comments on commit a05c3c6

Please sign in to comment.