linumpy.registration.refinement#

Refinement registration: best-Z search and small rotation/translation correction.

Functions#

find_best_z(fixed_vol, moving_slice, expected_z, ...)

Find the Z-index in fixed_vol that best matches moving_slice.

register_refinement(fixed, moving[, enable_rotation, ...])

Compute small rotation and translation refinement using SimpleITK.

centre_of_mass_offset(fixed, moving)

Compute alignment offset using center-of-mass difference.

gradient_magnitude_alignment(fixed, moving)

Compute alignment offset using phase correlation on gradient magnitude images.

Module Contents#

linumpy.registration.refinement.find_best_z(fixed_vol, moving_slice, expected_z, search_range)[source]#

Find the Z-index in fixed_vol that best matches moving_slice.

Uses normalized cross-correlation in the center region.

Parameters:
  • fixed_vol (array-like) – Fixed volume (Z, Y, X) or dask/zarr array.

  • moving_slice (np.ndarray) – 2D slice to match.

  • expected_z (int) – Expected Z-index in fixed_vol for the match.

  • search_range (int) – Search +/-search_range around expected_z.

Returns:

  • best_z (int) – Z-index giving the best correlation.

  • best_corr (float) – Correlation score at best_z.

Return type:

tuple[int, float]

linumpy.registration.refinement.register_refinement(fixed, moving, enable_rotation=True, max_rotation_deg=5.0, max_translation_px=20.0, fixed_mask=None, moving_mask=None, initial_offset=None)[source]#

Compute small rotation and translation refinement using SimpleITK.

Parameters:
  • fixed (np.ndarray) – 2D images for registration (should be normalized to [0, 1]).

  • moving (np.ndarray) – 2D images for registration (should be normalized to [0, 1]).

  • enable_rotation (bool) – Enable Euler2D rotation (default True). False = translation only.

  • max_rotation_deg (float) – Maximum allowed rotation in degrees.

  • max_translation_px (float) – Maximum allowed translation in pixels.

  • fixed_mask (np.ndarray or None) – Optional tissue masks multiplied into images before registration.

  • moving_mask (np.ndarray or None) – Optional tissue masks multiplied into images before registration.

  • initial_offset (tuple[float, float] or None) – Optional initial (dy, dx) translation offset for the transform.

Returns:

  • tx, ty (float) – Translation refinement in pixels.

  • angle_deg (float) – Rotation angle in degrees.

  • metric (float) – Registration metric value.

Return type:

tuple[float, float, float, float]

linumpy.registration.refinement.centre_of_mass_offset(fixed, moving)[source]#

Compute alignment offset using center-of-mass difference.

Parameters:
  • fixed (np.ndarray) – 2D normalized images (values in [0, 1]).

  • moving (np.ndarray) – 2D normalized images (values in [0, 1]).

Returns:

dy, dx – Translation from moving to fixed (fixed - moving offset).

Return type:

float

linumpy.registration.refinement.gradient_magnitude_alignment(fixed, moving)[source]#

Compute alignment offset using phase correlation on gradient magnitude images.

Parameters:
  • fixed (np.ndarray) – 2D normalized images (values in [0, 1]).

  • moving (np.ndarray) – 2D normalized images (values in [0, 1]).

Returns:

dy, dx – Translation from moving to fixed (fixed - moving offset).

Return type:

float