FireANTs Registration

RegisterImagesFireants provides GPU-accelerated rigid, affine, and deformable image registration using the FireANTs backend.

Class Reference

class monai_physio.RegisterImagesFireants(log_level=20)[source]

Bases: RegisterImagesBase

FireANTs-based image registration implementation.

This class extends RegisterImagesBase to provide rigid, affine, and deformable image registration on the GPU using FireANTs. FireANTs transforms are expressed in physical (LPS) coordinates as y = A x + t from the fixed to the moving image, which is the ITK fixed_to_moving_transform directly.

number_of_iterations

List of iterations per level (e.g. [40, 20, 10]). Level i of n runs at downsampling factor 2 ** (n - 1 - i).

transform_type

‘Deformable’, ‘Affine’, or ‘Rigid’

metric

‘CC’ (-> cc), ‘Mattes’ (-> mi), or ‘MeanSquares’ (-> mse)

scales

Optional explicit downsampling factor per level (coarse to fine); when None they follow from number_of_iterations.

init_affine

Source of the deformable stage’s initial transform: ‘Affine’ (FireANTs affine registration) or ‘Identity’ (none).

deformable_options

Keyword arguments forwarded to FireANTs’ GreedyRegistration (see set_deformable_options).

__init__(log_level=20)[source]

Initialize the FireANTs image registration class.

Parameters:

log_level (int | str) – Logging level (default: logging.INFO)

set_number_of_iterations(number_of_iterations)[source]

Set the number of iterations per resolution level.

Parameters:

number_of_iterations (list[int]) – List of iterations (e.g. [40, 20, 10]).

Return type:

None

set_transform_type(transform_type)[source]

Set the type of transform: Deformable, Affine, or Rigid.

Parameters:

transform_type (str) – ‘Deformable’, ‘Affine’, or ‘Rigid’.

Return type:

None

set_metric(metric)[source]

Set the similarity metric (CC, Mattes->mi, MeanSquares->mse).

Parameters:

metric (str) – ‘CC’, ‘Mattes’, or ‘MeanSquares’.

Return type:

None

set_scales(scales)[source]

Set the downsampling factor per level (one per iteration entry).

Parameters:

scales (Optional[list[float]]) – Factors in descending order (e.g. [4, 2, 1]), or None to derive them from the number of iterations.

Return type:

None

set_init_affine(init_affine)[source]

Set the initial transform of the deformable stage.

Parameters:

init_affine (str) – ‘Affine’ to register an affine first, or ‘Identity’.

Return type:

None

set_deformable_options(**options)[source]

Set GreedyRegistration options for the deformable stage.

Parameters:

**options (Any) – Any of cc_kernel_size, cc_kernel_type, smooth_grad_sigma, smooth_warp_sigma, optimizer, optimizer_lr, deformation_type, integrator_n, blur, max_tolerance_iters, tolerance.

Return type:

None

configure_for_heart_ct()[source]

Apply the tuned deformable settings for cardiac 4D CT.

Values from experiments/Registration-Fireants_vs_Greedy/results/REPORT.md: deformable-only (identity initial transform) CC registration.

Return type:

None

configure_for_lung_ct()[source]

Apply the tuned deformable settings for lung 4D CT.

Values from experiments/Registration-Fireants_vs_Greedy/results/REPORT.md: deformable-only (identity initial transform) CC registration at coarser scales than the heart.

Return type:

None

registration_method(moving_image, moving_mask=None, moving_labelmap=None, moving_image_pre=None)[source]

Register moving image to fixed image using FireANTs.

Returns a dict with “fixed_to_moving_transform”, “moving_to_fixed_transform”, and “loss”. As with the other image-registration backends, fixed_to_moving_transform warps the moving image onto the fixed grid and moving_to_fixed_transform warps the fixed image onto the moving grid; point and landmark warps use the opposite transform from image warps (see docs/developer/transform_conventions).

Raises:
  • ValueError – If the fixed image is not set.

  • NotImplementedError – For moving_labelmap or fixed_labelmap, which FireANTs cannot use as a similarity term. Masks are used through the FireANTs masked loss; a mask on only one image is paired with an all-ones mask on the other.

Return type:

dict[str, Union[Transform, float]]

Basic Registration

import itk

from monai_physio import RegisterImagesFireants

fixed = itk.imread("reference.mha")
moving = itk.imread("moving.mha")

registrar = RegisterImagesFireants()
registrar.set_modality("ct")
registrar.set_fixed_image(fixed)

result = registrar.register(moving)

fixed_to_moving_transform = result["fixed_to_moving_transform"]
moving_to_fixed_transform = result["moving_to_fixed_transform"]
registered = registrar.get_registered_image()

Installation Note

RegisterImagesFireants requires the fireants package, which is not installed by default. Install it without its dependencies, so that it does not replace the CUDA build of PyTorch already in the environment:

pip install fireants --no-deps

See Also