linumpy.stack_alignment.units#

Unit conversion and centring for inter-slice shift fields.

Functions#

detect_shift_units(resolution)

Detect whether resolution is in mm or µm and return (res_x_um, res_y_um).

convert_shifts_to_pixels(cumsum_mm, resolution_um)

Convert mm cumulative shifts to pixel shifts.

center_shifts(cumsum_px, slice_ids)

Center shifts around the middle slice.

Module Contents#

linumpy.stack_alignment.units.detect_shift_units(resolution)[source]#

Detect whether resolution is in mm or µm and return (res_x_um, res_y_um).

OME-Zarr resolution can be reported in either mm (OME-NGFF standard) or µm depending on the writer. Detects by magnitude: - Values < 1.0 assumed to be mm (e.g. 0.01 mm = 10 µm) - Values >= 1.0 assumed to be µm (e.g. 10 µm)

Parameters:

resolution (sequence) – Resolution tuple/list (res_z, res_y, res_x) from read_omezarr.

Returns:

res_x_um, res_y_um – X and Y resolution in microns.

Return type:

float

linumpy.stack_alignment.units.convert_shifts_to_pixels(cumsum_mm, resolution_um)[source]#

Convert mm cumulative shifts to pixel shifts.

Parameters:
  • cumsum_mm (dict) – Mapping from slice_id to (dx_mm, dy_mm).

  • resolution_um (float or (float, float)) – Resolution in microns per pixel. Either a single value (isotropic XY) or a (res_x_um, res_y_um) tuple for anisotropic XY.

Returns:

Mapping from slice_id to (dx_px, dy_px).

Return type:

dict

linumpy.stack_alignment.units.center_shifts(cumsum_px, slice_ids)[source]#

Center shifts around the middle slice.

Subtracts the middle slice’s cumulative shift from all slices, preventing drift from pushing slices out of the output canvas.

Parameters:
  • cumsum_px (dict) – Mapping from slice_id to (dx_px, dy_px).

  • slice_ids (list) – Sorted list of slice IDs.

Returns:

Centered cumulative shifts.

Return type:

dict