atlannot.ants package

Module contents

Registration using ANTsPy.

atlannot.ants.check_dtype_antspy(array: ndarray) None[source]

Check whether dtype compatible with ANTsPy.

Parameters:

array – Any numpy array.

Raises:

TypeError

atlannot.ants.register(fixed, moving, **ants_kwargs)[source]

Perform an intensity-based registration.

Parameters:
  • fixed (np.ndarray) – The fixed reference image. The dtype should be one of: float64, float32, uint32, uint8.

  • moving (np.ndarray) – The moving image that will be registered to the fixed image. The dtype should be one of: float64, float32, uint32, uint8.

  • ants_kwargs – Any additional registration parameters as specified in the documentation for ants.registration.

Returns:

nii_data – The transformation of the moving image encoded in displacement fields. The shape will depend on whether the registration is 2D or 3D. For 2D inputs with shape (a, b) the output will have shape (a, b, 1, 1, 2), for 3D inputs with shape (a, b, c) the output will have shape (a, b, c, 1, 3). The last axis always contains the displacement vectors. This data can be used directly in the transform function.

Return type:

np.ndarray

Raises:
  • ValueError – If the shapes of the input images don’t match or the d-type of input images is not float32 or uint32.

  • RuntimeError – If the resulting transform produced by ANTsPy doesn’t have the expected form.

atlannot.ants.stack_2d_transforms(nii_data_array)[source]

Convert a stack of 2D transforms into one 3D transform.

Instead of transforming moving images slice by slice the 2D transformations can be stacked into a 3D transformation with zero displacement along the z-axis and then applied directly to the 3D volume of slices.

Parameters:

nii_data_array (sequence of array_like) – A sequence of transforms produced by registering a number of 2D slices.

Returns:

nii_data_3d – The combined 3D transform.

Return type:

np.ndarray

atlannot.ants.transform(image, nii_data, **ants_kwargs)[source]

Apply a transform to an image.

Parameters:
  • image (np.ndarray) – The image to transform.

  • nii_data (np.ndarray) – The transformation as returned by the register function.

  • ants_kwargs

    Additional transformation parameters as specified in the documentation for ants.apply_transforms. Should not contain any of these parameters:

    • fixed

    • moving

    • transforms

    A useful parameter that can be specified in ants_kwargs is interpolator. For transforming usual images it can be set to “linear”, while for annotation atlases the value “genericLabel” is more appropriate. See the ANTsPy documentation for more details.

Returns:

warped – The warped image.

Return type:

np.ndarray

Raises:
  • ValueError – If d-type of the input image is not float32.

  • RuntimeError – Whenever the internal call of ants.apply_transforms fails.