Utils

Utilities for the affine transformations of the bounding box of the Free Form Deformation.

angles2matrix(rot_z=0, rot_y=0, rot_x=0)[source]

This method returns the rotation matrix for given rotations around z, y and x axes. The output rotation matrix is equal to the composition of the individual rotations. Rotations are counter-clockwise. The default value of the three rotations is zero.

Parameters:
  • rot_z (float) – rotation angle (in radians) around z-axis.

  • rot_y (float) – rotation angle (in radians) around y-axis.

  • rot_x (float) – rotation angle (in radians) around x-axis.

Returns:

rot_matrix: rotation matrix for the given angles. The matrix shape is always (3, 3).

Return type:

numpy.ndarray

Example:

>>> import pygem.affine as at
>>> import numpy as np
>>> from math import radians
>>> # Example of a rotation around x, y, z axis
>>> rotz = radians(10)
>>> roty = radians(20)
>>> rotx = radians(30)
>>> rot_matrix = at.angles2matrix(rotz, roty, rotx)

Note

  • The direction of rotation is given by the right-hand rule.

  • When applying the rotation to a vector, the vector should be column

    vector to the right of the rotation matrix.

fit_affine_transformation(points_start, points_end)[source]

Fit an affine transformation from starting points to ending points through a least square procedure.

Parameters:
Returns:

transform_vector: function that transforms a vector according to the affine map. It takes a source vector and return a vector transformed by the reduced row echelon form of the map.

Return type:

function

Example:

>>> import pygem.affine as at
>>> # Example of a rotation (affine transformation)
>>> p_start = np.array([[1,0,0], [0,1,0], [0,0,1], [0,0,0]])
>>> p_end = np.array([[0,1,0], [-1,0,0], [0,0,1], [0,0,0]])
>>> v_test = np.array([1., 2., 3.])
>>> transformation = at.affine_points_fit(p_start, p_end)
>>> v_trans = transformation(v_test)