Inheritance diagram for nipy.core.reference.coordinate_map:
CoordinateMaps map (transform) an image from an input space to an output space.
A CoordinateMap object contains all the details about an input CoordinateSystem, an output CoordinateSystem and the mappings between them. The mapping transforms an image from the input coordinate system to the output coordinate system. And the inverse_mapping performs the opposite transformation. The inverse_mapping can be specified explicity when creating the CoordinateMap or implicitly in the case of an Affine CoordinateMap.
Bases: nipy.core.reference.coordinate_map.CoordinateMap
A class representing an affine transformation from an input coordinate system to an output coordinate system.
This class has an affine property, which is a matrix representing the affine transformation in homogeneous coordinates. This matrix is used to perform mappings, rather than having an explicit mapping function.
>>> inp_cs = CoordinateSystem('ijk')
>>> out_cs = CoordinateSystem('xyz')
>>> cm = Affine(np.diag([1, 2, 3, 1]), inp_cs, out_cs)
>>> cm.affine
array([[ 1., 0., 0., 0.],
[ 0., 2., 0., 0.],
[ 0., 0., 3., 0.],
[ 0., 0., 0., 1.]])
>>> cm([1,1,1])
array([[ 1., 2., 3.]])
>>> icm = cm.inverse
>>> icm([1,2,3])
array([[ 1., 1., 1.]])
Return an CoordinateMap specified by an affine transformation in homogeneous coordinates.
Parameters: | affine : array-like
input_coords : CoordinateSystem
output_coords : CoordinateSystem
|
---|
Notes
The dtype of the resulting matrix is determined by finding a safe typecast for the input_coords, output_coords and affine.
Create a copy of the coordmap.
Returns: | cm : CoordinateMap |
---|
Examples
>>> cm = Affine(np.eye(4), CoordinateSystem('ijk'), CoordinateSystem('xyz'))
>>> cm_copy = cm.copy()
>>> cm is cm_copy
False
Note that the matrix (affine) is not a pointer to the same data, it’s a full independent copy
>>> cm.affine[0,0] = 2.0
>>> cm_copy.affine[0,0]
1.0
Create an Affine instance from sequences of innames and outnames.
Parameters: | innames : tuple of string
outnames : tuple of string
params : Affine, ndarray or (ndarray, ndarray)
|
---|---|
Returns: | aff : Affine object instance |
Notes
Precondition: | len(shape) == len(names) |
---|---|
Raises valueerror: | |
if len(shape) != len(names) |
Create an Affine 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
|
---|---|
Returns: | cm : CoordinateMap |
Notes
len(names) == len(start) == len(step)
Examples
>>> cm = Affine.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: | names : tuple of string
|
---|---|
Returns: | cm : CoordinateMap
|
Examples
>>> cm = Affine.identity('ijk')
>>> cm.affine
array([[ 1., 0., 0., 0.],
[ 0., 1., 0., 0.],
[ 0., 0., 1., 0.],
[ 0., 0., 0., 1.]])
>>> print cm.input_coords
name: 'input', coord_names: ('i', 'j', 'k'), coord_dtype: float64
>>> print cm.output_coords
name: 'output', coord_names: ('i', 'j', 'k'), coord_dtype: float64
Bases: object
A set of input and output CoordinateSystems and a mapping between them.
For example, the mapping may represent the mapping of an image from voxel space (the input coordinates) to real space (the output coordinates). The mapping may be an affine or non-affine transformation.
Attributes: | input_coords : CoordinateSystem
output_coords : CoordinateSystem
mapping : callable
inverse_mapping : None or callable
|
---|
Examples
>>> input_coords = CoordinateSystem('ijk', 'voxels')
>>> output_coords = CoordinateSystem('xyz', 'world')
>>> mni_orig = np.array([-90.0, -126.0, -72.0])
>>> mapping = lambda x: x + mni_orig
>>> inv_mapping = lambda x: x - mni_orig
>>> cm = CoordinateMap(mapping, input_coords, output_coords, inv_mapping)
Map the first 3 voxel coordinates, along the x-axis, to mni space:
>>> x = np.array([[0,0,0], [1,0,0], [2,0,0]])
>>> cm.mapping(x)
array([[ -90., -126., -72.],
[ -89., -126., -72.],
[ -88., -126., -72.]])
Create a CoordinateMap given the input/output coords and mappings.
Parameters: | mapping : callable
input_coords : CoordinateSystem
output_coords : CoordinateSystem
inverse_mapping : None or callable, optional
|
---|---|
Returns: | coordmap : CoordinateMap |
Create a copy of the coordmap.
Returns: | coordmap : CoordinateMap |
---|
Given a Mapping of ndimin variables, return the linearization of mapping at origin based on a given step size in each coordinate axis.
If not specified, origin defaults to np.zeros(ndimin, dtype=dtype).
Parameters: | mapping : callable
ndimin : int
step : scalar, optional
origin : None or array, optional
dtype : None or np.dtype, optional
|
---|---|
Returns: | C : array
|
Create a CoordinateMap by taking the product of coordmap with a 1-dimensional ‘concat’ CoordinateSystem
Parameters: |
|
---|