etspy.align.align_stack(stack: TomoStack, method: AlignmentMethod | 'PC' | 'COM' | 'COM-CL' | 'StackReg', start: int | None, show_progressbar: bool, xrange: tuple[int, int] | None = None, p: int = 20, nslices: int = 20, cuda: bool = False, upsample_factor: int = 3, com_ref_index: int | None = None, cl_ref_index: int | None = None, cl_resolution: float = 0.05, cl_div_factor: int = 8) TomoStack[source]

Compute the shifts for spatial registration.

Shifts are determined by one of three methods:
1.) Phase correlation (PC) as implemented in scikit-image. Based on:

Manuel Guizar-Sicairos, Samuel T. Thurman, and James R. Fienup. Efficient subpixel image registration algorithms, Optics Letters vol. 33 (2008) pp. 156-158. https://doi.org/10.1364/OL.33.000156

2.) Center of mass (COM) tracking. A Python implementation of

algorithms described in: T. Sanders. Physically motivated global alignment method for electron tomography, Advanced Structural and Chemical Imaging vol. 1 (2015) pp 1-11. https://doi.org/10.1186/s40679-015-0005-7

3.) Rigid translation using PyStackReg for shift calculation.

PyStackReg is a Python port of the StackReg plugin for ImageJ which uses a pyramidal approach to minimize the least-squares difference in image intensity between a source and target image. StackReg is described in: P. Thevenaz, U.E. Ruttimann, M. Unser. A Pyramid Approach to Subpixel Registration Based on Intensity, IEEE Transactions on Image Processing vol. 7, no. 1, pp. 27-41, January 1998. https://doi.org/10.1109/83.650848

4.) A combination of center of mass tracking for aligment of

projections perpendicular to the tilt axis and common line alignment for parallel to the tilt axis. This is a Python implementation of Matlab code described in: M. C. Scott, et al. Electron tomography at 2.4-ångström resolution, Nature 483, 444-447 (2012). https://doi.org/10.1038/nature10934

Shifts are then applied and the aligned stack is returned. The tilts are stored in stack.metadata.Tomography.shifts for later use.

Parameters:
stack: TomoStack

3-D numpy array containing the tilt series data

method: AlignmentMethod | 'PC' | 'COM' | 'COM-CL' | 'StackReg'

Method by which to calculate the alignments. Valid options are controlled by the etspy.AlignmentMethod enum.

start: int | None

Position in tilt series to use as starting point for the alignment. If None, the central projection is used.

show_progressbar: bool

Enable/disable progress bar

xrange: tuple[int, int] | None = None

(Only used when method ==COM) The range for performing alignment. See calculate_shifts_com() for more details.

p: int = 20

(Only used when method ==COM) Padding element. See calculate_shifts_com() for more details.

nslices: int = 20

(Only used when method ==COM) Number of slices to return. See calculate_shifts_com() for more details.

cuda: bool = False

(Only used when method ==PC) Enable/disable the use of GPU-accelerated processes using CUDA. See calculate_shifts_pc() for more details.

upsample_factor: int = 3

(Only used when method ==PC) Factor by which to resample the data. See calculate_shifts_pc() for more details.

com_ref_index: int | None = None

(Only used when method ==COM_CL) Reference slice for center of mass alignment. All other slices will be aligned to this reference. See calc_shifts_com_cl() for more details.

cl_ref_index: int | None = None

(Only used when method ==COM_CL) Reference slice for common line alignment. All other slices will be aligned to this reference. If not provided the projection closest to the middle of the stack will be chosen. See calc_shifts_com_cl() for more details.

cl_resolution: float = 0.05

(Only used when method ==COM_CL) Resolution for subpixel common line alignment. Default is 0.05. Should be less than 0.5. See calc_shifts_com_cl() for more details.

cl_div_factor: int = 8

(Only used when method ==COM_CL) Factor which determines the number of iterations of common line alignment to perform. Default is 8. See calc_shifts_com_cl() for more details.

Returns:

out – Spatially registered copy of the input stack

Return type:

TomoStack