core.image.image_list

Module: core.image.image_list

Inheritance diagram for nipy.core.image.image_list:

Inheritance diagram of nipy.core.image.image_list

ImageList

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

__init__(images=None)

An implementation of a list of images.

Parameters:

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.

Examples

>>> from nipy.testing import funcfile
>>> from nipy.core.api import Image, ImageList, iter_axis
>>> from nipy.io.api 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)
True

Indexing an ImageList returns a new Image

>>> newimg = ilist[2]
>>> isinstance(newimg, Image)
True
>>> isinstance(newimg, ImageList)
False
>>> 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

Parameters:

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.

Returns:

ilist : ImageList instance

get_list_data(axis=None)

Return data in ndarray with list dimension at position axis

Parameters:

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.

Returns:

data : ndarray

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

Examples

>>> from nipy.testing import funcfile
>>> from nipy.io.api 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)