microcorrelate.napari#

This module contains functions intendend for interactive landmark-based registration with Napari.

Classes#

NapariRegistrator

Interactive landmark-based image registrator using a Napari viewer.

ViewerParams

Visual parameters for the NapariRegistrator viewer.

Module Contents#

class microcorrelate.napari.NapariRegistrator(fixed_data: numpy.ndarray, moving_data: numpy.ndarray, fixed_spacing: tuple[float, float], moving_spacing: tuple[float, float], transform_type: Literal['affine', 'rigid', 'similarity'] = 'affine', fixed_channel_axis: int | None = None, moving_channel_axis: int | None = None, viewer_params: ViewerParams | None = None)#

Interactive landmark-based image registrator using a Napari viewer.

Place matching point pairs on the landmarks_fixed and landmarks_moving layers, then close the viewer to trigger transform estimation and resampling of the moving image onto the fixed grid.

Parameters:
  • fixed_data (np.ndarray) – Reference image. The moving image will be registered onto this grid.

  • moving_data (np.ndarray) – Moving image to be registered.

  • fixed_spacing (tuple[float, float]) – Pixel pitch of the fixed image (row, col) in physical units.

  • moving_spacing (tuple[float, float]) – Pixel pitch of the moving image (row, col) in physical units.

  • transform_type ({"affine", "rigid", "similarity"}, optional) – Type of spatial transform to estimate. Default is "affine".

  • fixed_channel_axis (int, optional) – Channel axis index in fixed_data, or None for single-channel.

  • moving_channel_axis (int, optional) – Channel axis index in moving_data, or None for single-channel.

  • viewer_params (ViewerParams, optional) – Visual parameters for the Napari viewer. If None, uses ViewerParams defaults.

fixed_image#

Fixed image converted to SimpleITK format (for internal use).

Type:

sitk.Image

transform#

Estimated spatial transform. Populated after calling run().

Type:

sitk.Transform

resampled_data#

Registered moving image. Populated after calling run().

Type:

np.ndarray

See also

ViewerParams

Visual settings for the Napari viewer.

Examples

Register a two-photon microscopy image to an SEM image:

from microcorrelate.napari import NapariRegistrator

registrator = NapariRegistrator(
    fixed_data=sem_image,
    moving_data=tpef_image,
    fixed_spacing=(0.15, 0.15),
    moving_spacing=(1.3, 1.3),
    transform_type='affine'
)

# Opens napari viewer for interactive landmark placement
registrator.run()

# After closing viewer, access results
registered_image = registrator.resampled_data
transform = registrator.transform

Visualize the registration result:

# After running registration
registrator.show_registered()
register_image(moving_array: numpy.ndarray, moving_spacing: tuple[float, float], moving_channel_axis: int | None = None, default_value: float = 0.0) numpy.ndarray#

Apply transform and resample moving image onto fixed image grid.

Parameters:
  • moving_array (np.ndarray) – Moving image array.

  • moving_spacing (Tuple[float, float]) – Moving image pixel pitch (row, col).

  • moving_channel_axis (int | None) – Index of the channel axis of the moving image, if present. If None, the image is treated as single channel.

  • default_value (float) – Fill value for regions outside moving image bounds.

Returns:

Registered image on fixed image grid.

Return type:

np.ndarray

run(verbose=False) None#

Open a Napari viewer for interactive landmark placement and run registration.

Place matching point pairs on the landmarks_fixed and landmarks_moving layers, then close the viewer window to trigger transform estimation and resampling of the moving image.

Parameters:

verbose (bool) – If True, print progress messages. Default is False.

Raises:

ValueError – If landmark counts don’t match or fewer than 3 points provided.

show_registered()#

Show the resampled image overlaid to the fixed image

class microcorrelate.napari.ViewerParams#

Visual parameters for the NapariRegistrator viewer.

fixed_color#

Colormap name for the fixed image layer. Default is "green".

Type:

str

moving_color#

Colormap name for the moving image layer. Default is "magenta".

Type:

str

pts_size#

Size of landmark points in data units. Default is 10.0.

Type:

float

pts_border_width#

Relative border width of landmark points (0-1). Default is 0.2.

Type:

float

pts_border_color#

Border color of landmark points. Default is "white".

Type:

str

text_color#

Color of the point index labels. Default is "white".

Type:

str

text_size#

Font size of the point index labels. Default is 12.

Type:

int

text_anchor#

Anchor position for the point index labels. Default is "upper_right".

Type:

str