image.registration.registration.pts2transfo(x, y)[source]

Infer rigid transformation from control point pairs using quaternions.

The quaternion representation is used to register two point sets with known correspondences. It computes the rigid transformation as a solution to a least squares formulation of the problem.

The rigid transformation, defined by the rotation R and the translation t, is optimized by minimizing the following cost function :

C(R,t) = sum ( |yi - R.xi - t|^2 )

The optimal translation is given by :

t_ = y_b - R.x_b

with x_b and y_b the barycenters of two point sets

The optimal rotation using quaternions is optimized by minimizing the following cost function :

C(q) = sum ( |yi'*q - q*xi'|^2 )

with yi' and xi' converted to barycentric coordinates and identified by quaternions

With the matrix representations :

yi'*q - q*xi' = Ai.q

C(q) = q^T.|sum(A^T.A)|.q = q^T.B.q

with A = array([ [ 0 , (xn_i - yn_i) , (xn_j - yn_j) , (xn_k - yn_k) ],
[-(xn_i - yn_i) , 0 , (-xn_k - yn_k) , (xn_j + yn_j) ], [-(xn_j - yn_j) , -(-xn_k - yn_k), 0 , (-xn_i - yn_i)], [-(xn_k - yn_k) , -(xn_j + yn_j) , -(-xn_i - yn_i), 0 ] ])

The unit quaternion representing the best rotation is the unit eigenvector corresponding to the smallest eigenvalue of the matrix -B :

v = a, b.i, c.j, d.k

The orthogonal matrix corresponding to a rotation by the unit quaternion v = a + bi + cj + dk (with |z| = 1) is given by :

R = array([ [a*a + b*b - c*c - d*d, 2bc - 2ad , 2bd + 2ac ],
[ 2bc + 2ad , a*a - b*b + c*c - d*d, 2cd - 2ab ], [ 2bd - 2ac , 2cd + 2ab , a*a - b*b - c*c + d*d] ])
Parameters:
  • x (list) - list of points
  • y (list) - list of points
Returns:
T : array_like (R,t) which correspond to the optimal rotation and translation
T = | R t |
0 1 |

T.shape(4,4)

Examples:
>>> from openalea.image import pts2transfo
>>> # x and y, two point sets with 7 known correspondences
>>> x = [[238.*0.200320, 196.*0.200320, 9.],
         [204.*0.200320, 182.*0.200320, 11.],
         [180.*0.200320, 214.*0.200320, 12.],
         [201.*0.200320, 274.*0.200320, 12.],
         [148.*0.200320, 225.*0.200320, 18.],
         [248.*0.200320, 252.*0.200320, 8.],
         [305.*0.200320, 219.*0.200320, 10.]]
>>> y = [[173.*0.200320, 151.*0.200320, 17.],
         [147.*0.200320, 179.*0.200320, 16.],
         [165.*0.200320, 208.*0.200320, 12.],
         [226.*0.200320, 204.*0.200320, 9.],
         [170.*0.200320, 254.*0.200320, 10.],
         [223.*0.200320, 155.*0.200320, 13.],
         [218.*0.200320, 109.*0.200320, 23.]]
>>> cp2transfo(x,y)
array([[ 0.40710149, 0.89363883, 0.18888626, -22.0271968 ],
[ -0.72459862, 0.19007589, 0.66244094, 51.59203463], [ 0.55608022, -0.40654742, 0.72490964, -0.07837002], [ 0. , 0. , 0. , 1. ]])
image.registration.registration.angles2transfo(image1, image2, angleX=0, angleY=0, angleZ=0)[source]

Compute transformation matrix between 2 images from the angles in each directions.

Parameters:
  • image1 (|SpatialImage|) -
  • image2 (|SpatialImage|) -
  • angleX (int) - Rotation through angleX (degree)
  • angleY (int) - Rotation through angleY (degree)
  • angleZ (int) - Rotation through angleZ (degree)
Returns:
  • matrix (numpy array) - Transformation matrix

This Page