scallops.registration.crosscorrelation.align_images

scallops.registration.crosscorrelation.align_images(image_1, image_2, channel_index=0, upsample_factor=2, autoscale=True)

Align two images, using the channel at position channel_index (typically DAPI).

This function aligns two images using cross correlation with optional autoscaling.

Parameters:
  • image_1 (DataArray) – First image to align

  • image_2 (DataArray) – Second image to align

  • channel_index (int) – Index of the desired channel to align by

  • upsample_factor (int) – Subpixel alignment is done if upsample_factor is greater than one. Images will be registered to within 1 / upsample_factor of a pixel. For example, upsample_factor == 20 means the images will be registered within 1/20th of a pixel.

  • autoscale (bool) – Automatically scale image_2 prior to alignment. Offsets are applied to the unscaled image so no resolution is lost.

Returns:

image_2 with calculated offsets applied to all channels.

Example:

Return type:

DataArray

import xarray as xr
from your_module import align_images

# Create two sample DataArrays
channels = ["ChannelA", "ChannelT", "ChannelG", "ChannelC"]
data_1 = xr.DataArray(
    np.random.rand(100, 10, len(channels)),
    dims=("t", "c", "z", "y", "x"),
    coords={"c": channels},
)
data_2 = xr.DataArray(
    np.random.rand(100, 10, len(channels)),
    dims=("t", "c", "z", "y", "x"),
    coords={"c": channels},
)

# Generate aligned image
aligned_image = align_images(
    data_1, data_2, channel_index=0, upsample_factor=2, autoscale=True
)