algorithms.registration.affine

Module: algorithms.registration.affine

Inheritance diagram for nipy.algorithms.registration.affine:

digraph inheritancea2fe1494e6 { rankdir=LR; size="8.0, 12.0"; "registration.affine.Affine" [URL="#nipy.algorithms.registration.affine.Affine",fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5)",target="_top"]; "registration.transform.Transform" -> "registration.affine.Affine" [arrowsize=0.5,style="setlinewidth(0.5)"]; "registration.affine.Affine2D" [URL="#nipy.algorithms.registration.affine.Affine2D",fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5)",target="_top"]; "registration.affine.Affine" -> "registration.affine.Affine2D" [arrowsize=0.5,style="setlinewidth(0.5)"]; "registration.affine.Rigid" [URL="#nipy.algorithms.registration.affine.Rigid",fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5)",target="_top"]; "registration.affine.Affine" -> "registration.affine.Rigid" [arrowsize=0.5,style="setlinewidth(0.5)"]; "registration.affine.Rigid2D" [URL="#nipy.algorithms.registration.affine.Rigid2D",fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5)",target="_top"]; "registration.affine.Rigid" -> "registration.affine.Rigid2D" [arrowsize=0.5,style="setlinewidth(0.5)"]; "registration.affine.Similarity" [URL="#nipy.algorithms.registration.affine.Similarity",fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5)",target="_top"]; "registration.affine.Affine" -> "registration.affine.Similarity" [arrowsize=0.5,style="setlinewidth(0.5)"]; "registration.affine.Similarity2D" [URL="#nipy.algorithms.registration.affine.Similarity2D",fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5)",target="_top"]; "registration.affine.Similarity" -> "registration.affine.Similarity2D" [arrowsize=0.5,style="setlinewidth(0.5)"]; "registration.transform.Transform" [URL="nipy.algorithms.registration.transform.html#nipy.algorithms.registration.transform.Transform",fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5)",target="_top",tooltip="A default transformation class"]; }

Classes

Affine

class nipy.algorithms.registration.affine.Affine(array=None, radius=100)[source]

Bases: nipy.algorithms.registration.transform.Transform

__init__(array=None, radius=100)[source]

Initialize self. See help(type(self)) for accurate signature.

param_inds = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]
copy()[source]
from_matrix44(aff)[source]

Convert a 4x4 matrix describing an affine transform into a 12-sized vector of natural affine parameters: translation, rotation, log-scale, pre-rotation (to allow for shearing when combined with non-unitary scales). In case the transform has a negative determinant, set the _direct attribute to False.

apply(xyz)[source]
property translation
property rotation
property scaling
property pre_rotation
property is_direct
property precond
property param
as_affine(dtype='double')[source]
compose(other)[source]

Compose this transform onto another

Parameters

other : Transform

transform that we compose onto

Returns

composed_transform : Transform

a transform implementing the composition of self on other

inv()[source]

Return the inverse affine transform.

Affine2D

class nipy.algorithms.registration.affine.Affine2D(array=None, radius=100)[source]

Bases: nipy.algorithms.registration.affine.Affine

__init__(array=None, radius=100)

Initialize self. See help(type(self)) for accurate signature.

param_inds = [0, 1, 5, 6, 7, 11]
apply(xyz)
as_affine(dtype='double')
compose(other)

Compose this transform onto another

Parameters

other : Transform

transform that we compose onto

Returns

composed_transform : Transform

a transform implementing the composition of self on other

copy()
from_matrix44(aff)

Convert a 4x4 matrix describing an affine transform into a 12-sized vector of natural affine parameters: translation, rotation, log-scale, pre-rotation (to allow for shearing when combined with non-unitary scales). In case the transform has a negative determinant, set the _direct attribute to False.

inv()

Return the inverse affine transform.

property is_direct
property param
property pre_rotation
property precond
property rotation
property scaling
property translation

Rigid

class nipy.algorithms.registration.affine.Rigid(array=None, radius=100)[source]

Bases: nipy.algorithms.registration.affine.Affine

__init__(array=None, radius=100)

Initialize self. See help(type(self)) for accurate signature.

param_inds = [0, 1, 2, 3, 4, 5]
from_matrix44(aff)[source]

Convert a 4x4 matrix describing a rigid transform into a 12-sized vector of natural affine parameters: translation, rotation, log-scale, pre-rotation (to allow for pre-rotation when combined with non-unitary scales). In case the transform has a negative determinant, set the _direct attribute to False.

apply(xyz)
as_affine(dtype='double')
compose(other)

Compose this transform onto another

Parameters

other : Transform

transform that we compose onto

Returns

composed_transform : Transform

a transform implementing the composition of self on other

copy()
inv()

Return the inverse affine transform.

property is_direct
property param
property pre_rotation
property precond
property rotation
property scaling
property translation

Rigid2D

class nipy.algorithms.registration.affine.Rigid2D(array=None, radius=100)[source]

Bases: nipy.algorithms.registration.affine.Rigid

__init__(array=None, radius=100)

Initialize self. See help(type(self)) for accurate signature.

param_inds = [0, 1, 5]
apply(xyz)
as_affine(dtype='double')
compose(other)

Compose this transform onto another

Parameters

other : Transform

transform that we compose onto

Returns

composed_transform : Transform

a transform implementing the composition of self on other

copy()
from_matrix44(aff)

Convert a 4x4 matrix describing a rigid transform into a 12-sized vector of natural affine parameters: translation, rotation, log-scale, pre-rotation (to allow for pre-rotation when combined with non-unitary scales). In case the transform has a negative determinant, set the _direct attribute to False.

inv()

