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', inverse=False, *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 alignment methods

  • **kwargs – The keyword arguments used for the alignment 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
static contPoints(mv=None, sv=None)

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

Parameters
  • mv (ndarray) – The array of control points to be moved

  • sv (ndarray) – The array of control points

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
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

getAlign()

Return the aligned AmpObject

getRMSE()

Return the RMSE post alignment

getRT()

Return the rotation and translation array

getTForm()

Return the transformation array

idxPoints(mv=None, sv=None)

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

Parameters
  • mv (ndarray) – The index array of moving vertices to be aligned

  • sv (ndarray) – The index array of static vertices to be aligned to

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, mv = [0, 1, 2], sv = [0, 1, 2], method='idxPoints').m
inverse(method='linPoint2Plane', *args, **kwargs)
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
optZVol(z0=0)

Direct minimisation of the volume. 1) Translate moving object to match minZ of static 2) Calculate volume to static z0 3) Cumulative sum the slices and evaluate volume 4) Find slice nearest volume of static

Parameters

opt (z0, default 0) – The slice height to evaluate the static volume from

Returns

  • R (ndarray) – The optimal rotation array, rotation

  • T (ndarray) – The optimal translation array

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 alignment methods

  • **kwargs – The keyword arguments used for the alignment methods

setMoving(amp)

Set the moving AmpObject

setStatic(amp)

Set the static AmpObject