mymesh.register.Mesh2Mesh#
- mymesh.register.Mesh2Mesh(M1, M2, T0=None, bounds=None, transform='rigid', metric='icp', method='icp', decimation=1, transform_args={}, optimizer_args=None, verbose=True)[source]#
Mesh-to-mesh registration. M2 will be aligned to M1.
- Parameters:
M1 (mymesh.mesh) – Fixed mesh that M2 will be aligned to
M2 (mymesh.mesh) – Moving mesh that will be aligned to M1
T0 (array_like or NoneType, optional) – Initial transformation to apply to M2, by default, None. This can serve as an ‘initial guess’ of the alignment.
bounds (array_like or NoneType, optional) – Optimization bounds, formatted as [(min,max),…] for each parameter. If None, bounds are selected that should cover most possible transformations, by default None. Not used by all optimizers.
transform (str, optional) –
Transformation model, by default ‘rigid’.
’rigid’: translations and rotations
’similarity: translations, rotations, and uniform scaling
’affine’: translations, rotations, triaxial scaling, shearing
metric (str, optional) – Similarity metric to compare the two point clouds, by default ‘closest_point_MSE’
method (str, optional) – Optimization method, by default ‘direct’. See
optimize()for details.decimation (float, optional) – Scalar factor in the range (0,1] used to reduce the size of the point set, by default 1.
decimation = 1uses the full point sets, numbers less than one will reduce the size of both point sets by that factor by randomly selecting a set of points to use. For exampledecimation = 0.5will use only half of the points of each set. A random seed of 0 is used for repeatable results. Note that if verbose=True, the final score will be reported for the full point set, not the decimated point set used during optimization.transform_args (dict, optional) – Additional arguments for the chosen transformation model, by default {}. See
rigid(),similarity(), oraffine().optimizer_args (dict, optional) – Additional arguments for the chosen optimizer, by default None. See
optimize()for details.verbose (bool, optional) – Verbosity, by default True. If True, iteration progress will be printed.
- Returns:
Mnew (mymesh.mesh) – Transformed transformed mesh registered to M1.
T (np.ndarray) – Affine transformation matrix (shape=(4,4)) to transform M2 to Mnew.
Mnew.NodeCoords = transform_points(M.NodeCoords, T)
Examples
import mymesh from mymesh import register import numpy as np # Load two versions of the stanford bunny (fine and coarsened) m1 = mymesh.demo_mesh('bunny') m2 = mymesh.demo_mesh('bunny-res2') # Perform an arbitrary rotation to the copy R = register.rotation([np.pi/6, -np.pi/6, np.pi/6]) m2.NodeCoords = register.transform_points(m2.NodeCoords, R) # Align the two meshes using the iterative closest point (ICP) algorithm m_aligned, T = register.Mesh2Mesh(m1, m2, method='icp')