NIPY logo

Site Navigation

NIPY Community

Table Of Contents

Previous topic

algorithms.optimize

This Page

algorithms.registration.affine

Module: algorithms.registration.affine

Inheritance diagram for nipy.algorithms.registration.affine:

Classes

Affine

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

Bases: nipy.algorithms.registration.transform.Transform

Methods

apply
as_affine
compose
inv
set_vector12
__init__(array=None, radius=100)
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

inv()

Return the inverse affine transform.

is_direct
param
pre_rotation
precond
rotation
scaling
set_vector12(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.

translation

Affine2D

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

Bases: nipy.algorithms.registration.affine.Affine

Methods

apply
as_affine
compose
inv
set_vector12
__init__(array=None, radius=100)
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

inv()

Return the inverse affine transform.

is_direct
param
pre_rotation
precond
rotation
scaling
set_vector12(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.

translation

Rigid

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

Bases: nipy.algorithms.registration.affine.Affine

Methods

apply
as_affine
compose
inv
set_vector12
__init__(array=None, radius=100)
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

inv()

Return the inverse affine transform.

is_direct
param
pre_rotation
precond
rotation
scaling
set_vector12(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.

translation

Rigid2D

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

Bases: nipy.algorithms.registration.affine.Rigid

Methods

apply
as_affine
compose
inv
set_vector12
__init__(array=None, radius=100)
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

inv()

Return the inverse affine transform.

is_direct
param
pre_rotation
precond
rotation
scaling
set_vector12(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.

translation

Similarity

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

Bases: nipy.algorithms.registration.affine.Affine

Methods

apply
as_affine
compose
inv
set_vector12
__init__(array=None, radius=100)
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

inv()

Return the inverse affine transform.

is_direct
param
pre_rotation
precond
rotation
scaling
set_vector12(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.

translation

Similarity2D

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

Bases: nipy.algorithms.registration.affine.Similarity

Methods

apply
as_affine
compose
inv
set_vector12
__init__(array=None, radius=100)
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

inv()

Return the inverse affine transform.

is_direct
param
pre_rotation
precond
rotation
scaling
set_vector12(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.

translation

Functions

nipy.algorithms.registration.affine.apply_affine(aff, pts)

Apply affine T to points pts

Parameters :

aff : (N, N) array-like

Homogenous affine, probably 4 by 4

pts : (P, N-1) array-like

Points, one point per row. N-1 is probably 3.

Returns :

transformed_pts : (P, N-1) array

transformed points

nipy.algorithms.registration.affine.inverse_affine(affine)
nipy.algorithms.registration.affine.matrix44(t)

t is a vector of 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

nipy.algorithms.registration.affine.preconditioner(radius)

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)

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)

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

nipy.algorithms.registration.affine.subgrid_affine(affine, slices)