linumpy.registration.sitk#

SimpleITK-based image registration and transform application.

Functions#

itk_registration(vol1, vol2[, _offset, metric, ...])

Use ITK::ImageRegistrationMethod.MutualInformation.

align_images_sitk(im1, im2)

Align two images using SimpleITK translation registration.

register_2d_images_sitk(ref_image, moving_image[, ...])

Register 2D moving_image to ref_image.

command_iteration(method)

Invoke when the optimization has an iteration.

apply_transform(moving_image, transform)

Apply transform to moving_image.

Module Contents#

linumpy.registration.sitk.itk_registration(vol1, vol2, _offset=(0, 0, 0), metric='MSQ', verbose=False, match_histograms=False, mask_fixed=None, mask_moving=None)[source]#

Use ITK::ImageRegistrationMethod.MutualInformation.

Parameters:
  • vol1 (ndarray) – Fixed image / volume

  • vol2 (ndarray) – Moving image / volume

  • offset ((3,) tuple) – Offset position relating the two volumes

  • metric (str) – Similarity metric to use for registration. Available metrics are : MSQ, JHMI, MMI, ANTsCorr, corr (default)

  • verbose (bool) – Verbose flag

  • match_histograms (bool) – If True, match histograms of moving and fixed volumes before registration.

  • mask_fixed (ndarray, optional) – Mask to apply to the fixed volume.

  • mask_moving (ndarray, optional) – Mask to apply to the moving volume.

  • _offset (tuple[float, float, float])

Returns:

  • (3,) tuple – Estimated deltas between these two volumes

  • float – Similarity metric

Return type:

tuple[list[float], float]

linumpy.registration.sitk.align_images_sitk(im1, im2)[source]#

Align two images using SimpleITK translation registration.

Parameters:
Return type:

tuple[list[float], float]

linumpy.registration.sitk.register_2d_images_sitk(ref_image, moving_image, method='euler', metric='MSE', max_iterations=2500, min_step=1e-12, grad_mag_tol=1e-12, fixed_mask=None, moving_mask=None, return_3d_transform=False, verbose=False, initial_translation=None, initial_step=None)[source]#

Register 2D moving_image to ref_image.

Parameters:
  • ref_image (numpy.ndarray) – The reference image.

  • moving_image (numpy.ndarray) – The image to register.

  • method (str) – The type of transform for registration. Choices are: “euler”, “affine” or “translation”.

  • metric (str) –

    The metric to optimize. Choices are:
    • ”MSE”: Mean-squared error

    • ”MI”: Mattes mutual information

    • ”AntsCC”: Ants neighbourhood cross-correlation

    • ”CC”: Cross-correlation

  • max_iterations (int) – Maximum number of iterations at each level of the multiscale pyramid (3 levels).

  • min_step (float) – Minimum step size for the gradient descent.

  • grad_mag_tol (float) – Gradient magnitude tolerance for gradient descent.

  • fixed_mask (numpy.ndarray) – Optional mask to apply to the reference image during registration.

  • moving_mask (numpy.ndarray) – Optional mask to apply to the moving image during registration.

  • return_3d_transform (bool) – If True, will return a 3D transform instead of 2D. Useful when the transform is applied to a 3D image.

  • verbose (bool) – If True, will log registrations metric at each iteration.

  • initial_translation (tuple or None) – Optional initial translation (tx, ty) to use as starting point. If None, uses CenteredTransformInitializer.

  • initial_step (float or None) – Initial step size for the optimizer. If None, uses 4.0 pixels. When initial_translation is provided, a smaller step (e.g., 1.0) is recommended.

Returns:

  • out_transform (sitk.sitkTransform) – Transform for bringing moving_image onto ref_image.

  • stop_condition (str) – String describing optimizer stopping condition.

  • error (float) – Registration metric value at the end of registration process.

Return type:

tuple[SimpleITK.Transform, str, float]

linumpy.registration.sitk.command_iteration(method)[source]#

Invoke when the optimization has an iteration.

Parameters:

method (SimpleITK.ImageRegistrationMethod)

Return type:

None

linumpy.registration.sitk.apply_transform(moving_image, transform)[source]#

Apply transform to moving_image.

The image is transformed inside its own domain.

Parameters:
  • moving_image (numpy.ndarray) – Moving image to transform.

  • transform (sitk.sitkTransform) – Transform to apply to moving_image.

Return type:

numpy.ndarray