autoemx.core.em_runtime.drift_correction module

autoemx.core.em_runtime.drift_correction.preprocess_image(img: ndarray) → ndarray[source]

Normalize and apply a window function to reduce FFT edge effects. Critical for non-periodic real-world images.

autoemx.core.em_runtime.drift_correction.shift_image(img: ndarray, dx: float, dy: float) → ndarray[source]

Apply an affine shift (translation) to an image.

autoemx.core.em_runtime.drift_correction.estimate_drift_of(img1: ndarray, img2: ndarray) → Tuple[float, float][source]

Robust estimate of the translation (dx, dy) of img2 relative to img1.

Uses a 2-stage hierarchical approach:

  1. Coarse estimation on downscaled images to handle large displacements.

  2. Fine estimation using an ensemble of crops on the full-resolution images, corrected by the coarse shift.

  3. Robust averaging (IQR) to reject outliers.