Return the inverse affine transform.

property is_direct
property param
property pre_rotation
property precond
property rotation
property scaling
property translation

Similarity

class nipy.algorithms.registration.affine.Similarity(array=None, radius=100)[source]

Bases: nipy.algorithms.registration.affine.Affine

__init__(array=None, radius=100)

Initialize self. See help(type(self)) for accurate signature.

param_inds = [0, 1, 2, 3, 4, 5, 6]
from_matrix44(aff)[source]

Convert a 4x4 matrix describing a similarity transform into a 12-sized vector of natural affine parameters: translation, rotation, log-scale, pre-rotation (to allow for pre-rotation when combined with non-unitary scales). In case the transform has a negative determinant, set the _direct attribute to False.

property param
apply(xyz)
as_affine(dtype='double')
compose(other)

Compose this transform onto another

Parameters

other : Transform

transform that we compose onto

Returns

composed_transform : Transform

a transform implementing the composition of self on other

copy()
inv()

Return the inverse affine transform.

property is_direct
property pre_rotation
property precond
property rotation
property scaling
property translation

Similarity2D

class nipy.algorithms.registration.affine.Similarity2D(array=None, radius=100)[source]

Bases: nipy.algorithms.registration.affine.Similarity

__init__(array=None, radius=100)

Initialize self. See help(type(self)) for accurate signature.

param_inds = [0, 1, 5, 6]
property param
apply(xyz)
as_affine(dtype='double')
compose(other)

Compose this transform onto another

Parameters

other : Transform

transform that we compose onto

Returns

composed_transform : Transform

a transform implementing the composition of self on other

copy()
from_matrix44(aff)

Convert a 4x4 matrix describing a similarity transform into a 12-sized vector of natural affine parameters: translation, rotation, log-scale, pre-rotation (to allow for pre-rotation when combined with non-unitary scales). In case the transform has a negative determinant, set the _direct attribute to False.

inv()

Return the inverse affine transform.

property is_direct
property pre_rotation
property precond
property rotation
property scaling
property translation

Functions

nipy.algorithms.registration.affine.inverse_affine(affine)[source]
nipy.algorithms.registration.affine.preconditioner(radius)[source]

Computes a scaling vector pc such that, if p=(u,r,s,q) represents affine transformation parameters, where u is a translation, r and q are rotation vectors, and s is the vector of log-scales, then all components of (p/pc) are roughly comparable to the translation component.

To that end, we use a radius parameter which represents the ‘typical size’ of the object being registered. This is used to reformat the parameter vector (translation+rotation+scaling+pre-rotation) so that each element roughly represents a variation in mm.

nipy.algorithms.registration.affine.rotation_mat2vec(R)[source]

Rotation vector from rotation matrix R

Parameters

R : (3,3) array-like

Rotation matrix

Returns

vec : (3,) array

Rotation vector, where norm of vec is the angle theta, and the axis of rotation is given by vec / theta

nipy.algorithms.registration.affine.rotation_vec2mat(r)[source]

The rotation matrix is given by the Rodrigues formula:

R = Id + sin(theta)*Sn + (1-cos(theta))*Sn^2

with:

0 -nz ny

Sn = nz 0 -nx
-ny

nx 0

where n = r / ||r||

In case the angle ||r|| is very small, the above formula may lead to numerical instabilities. We instead use a Taylor expansion around theta=0:

R = I + sin(theta)/tetha Sr + (1-cos(theta))/teta2 Sr^2

leading to:

R = I + (1-theta2/6)*Sr + (1/2-theta2/24)*Sr^2

To avoid numerical instabilities, an upper threshold is applied to the angle. It is chosen to be a multiple of 2*pi, hence the resulting rotation is then the identity matrix. This strategy warrants that the output matrix is a continuous function of the input vector.

nipy.algorithms.registration.affine.slices2aff(slices)[source]

Return affine from start, step of sequence slices of slice objects

Parameters

slices : sequence of slice objects

Returns

aff : ndarray

If N = len(slices) then affine is shape (N+1, N+1) with diagonal given by the step attribute of the slice objects (where None corresponds to 1), and the :N elements in the last column are given by the start attribute of the slice objects

Examples

>>> slices2aff([slice(None), slice(None)])
array([[ 1.,  0.,  0.],
       [ 0.,  1.,  0.],
       [ 0.,  0.,  1.]])
>>> slices2aff([slice(2, 3, 4), slice(3, 4, 5), slice(4, 5, 6)])
array([[ 4.,  0.,  0.,  2.],
       [ 0.,  5.,  0.,  3.],
       [ 0.,  0.,  6.,  4.],
       [ 0.,  0.,  0.,  1.]])
nipy.algorithms.registration.affine.subgrid_affine(affine, slices)[source]

Return dot prodoct of affine and affine resulting from slices

Parameters

affine : array-like

Affine to apply on right of affine resulting from slices

slices : sequence of slice objects

Slices generating (N+1, N+1) affine from slices2aff, where N = len(slices)

Returns

aff : ndarray

result of np.dot(affine, slice_affine) where slice_affine is affine resulting from slices2aff(slices).

Raises

ValueError : if the slice_affine contains non-integer values

nipy.algorithms.registration.affine.threshold(x, th)[source]
nipy.algorithms.registration.affine.to_matrix44(t)[source]

t is a vector of affine transformation parameters with size at least 6.

size < 6 ==> error size == 6 ==> t is interpreted as translation + rotation size == 7 ==> t is interpreted as translation + rotation + isotropic scaling 7 < size < 12 ==> error size >= 12 ==> t is interpreted as translation + rotation + scaling + pre-rotation