mymesh.register.AxisAlignImage#

mymesh.register.AxisAlignImage(img, axis_order=[2, 1, 0], threshold=None, center='image', scale=1, interpolation_order=1, transform_args=None, return_transformed=True, return_transform=False)[source]#

Align an object in an image to the x, y, z axes. This works by identifying the minimum volume bounding box (see :func:~`mymesh.utils.MVBB`) and aligning that box to the principal axes, so objects with rounded objects with ambiguous orientation may be oriented seemingly-arbitrarily.

Parameters:
  • img (array_like) – 3 dimensional image array of the image

  • axis_order (array_like, optional) – Orientation of the aligned image in terms of the lengths of each side of the object, by default [0,1,2]. The first axis will correspond to the shortest side of the object and the last index to the longest side. For example, with [0,1,2], the longest side will be aligned with the z (2) axis, and the shortest will be aligned with the x (0) axis. Must be a combination of 0, 1, and 2. Threshold value used to binarize the image for identification of the object. If the image is already binarized, this is not necessary, by default None.

  • center (str, array_like, or NoneType, optional) –

    Location of the center of the object after axis alignment, by default ‘image’. Options are:

    • ’image’: Centers the object at the center of the image

    • ’object’: Keeps the center of the object in place

    • [x,y,z]: A three element list or array specifies the location, in voxels, of where to place to place the center of the bounding box of the object after transformation.

  • scale (float, optional) – Scale factor used to resample the image to either reduce (scale < 1) or increase (scale > 1) the size/resolution of the image used for alignment, by default 1. The returned image will still be of the original resolution.

  • interpolation_order (int, optional) – Interpolation order used in image scaling and transformation (see scipy.ndimage.zoom) and scaling (if used). Must be an integer in the range 0-5. Lower order is more efficient at the cost of quality. By default, 1.

  • transform_args (dict, optional) – Optional input arguments passed to scipy.ndimage.affine_transform, by default dict(mode=’constant’, order=interpolation_order).

  • return_transform (bool, optional) – Option to return the transformation matrix as well as the transformed point cloud, by default False

Returns:

  • transformed (np.ndarray) – Array of point coordinates transformed to be aligned to the axes

  • transform (np.ndarray, optional) – Affine transformation matrix (shape=(4,4)) to transform img to transformed. Only returned if return_transform = True.