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 :
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: |
|
---|---|
Returns: |
|
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)
Compute transformation matrix between 2 images from the angles in each directions.
Parameters: |
|
---|---|
Returns: |
|