Inheritance diagram for nipy.core.image.affine_image:
The base image interface.
Bases: nipy.core.image.image.Image
The affine image for nipy.
This object is a subclass of Image that assumes the first 3 coordinates are spatial.
Attributes
Metadata : | dictionnary Optional, user-defined, dictionnary used to carry around extra information about the data as it goes through transformations. The Image class does not garanty consistency of this information as the data is modified. |
---|---|
_data : | Private pointer to the data. |
Properties
Affine : | 4x4 ndarray Affine mapping from voxel axes to world coordinates (world coordinates are always forced to be ‘x’, ‘y’, ‘z’). |
---|---|
Spatial_coordmap : | |
AffineTransform Coordinate map describing the spatial coordinates (always forced to be ‘x’, ‘y’, ‘z’) and the coordinate axes with names axis_names[:3]. |
|
Coordmap : | AffineTransform Coordinate map describing the relationship between all coordinates and axis_names. |
Notes
The data is stored in an undefined way: prescalings might need to be applied to it before using it, or the data might be loaded on demand. The best practice to access the data is not to access the _data attribute, but to use the get_data method.
Methods
axes | |
coordmap | |
get_data | |
ndim | |
reference | |
renamed_axes | |
renamed_reference | |
reordered_axes | |
reordered_reference | |
resampled_to_affine | |
resampled_to_img | |
shape | |
values_in_world | |
xyz_ordered |
Creates a new nipy image with an affine mapping.
Parameters : | data : ndarray
affine : 4x4 ndarray
coord_system : string
|
---|
Returns the affine of the spatial coordmap which will always be a 4x4 matrix.
Return data as a numpy array.
The file header structure for this image, if available. This interface will soon go away - you should use ``img.metadata[‘header’] instead.
Return a new image with input (domain) axes renamed
Axes renamed according to the input dictionary.
Parameters : | **names_dict : dict
|
---|---|
Returns : | newimg : Image
|
Examples
>>> data = np.random.standard_normal((11,9,4))
>>> im = Image(data, AffineTransform.from_params('ijk', 'xyz', np.identity(4), 'domain', 'range'))
>>> im_renamed = im.renamed_axes(i='slice')
>>> print im_renamed.axes
CoordinateSystem(coord_names=('slice', 'j', 'k'), name='domain', coord_dtype=float64)
Return new image with renamed output (range) coordinates
Coordinates renamed according to the dictionary
Parameters : | **names_dict : dict
|
---|---|
Returns : | newimg : Image
|
Examples
>>> data = np.random.standard_normal((11,9,4))
>>> im = Image(data, AffineTransform.from_params('ijk', 'xyz', np.identity(4), 'domain', 'range'))
>>> im_renamed_reference = im.renamed_reference(x='newx', y='newy')
>>> print im_renamed_reference.reference
CoordinateSystem(coord_names=('newx', 'newy', 'z'), name='range', coord_dtype=float64)
Return a new Image with reordered input coordinates.
This transposes the data as well.
Parameters : | order : None, sequence, optional
|
---|---|
Returns : | r_img : object
|
Examples
>>> cmap = AffineTransform.from_start_step('ijk', 'xyz', [1,2,3],[4,5,6], 'domain', 'range')
>>> cmap
AffineTransform(
function_domain=CoordinateSystem(coord_names=('i', 'j', 'k'), name='domain', coord_dtype=float64),
function_range=CoordinateSystem(coord_names=('x', 'y', 'z'), name='range', coord_dtype=float64),
affine=array([[ 4., 0., 0., 1.],
[ 0., 5., 0., 2.],
[ 0., 0., 6., 3.],
[ 0., 0., 0., 1.]])
)
>>> im = Image(np.empty((30,40,50)), cmap)
>>> im_reordered = im.reordered_axes([2,0,1])
>>> im_reordered.shape
(50, 30, 40)
>>> im_reordered.coordmap
AffineTransform(
function_domain=CoordinateSystem(coord_names=('k', 'i', 'j'), name='domain', coord_dtype=float64),
function_range=CoordinateSystem(coord_names=('x', 'y', 'z'), name='range', coord_dtype=float64),
affine=array([[ 0., 4., 0., 1.],
[ 0., 0., 5., 2.],
[ 6., 0., 0., 3.],
[ 0., 0., 0., 1.]])
)
Return new Image with reordered output coordinates
New Image coordmap has reordered output coordinates. This does not transpose the data.
Parameters : | order : None, sequence, optional
|
---|---|
Returns : | r_img : object
|
Examples
>>> cmap = AffineTransform.from_start_step('ijk', 'xyz', [1,2,3],[4,5,6], 'domain', 'range')
>>> im = Image(np.empty((30,40,50)), cmap)
>>> im_reordered = im.reordered_reference([2,0,1])
>>> im_reordered.shape
(30, 40, 50)
>>> im_reordered.coordmap
AffineTransform(
function_domain=CoordinateSystem(coord_names=('i', 'j', 'k'), name='domain', coord_dtype=float64),
function_range=CoordinateSystem(coord_names=('z', 'x', 'y'), name='range', coord_dtype=float64),
affine=array([[ 0., 0., 6., 3.],
[ 4., 0., 0., 1.],
[ 0., 5., 0., 2.],
[ 0., 0., 0., 1.]])
)
Resample the image to be an affine image.
Parameters : | affine_transform : AffineTransform
world_to_world: 4x4 ndarray, optional :
interpolation_order : int, optional
shape: tuple :
|
---|---|
Returns : | resampled_image : nipy AffineImage
|
Notes
The coordinate system of the resampled_image is the world of affine_transform. Therefore, if world_to_world=np.identity(4), the coordinate system is not changed: the returned image points to the same world space.
Resample the image to be on the same grid than the target image.
Parameters : | target_image : AffineImage
|
---|---|
Returns : | resampled_image : nipy_image
|
XXX Since you’ve enforced the outputs always to be ‘x’,’y’,’z’ – EVERY image is embedded in the same coordinate system (i.e. ‘x’,’y’,’z’), but images can have different coordinate axes. The term “embedding” that was here in the proposal refers to something in the range of a function, not its domain. By adding a world_to_world transformation, i.e. a rotation or something, we now change the coordinate system of the resampled_image
Returns 3 dimensional AffineTransform, which is the same as self.coordmap if self.ndim == 3.
Return the values of the data at the world-space positions given by x, y, z
Parameters : | x : number or ndarray
y : number or ndarray
z : number or ndarray
interpolation_order : int, optional
|
---|---|
Returns : | values : number or ndarray
|
Returns an image with the affine diagonal and positive in its coordinate system.