Module: core.image.image_list

Inheritance diagram for nipy.core.image.image_list:

Inheritance diagram of nipy.core.image.image_list


class nipy.core.image.image_list.ImageList(images=None)

Bases: nipy.externals.six.Iterator

Class to contain ND image as list of (N-1)D images


An implementation of a list of images.


images : iterable

an iterable object whose items are meant to be images; this is checked by asserting that each has a coordmap attribute and a get_data method. Note that Image objects are not iterable by default; use the from_image classmethod or iter_axis function to convert images to image lists - see examples below for the latter.


>>> from nipy.testing import funcfile
>>> from nipy.core.api import Image, ImageList, iter_axis
>>> from import load_image
>>> funcim = load_image(funcfile)
>>> iterable_img = iter_axis(funcim, 't')
>>> ilist = ImageList(iterable_img)
>>> sublist = ilist[2:5]

Slicing an ImageList returns a new ImageList

>>> isinstance(sublist, ImageList)

Indexing an ImageList returns a new Image

>>> newimg = ilist[2]
>>> isinstance(newimg, Image)
>>> isinstance(newimg, ImageList)
>>> np.asarray(sublist).shape
(3, 17, 21, 3)
>>> newimg.get_data().shape
(17, 21, 3)
classmethod from_image(klass, image, axis=None, dropout=True)

Create an image list from an image by slicing over axis


image : object

object with coordmap attribute

axis : str or int

axis of image that should become the axis indexed by the image list.

dropout : bool, optional

When taking slices from an image, we will leave an output dimension to the coordmap that has no corresponding input dimension. If dropout is True, drop this output dimension.


ilist : ImageList instance


Return data in ndarray with list dimension at position axis


axis : int

axis specifies which axis of the output will take the role of the list dimension. For example, 0 will put the list dimension in the first axis of the result.


data : ndarray

data in image list as array, with data across elements of the list concetenated at dimension axis of the array.


>>> from nipy.testing import funcfile
>>> from import load_image
>>> funcim = load_image(funcfile)
>>> ilist = ImageList.from_image(funcim, axis='t')
>>> ilist.get_list_data(axis=0).shape
(20, 17, 21, 3)