align module

Package for dealing with alignment methods between two AmpObject meshes Copyright: Joshua Steer 2020, Joshua.Steer@soton.ac.uk

class align(moving, static, method='linPoint2Plane', *args, **kwargs)

Bases: object

Automated alignment methods between two meshes

Parameters:
  • moving (AmpObject) – The moving AmpObject that is to be aligned to the static object
  • static (AmpObject) – The static AmpObject that the moving AmpObject that the moving object will be aligned to
  • method (str, default 'linPoint2Plane') – A string of the method used for alignment
  • *args – The arguments used for the registration methods
  • **kwargs – The keyword arguments used for the registration methods
Returns:

m – The aligned AmpObject, it same number of vertices and face array as the moving AmpObject Access this using align.m

Return type:

AmpObject

Examples

>>> static = AmpObject(staticfh)
>>> moving = AmpObject(movingfh)
>>> al = align(moving, static).m
display()

Display the static mesh and the aligned within an interactive VTK window

genIm(crop=False)

Display the static mesh and the aligned within an interactive VTK window

static linPoint2Plane(mv, sv, sn)

Iterative Closest Point algorithm which relies on using least squares method from converting the minimisation problem into a set of linear equations. This uses a

Parameters:
  • mv (ndarray) – The array of vertices to be moved
  • sv (ndarray) – The array of static vertices, these are the face centroids of the static mesh
  • sn (ndarray) – The normals of the point in teh static array, these are derived from the normals of the faces for each centroid
Returns:

  • R (ndarray) – The optimal rotation array
  • T (ndarray) – The optimal translation array

References

[1]Besl, Paul J.; N.D. McKay (1992). “A Method for Registration of 3-D Shapes”. IEEE Trans. on Pattern Analysis and Machine Intelligence (Los Alamitos, CA, USA: IEEE Computer Society) 14 (2): 239-256.
[2]Chen, Yang; Gerard Medioni (1991). “Object modelling by registration of multiple range images”. Image Vision Comput. (Newton, MA, USA: Butterworth-Heinemann): 145-155

Examples

>>> static = AmpObject(staticfh)
>>> moving = AmpObject(movingfh)
>>> al = align(moving, static, method='linPoint2Plane').m
static linPoint2Point(mv, sv)

Point-to-Point Iterative Closest Point algorithm which relies on using singular value decomposition on the centered arrays.

Parameters:
  • mv (ndarray) – The array of vertices to be moved
  • sv (ndarray) – The array of static vertices, these are the face centroids of the static mesh
Returns:

  • R (ndarray) – The optimal rotation array
  • T (ndarray) – The optimal translation array

References

[1]Besl, Paul J.; N.D. McKay (1992). “A Method for Registration of 3-D Shapes”. IEEE Trans. on Pattern Analysis and Machine Intelligence (Los Alamitos, CA, USA: IEEE Computer Society) 14 (2): 239-256.
[2]Chen, Yang; Gerard Medioni (1991). “Object modelling by registration of multiple range images”. Image Vision Comput. (Newton, MA, USA: Butterworth-Heinemann): 145-155

Examples

>>> static = AmpObject(staticfh)
>>> moving = AmpObject(movingfh)
>>> al = align(moving, static, method='linPoint2Point').m
static optDistError(X, mv, sv)

The function to minimise. It performs the affine transformation then returns the rmse between the two vertex sets

Parameters:
  • X (ndarray) – The affine transformation corresponding to [Rx, Ry, Rz, Tx, Ty, Tz]
  • mv (ndarray) – The array of vertices to be moved
  • sv (ndarray) – The array of static vertices, these are the face centroids of the static mesh
Returns:

err – The RMSE between the two meshes

Return type:

float

static optPoint2Point(mv, sv, opt='L-BFGS-B')

Direct minimisation of the rmse between the points of the two meshes. This method enables access to all of Scipy’s minimisation algorithms

Parameters:
  • mv (ndarray) – The array of vertices to be moved
  • sv (ndarray) – The array of static vertices, these are the face centroids of the static mesh
  • opt (str, default 'L_BFGS-B') – The string of the scipy optimiser to use
Returns:

  • R (ndarray) – The optimal rotation array
  • T (ndarray) – The optimal translation array

Examples

>>> static = AmpObject(staticfh)
>>> moving = AmpObject(movingfh)
>>> al = align(moving, static, method='optPoint2Point', opt='SLSQP').m
static rot2quat(R)

Convert a rotation matrix to a quaternionic matrix

Parameters:R (array_like) – The 3x3 rotation array to be converted to a quaternionic matrix
Returns:Q – The quaternionic matrix
Return type:ndarray
runICP(method='linPoint2Plane', maxiter=20, inlier=1.0, initTransform=None, *args, **kwargs)

The function to run the ICP algorithm, this function calls one of multiple methods to calculate the affine transformation

Parameters:
  • method (str, default 'linPoint2Plane') – A string of the method used for alignment
  • maxiter (int, default 20) – Maximum number of iterations to run the ICP algorithm
  • inlier (float, default 1.0) – The proportion of closest points to use to calculate the transformation, if < 1 then vertices with highest error are discounted
  • *args – The arguments used for the registration methods
  • **kwargs – The keyword arguments used for the registration methods