Inheritance diagram for nipy.core.image.xyz_image:
Images that have orientations L/R, A/P, S/I, and that have the first three dimensions as spatial
Bases: nipy.core.image.image.Image
The standard image for nipy, with XYZ output coordinates.
This object is a subclass of Image that assumes the first 3 coordinates are spatial.
Attributes
metadata: dictionary
Optional, user-defined, dictionary 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.
Examples
>>> 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 : array
affine : 4x4 array
axis_names : [string]
|
---|
4x4 Affine matrix
Return an XYZImage from an Image with the same data.
The affine matrix is read off from the upper left corner of img.affine.
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.
Reference space is always ‘world’ for XYZImage
Return new image with its axes renamed
Axes renamed according to the dictionary.
Parameters : | img : Image names_dict : dict |
---|---|
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')
>>> 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 : str, optional
|
---|---|
Returns : | im_reordered : XYZImage |
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 an Image with the same data as self.
Return values of data at world-space positions x, y, z
Parameters : | x : number or array
y : number or array
z : number or array
interpolation_order : int, optional
|
---|---|
Returns : | values : number or array
|
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]
Returns 3-dimensional XYZTransform
The same as self.coordmap if self.ndim == 3.
Bases: nipy.core.reference.coordinate_map.AffineTransform
Affine transform with x, y, z being L<->R, P<->A, I<->S
That is, the X axis is left to right or right to left, the Y axis is anterior to posterior or posterior to anterior, and the Z axis is inferior to superior or superior to inferior.
Methods
from_params | |
from_start_step | |
identity | |
inverse | |
renamed_domain | |
renamed_range | |
reordered_domain | |
reordered_range |
Initialize XYZTransform
Parameters : | affine : (4, 4) array-like axis_names : sequence or str
lps : bool, optional
|
---|
Examples
>>> 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 AffineTransform from innames and outnames
Parameters : | innames : sequence of str or str
outnames : seqence of str or str
params : AffineTransform, array or (array, array)
domain_name : str, optional
range_name : str, optional
|
---|---|
Returns : | aff : AffineTransform |
Notes
Precondition : | len(shape) == len(names) |
---|---|
Raises ValueError: | |
if len(shape) != len(names) |
New AffineTransform from names, start and step.
Parameters : | innames : sequence of str or str
outnames : seqence of str or str
start : sequence of float
step : sequence of float
domain_name : str, optional
range_name : str, optional
|
---|---|
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 : sequence of str or str
name : str, optional
|
---|---|
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.]])
>>> cm.function_domain
CoordinateSystem(coord_names=('i', 'j', 'k'), name='somewhere', coord_dtype=float64)
>>> cm.function_range
CoordinateSystem(coord_names=('i', 'j', 'k'), name='somewhere', coord_dtype=float64)
Return inverse affine transform or None if not invertible
New AffineTransform with function_domain renamed
Parameters : | newnames : dict
|
---|---|
Returns : | newmapping : AffineTransform
|
Examples
>>> affine_domain = CoordinateSystem('ijk')
>>> affine_range = CoordinateSystem('xyz')
>>> affine_matrix = np.identity(4)
>>> affine_mapping = AffineTransform(affine_domain, affine_range, affine_matrix)
>>> new_affine_mapping = affine_mapping.renamed_domain({'i':'phase','k':'freq','j':'slice'})
>>> new_affine_mapping.function_domain
CoordinateSystem(coord_names=('phase', 'slice', 'freq'), name='', coord_dtype=float64)
>>> new_affine_mapping = affine_mapping.renamed_domain({'i':'phase','k':'freq','l':'slice'})
Traceback (most recent call last):
...
ValueError: no domain coordinate named l
New AffineTransform with function_domain reordered
Default behaviour is to reverse the order of the coordinates.
Parameters : | order : sequence
|
---|---|
Returns : | newmapping :AffineTransform :
|
Examples
>>> input_cs = CoordinateSystem('ijk')
>>> output_cs = CoordinateSystem('xyz')
>>> cm = AffineTransform(input_cs, output_cs, np.identity(4))
>>> cm.reordered_domain('ikj').function_domain
CoordinateSystem(coord_names=('i', 'k', 'j'), name='', coord_dtype=float64)
Flip world of xyz_img from LPS / RAS to RAS / LPS.
Parameters : | xyz_img : XYZImage |
---|---|
Returns : | f_img : XYZImage
|
Examples
>>> 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.]])
)
>>> np.allclose(ras_im.get_data(), lps_im.get_data())
True
>>> ras_im.metadata == lps_im.metadata
True
>>>
>>> flip(ras_im) == lps_im
True