bartorch.register_affine

bartorch.register_affine#

bartorch.register_affine(reference, moved, *, transform='rigid', reference_mask=None, moved_mask=None)#

Affine transform that maps reference onto moved, by mutual information.

Registers magnitudes over a three-level Gaussian pyramid.

Parameters:
  • reference (torch.Tensor) – Images of C shape (z, y, x) or (y, x); any further leading axis must have size one. A reference without z, or with z of size one, is registered in two dimensions.

  • moved (torch.Tensor) – Images of C shape (z, y, x) or (y, x); any further leading axis must have size one. A reference without z, or with z of size one, is registered in two dimensions.

  • transform ({"translation", "rigid", "affine"}) – Degrees of freedom: translation only (-T), rotation and translation (-R), or all (-A).

  • reference_mask (torch.Tensor, optional) – Binary masks shaped like their image (--mask-reference, --mask-moved); both or neither.

  • moved_mask (torch.Tensor, optional) – Binary masks shaped like their image (--mask-reference, --mask-moved); both or neither.

Returns:

Real (k, k + 1) matrix [A | t], k two or three, whose rows and columns are the last k axes in C order. It maps a position in reference to the position in moved that lands there, p_moved = A @ p_ref + t, each in its own grid’s field-of-view units (index - n // 2) / n (motion/affine.c:152-171, :428-465): content of moved displaced by d voxels along the last axis gives t[-1] = d / n. This is what bartorch.affine_transform() takes: affine_transform(moved, matrix, axes=tuple(range(-k, 0))) resamples moved onto reference.

Return type:

torch.Tensor