smlmlp.registrate_optimize_images module

smlmlp.registrate_optimize_images(channels, /, mode='mean', channels_x_shifts_nm=None, channels_y_shifts_nm=None, channels_rotations_deg=None, channels_x_shears=None, channels_y_shears=None, optimized=None, *, channels_pixels_nm=1.0, cuda=False, parallel=False)[source]

Transform and normalize channel images to facilitate registration.

This function rescales each channel to a common reference pixel size, applies geometric transformations, and compresses the intensity range in order to produce registration-friendly images.

Parameters:
  • channels (sequence of ndarray) – Sequence of image stacks, one per channel.

  • mode ({"mean", "std"}, optional) – Projection used to reduce each channel stack before registration.

  • channels_x_shifts_nm (sequence of float) – Per-channel shifts along x, in nanometers.

  • channels_y_shifts_nm (sequence of float) – Per-channel shifts along y, in nanometers.

  • channels_rotations_deg (sequence of float) – Per-channel rotations, in degrees.

  • channels_x_shears (sequence of float) – Per-channel shear values along x.

  • channels_y_shears (sequence of float) – Per-channel shear values along y.

  • optimized (sequence of ndarray or None, optional) – Optional preallocated output arrays for the transformed images. If provided with larger arrays, centered spatial views are reused when possible.

  • channels_pixels_nm (float or sequence, optional) – Pixel size in nanometers. Can be scalar, (y, x), or per-channel.

  • cuda (bool, optional) – Whether to enable CUDA processing.

  • parallel (bool, optional) – Whether to enable parallel processing.

Returns:

A tuple (new_optimized, info) where:

  • new_optimized is the list of transformed and compressed images,

  • info is a dictionary containing reusable intermediate results.

The dictionary contains the following keys:

'channels_pixels_nm'

Normalized per-channel pixel sizes.

'ref_pix'

Reference pixel size used for the common scaling.

'scales_x'

Per-channel x scaling factors.

'scales_y'

Per-channel y scaling factors.

'crop_shape'

Common centered crop shape applied after transformation.

'crop_bboxes'

Per-channel centered crop boxes as (x0, y0, x1, y1).

Return type:

tuple

Examples

>>> import numpy as np
>>> channels = [np.random.rand(5, 16, 16).astype(np.float32)]
>>> optimized, info = registrate_optimize_images(
...     channels,
...     channels_x_shifts_nm=[0.0],
...     channels_y_shifts_nm=[0.0],
...     channels_rotations_deg=[0.0],
...     channels_x_shears=[0.0],
...     channels_y_shears=[0.0],
... )
>>> len(optimized)
1
>>> info["ref_pix"]
(1.0, 1.0)
>>> channels = [
...     np.random.rand(5, 16, 16).astype(np.float32),
...     np.random.rand(5, 16, 16).astype(np.float32),
... ]
>>> optimized, info = registrate_optimize_images(
...     channels,
...     channels_x_shifts_nm=[0.0, 20.0],
...     channels_y_shifts_nm=[0.0, -10.0],
...     channels_rotations_deg=[0.0, 1.0],
...     channels_x_shears=[0.0, 0.01],
...     channels_y_shears=[0.0, -0.01],
...     channels_pixels_nm=[(100.0, 100.0), (110.0, 120.0)],
... )
>>> len(info["scales_x"])
2