Inheritance diagram for nipy.core.image.xyz_image:
The base image interface.
Bases: nipy.core.image.image.Image
XYZ output coordinates.
This object is a subclass of Image that assumes the first 3 coordinates are spatial.
Attributes
| metadata: | dictionary 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’). |
|---|---|
| xyz_transform: | XYZTransform A CoordinateMap that relates all the spatial axes of the data to XYZ ‘xyz’ coordinates. |
| coordmap: | AffineTransform Coordinate map describing the relationship between all coordinates and axis_names. |
| axes: | CoordinateSystem CoordinateSystem for the axes of the data. |
| reference: | CoordinateSystem CoordinateSystem for the reference space of the data. |
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.
>>> data = np.empty((30,40,50))
>>> affine = np.diag([3,4,5,1])
>>> im = XYZImage(data, affine, 'ijk')
>>> im.reference
CoordinateSystem(coord_names=('x+LR', 'y+PA', 'z+SI'), name='world', coord_dtype=float64)
>>> im.axes
CoordinateSystem(coord_names=('i', 'j', 'k'), name='voxel', coord_dtype=float64)
>>> im.xyz_transform
XYZTransform(
function_domain=CoordinateSystem(coord_names=('i', 'j', 'k'), name='voxel', coord_dtype=float64),
function_range=CoordinateSystem(coord_names=('x+LR', 'y+PA', 'z+SI'), name='world', coord_dtype=float64),
affine=array([[ 3., 0., 0., 0.],
[ 0., 4., 0., 0.],
[ 0., 0., 5., 0.],
[ 0., 0., 0., 1.]])
)
>>>
Methods
| axes | |
| coordmap | |
| from_image | |
| get_data | |
| ndim | |
| renamed_axes | |
| renamed_reference | |
| reordered_axes | |
| reordered_reference | |
| resampled_to_affine | |
| resampled_to_img | |
| shape | |
| to_image | |
| values_in_world | |
| xyz_ordered |
Creates a new nipy image with an affine mapping.
| Parameters: | data : ndarray
affine : 4x4 ndarray
axis_names : [string]
|
|---|
Return a new image with its axes renamed according to the dictionary.
| Parameters: | img : Image names_dict : dictionary |
|---|---|
| Returns: | newimg : Image
|
Examples
>>> data = np.random.standard_normal((11,9,4))
>>> im = XYZImage(data, np.diag([3,4,5,1]), 'ijk')
>>> im_renamed = im.renamed_axes(i='slice')
>>> print im_renamed.axes
CoordinateSystem(coord_names=('slice', 'j', 'k'), name='voxel', coord_dtype=float64)
Return a new XYZImage whose axes have been reordered. The reordering must be such that the first 3 coordinates remain the same.
| Parameters: | order : sequence
name: string, optional :
|
|---|
Resample the image to be an affine image.
| Parameters: | affine_transform : XYZTransform
world_to_world: 4x4 ndarray, optional :
interpolation_order : int, optional
shape: tuple :
|
|---|---|
| Returns: | resampled_image : XYZImage
|
Notes
The coordinate system of the output 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 : XYZImage
world_to_world: 4x4 ndarray, optional :
interpolation_order : int, optional
|
|---|---|
| Returns: | resampled_image : XYZImage
|
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, (optionally with positive entries), in the XYZ coordinate system.
| Parameters: | positive : bool, optional
|
|---|
Notes
This may possibly transpose the data array.
If positive is True, this may involve creating a new array with data
self.get_data()[::-1,::-1]
Bases: nipy.core.reference.coordinate_map.AffineTransform
An AffineTransform with either LPS:(‘x+LR’, ‘y+PA’, ‘z+SI’) or RAS:(‘x+RL’, ‘y+AP’, ‘z+SI’) output coordinates.
Methods
| from_params | |
| from_start_step | |
| identity | |
| inverse | |
| renamed_domain | |
| renamed_range | |
| reordered_domain | |
| reordered_range |
>>> xyz = XYZTransform(np.diag([3,4,5,1]), 'ijk')
>>> xyz
XYZTransform(
function_domain=CoordinateSystem(coord_names=('i', 'j', 'k'), name='voxel', coord_dtype=float64),
function_range=CoordinateSystem(coord_names=('x+LR', 'y+PA', 'z+SI'), name='world', coord_dtype=float64),
affine=array([[ 3., 0., 0., 0.],
[ 0., 4., 0., 0.],
[ 0., 0., 5., 0.],
[ 0., 0., 0., 1.]])
)
>>>
Create an AffineTransform instance from sequences of innames and outnames.
| Parameters: | innames : tuple of string
outnames : tuple of string
params : AffineTransform, ndarray or (ndarray, ndarray)
domain_name : string
range_name : string
|
|---|---|
| Returns: | aff : AffineTransform object instance |
Notes
| Precondition: | len(shape) == len(names) |
|---|---|
| Raises valueerror: | |
| if len(shape) != len(names) | |
Create an AffineTransform instance from sequences of names, start and step.
| Parameters: | innames : tuple of string
outnames : tuple of string
start : tuple of float
step : tuple of float
domain_name : string
range_name : string
|
|---|---|
| Returns: | cm : CoordinateMap |
Notes
len(names) == len(start) == len(step)
Examples
>>> cm = AffineTransform.from_start_step('ijk', 'xyz', [1, 2, 3], [4, 5, 6])
>>> cm.affine
array([[ 4., 0., 0., 1.],
[ 0., 5., 0., 2.],
[ 0., 0., 6., 3.],
[ 0., 0., 0., 1.]])
Return an identity coordmap of the given shape.
| Parameters: | coord_names : tuple of string
name : string
|
|---|---|
| Returns: | cm : CoordinateMap
|
Examples
>>> cm = AffineTransform.identity('ijk', 'somewhere')
>>> cm.affine
array([[ 1., 0., 0., 0.],
[ 0., 1., 0., 0.],
[ 0., 0., 1., 0.],
[ 0., 0., 0., 1.]])
>>> print cm.function_domain
CoordinateSystem(coord_names=('i', 'j', 'k'), name='somewhere', coord_dtype=float64)
>>> print cm.function_range
CoordinateSystem(coord_names=('i', 'j', 'k'), name='somewhere', coord_dtype=float64)
Create a new AffineTransform with the coordinates of function_domain reordered. Default behaviour is to reverse the order of the coordinates.
| Parameters: | order: sequence :
|
|---|
Take an xyz_img and flip its world from LPS / RAS to RAS / LPS.
>>> data = np.random.standard_normal((30,40,50,5))
>>> metadata = {'name':'John Doe'}
>>> lps_im = XYZImage(data, np.diag([3,4,5,1]), 'ijkt', metadata)
>>> lps_im.xyz_transform
XYZTransform(
function_domain=CoordinateSystem(coord_names=('i', 'j', 'k'), name='voxel', coord_dtype=float64),
function_range=CoordinateSystem(coord_names=('x+LR', 'y+PA', 'z+SI'), name='world', coord_dtype=float64),
affine=array([[ 3., 0., 0., 0.],
[ 0., 4., 0., 0.],
[ 0., 0., 5., 0.],
[ 0., 0., 0., 1.]])
)
>>> ras_im = flip(lps_im)
>>> ras_im.xyz_transform
XYZTransform(
function_domain=CoordinateSystem(coord_names=('i', 'j', 'k'), name='voxel', coord_dtype=float64),
function_range=CoordinateSystem(coord_names=('x+RL', 'y+AP', 'z+SI'), name='world', coord_dtype=float64),
affine=array([[-3., 0., 0., 0.],
[ 0., -4., 0., 0.],
[ 0., 0., 5., 0.],
[ 0., 0., 0., 1.]])
)
>>> print np.allclose(ras_im.get_data(), lps_im.get_data())
True
>>> print ras_im.metadata == lps_im.metadata
True
>>>
>>> print flip(ras_im) == lps_im
True
>>>