Skip to content

_registration_utils

Utils functions for registration.

InitArgsRegistration

Bases: BaseModel

Registration init args.

Passed from init_image_based_registration to compute_image_based_registration.

Source code in fractal_tasks_core/_registration_utils.py
76
77
78
79
80
81
82
83
84
85
86
class InitArgsRegistration(BaseModel):
    """Registration init args.

    Passed from `init_image_based_registration` to
    `compute_image_based_registration`.
    """

    reference_zarr_url: str
    """
    zarr_url for the reference image.
    """

reference_zarr_url: str instance-attribute

zarr_url for the reference image.

InitArgsRegistrationConsensus

Bases: BaseModel

Registration consensus init args.

Provides the list of zarr_urls for all acquisitions for a given well.

Source code in fractal_tasks_core/_registration_utils.py
89
90
91
92
93
94
95
96
97
98
class InitArgsRegistrationConsensus(BaseModel):
    """Registration consensus init args.

    Provides the list of zarr_urls for all acquisitions for a given well.
    """

    zarr_url_list: list[str]
    """
    List of zarr_urls for all the OME-Zarr images in the well.
    """

zarr_url_list: list[str] instance-attribute

List of zarr_urls for all the OME-Zarr images in the well.

RegistrationMethod

Bases: Enum

RegistrationMethod Enum class.

ATTRIBUTE DESCRIPTION
PHASE_CROSS_CORRELATION

phase cross correlation based on scikit-image (works with 2D & 3D images).

CHI2_SHIFT

chi2 shift based on image-registration library (only works with 2D images).

Source code in fractal_tasks_core/_registration_utils.py
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
class RegistrationMethod(Enum):
    """RegistrationMethod Enum class.

    Attributes:
        PHASE_CROSS_CORRELATION: phase cross correlation based on scikit-image
            (works with 2D & 3D images).
        CHI2_SHIFT: chi2 shift based on image-registration library
            (only works with 2D images).
    """

    PHASE_CROSS_CORRELATION = "phase_cross_correlation"
    CHI2_SHIFT = "chi2_shift"

    def register(self, img_ref, img_acq_x):
        if self == RegistrationMethod.PHASE_CROSS_CORRELATION:
            return phase_cross_correlation(img_ref, img_acq_x)
        elif self == RegistrationMethod.CHI2_SHIFT:
            return chi2_shift_out(img_ref, img_acq_x)

chi2_shift_out(img_ref, img_cycle_x)

Calculate the shift between two images using chi2_shift.

Returns the output in the same format as phase_cross_correlation.

PARAMETER DESCRIPTION
img_ref

First image.

TYPE: ndarray

img_cycle_x

Second image.

TYPE: ndarray

RETURNS DESCRIPTION
list[ndarray]

List containing numpy array of shift in y and x direction.

Source code in fractal_tasks_core/_registration_utils.py
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
def chi2_shift_out(img_ref, img_cycle_x) -> list[np.ndarray]:
    """Calculate the shift between two images using chi2_shift.

    Returns the output in the same format as phase_cross_correlation.

    Args:
        img_ref (np.ndarray): First image.
        img_cycle_x (np.ndarray): Second image.

    Returns:
        List containing numpy array of shift in y and x direction.
    """
    x, y, _a, _b = chi2_shift(np.squeeze(img_ref), np.squeeze(img_cycle_x))

    # Running into issues when using direct float output for fractal.
    # When rounding to integer and using integer dtype, it typically works
    # but for some reasons fails when run over a whole 384 well plate (but
    # the well where it fails works fine when run alone). For now, rounding
    # to integer, but still using float64 dtype (like the scikit-image
    # phase cross correlation function) seems to be the safest option.
    shifts = np.array([-np.round(y), -np.round(x)], dtype="float64")
    # return as a list to adhere to the phase_cross_correlation output format
    return [shifts]