tools.RigidRegistration#

class bartorch.tools.RigidRegistration#

Bases:

Multi-resolution rigid registration of magnitude images with SimpleITK.

Regular-step gradient descent over an Euler transform initialized at the images’ geometric centres, with linear interpolation. Complex inputs are registered by their modulus, and both images are normalized to zero mean and unit standard deviation.

Parameters:
  • metric ({"correlation", "mutual_information", "mean_squares"}, default='correlation') – Similarity metric; mutual information uses 32 histogram bins.

  • iterations (int, default=50) – Optimizer iterations per resolution level.

  • sampling_percentage (float, default=0.2) – Fraction of voxels the metric samples at random, with a fixed seed. One samples every voxel.

  • shrink_factors (sequence of int, default=(4, 2, 1)) – Pyramid shrink factor per level, coarsest first.

  • smoothing_sigmas (sequence of float, default=(2.0, 1.0, 0.0)) – Gaussian smoothing per level, in physical units.

  • learning_rate (float, default=1.0) – Initial optimizer step.

  • min_step (float, default=0.0001) – Step at which the optimizer stops.

  • threads (int, default=1) – ITK threads for the registration. ITK’s thread count is process-wide; it is set for the call and restored after it.

Examples

>>> estimate = RigidRegistration()(fixed, moving, spacing=(1.0, 1.0))
>>> estimate.parameters  # (angle, tx, ty)
estimate()#

Register moving to fixed.

Parameters:
  • fixed (torch.Tensor or numpy.ndarray) – One 2D or 3D image each, after squeezing singleton axes.

  • moving (torch.Tensor or numpy.ndarray) – One 2D or 3D image each, after squeezing singleton axes.

  • initial (RigidMotionEstimate, default=None) – Starting parameters; the geometric-centre initialization otherwise.

  • spacing (sequence of float, default=None) – Voxel size per axis in SimpleITK (x, y[, z]) order; one otherwise. Translations come back in its unit.

Returns:

The transform mapping points of fixed into moving, with the final metric value and the optimizer’s stop condition.

Return type:

RigidMotionEstimate

resample()#

Resample moving onto the grid of reference through estimate.

Parameters:
  • moving (torch.Tensor or numpy.ndarray) – Image to resample; complex values are resampled by their modulus.

  • estimate (RigidMotionEstimate) – Transform from the reference grid into moving, as estimate() returns it.

  • reference (torch.Tensor or numpy.ndarray, default=None) – Image whose grid is resampled onto; the grid of moving otherwise.

  • spacing (sequence of float, default=None) – Voxel size, as in estimate().

  • default_value (float, default=0.0) – Value outside moving.

Returns:

Real float32 image on the grid of reference, on the device of moving when it is a tensor.

Return type:

torch.Tensor

__call__()#

estimate().