scallops.registration.crosscorrelation.align_image

scallops.registration.crosscorrelation.align_image(image, align_within_time_channels=None, align_between_time_channel=0, window=2, upsample_factor=2, filter_percentiles=None)

Align an image within cycles (timepoints) and then between cycles.

This function aligns an image stack within cycles (timepoints) and between cycles using cross correlation. The returned image has attributes containing the key ‘coordinateTransformations’, which describes the applied transformations.

Parameters:
  • image (DataArray) – DataArray containing the data to align with dimensions of (t,c,z,y,x)

  • align_within_time_channels (Sequence[int] | None) – List of channel indices for aligning within cycles. Set to None to skip aligning within a timepoint.

  • align_between_time_channel (int | None) – Channel index to use for aligning between cycles. Set to None to skip aligning between timepoints.

  • window (int) – The Window size.

  • 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. Parameter passed to :skimage.registration.phase_cross_correlation:

  • filter_percentiles (Sequence[float] | None) – Replaces data outside of percentile range [q1, q2] with uniform noise over the range [q1,q2] when aligning within cycle.

Returns:

Aligned image

Example:

Return type:

DataArray

import xarray as xr
from scallops.registration.crosscorrelation import align_image

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

# Generate aligned image
aligned_image = align_image(
    data,
    align_within_time_channels=[0, 1, 2],
    align_between_time_channel=0,
    window=2,
    upsample_factor=2,
    filter_percentiles=(0, 90),
)