Add function 'concatenate' to ImageCollection

Many algorithms work on 3D stacks rather than images. It is convenient
to provide automatic conversion from an ImageCollection to an nD-stack.
This commit is contained in:
Juan Nunez-Iglesias
2012-07-20 15:16:48 -05:00
parent 12fb05f9ab
commit 11c7fd2f59
+20
View File
@@ -307,3 +307,23 @@ class ImageCollection(object):
"""
self.data = np.empty_like(self.data)
def concatenate(self):
"""Concatenate all images in the collection on a new axis.
Returns
-------
ar : np.ndarray
An array having one more dimension than the images in `self`.
Raises
------
ValueError
If images in the collection don't have identical shapes.
"""
all_images = [img[np.newaxis, ...] for img in self]
try:
ar = np.concatenate(all_images)
except ValueError:
raise ValueError('Image dimensions must agree.')
return ar