polyTEM.tomography.alignment.AlignmentResult

class polyTEM.tomography.alignment.AlignmentResult(beta_history=None, dx_history=None, dy_history=None, num_images=None, num_markers=None, u=None, v=None, w=None, init_x=None, init_y=None, final_x=None, final_y=None, err=None, iterations=None, tilt_angles=None)

Bases: object

AlignmentResult object contains the parameters and results of aligning a stack of tilt images based on fiduciary marker locations

Achieved by solving for X = R(PTU+D) where X is the initial image coordinates, R is the rotation matrix from alignment error D is the displacement matrix from alignment error P is the Projection, and T is the tilt matrix.

Thus the final, aligned coordinates = R^-1 X - D which can be represented as M cdot X.T, where M is the affine transformation matrix

The algorithm also applies a manually inputed origin shift since the Y-axis should coincide with the tilt axis. In future versions, this origin shift should be saved with the class object.

Attributes – beta_history: shape (num_iterations,num_images) dx_history: shape (num_iterations, num_images) dy_history: shape (num_iterations,num_images) marker_u: shape (num_markers) marker_v: shape (num_markers) marker_w: shape (num_markers) init_x: shape (num_images, num_markers) init_y: shape (num_images, num_markers) final_x: shape (num_images, num_markers) final_y: shape (num_images, num_markers) err: shape (num_iterations,) iterations: int affine_transform_mat: shape (num_images,2,3) num_images: number of images num_markers: number of markers tilt_angles: list of tilt angles in DEGREES, with matching order

__init__(beta_history=None, dx_history=None, dy_history=None, num_images=None, num_markers=None, u=None, v=None, w=None, init_x=None, init_y=None, final_x=None, final_y=None, err=None, iterations=None, tilt_angles=None)

Methods

__init__([beta_history, dx_history, ...])

align_markers(x_coo, y_coo, tilt_angles, ...)

Iterative Algorithm for fiduciary marker alignment

get_affine_transform_matrix([...])

Returns the affine transformation matrix that accounts for the alignment error calculated in AlignmentResult, such that aligned image coordinates (x,y) = M * initial image coordinates

load(filename[, json])

Load from pickle

match_coo(coo[, x_origin_shift, y_origin_shift])

Given coordinate from first image in stack, find the corresponding coordinates in all tilt images that should come from the same (u,v,w)

plot_history()

save(filename[, json])

classmethod align_markers(x_coo, y_coo, tilt_angles, num_images, num_particles, method='explicit', max_iter=50, tol=0.1)

Iterative Algorithm for fiduciary marker alignment

Based on Jing and Sachs (1990)

Parameters:
  • x_coo – numpy array shape (num_images,num_particles)

  • y_coo – numpy array shape (num_images,num_particles)

  • tilt_angles – list of tilt_angles in radians

  • num_images – int

  • num_particles – int

  • method – ‘explicit’ or ‘lu’ solve method

Returns:

AlignmentResult

get_affine_transform_matrix(marker_indices=[0, 1, 2], origin_shift=(0, 0))

Returns the affine transformation matrix that accounts for the alignment error calculated in AlignmentResult, such that aligned image coordinates (x,y) = M * initial image coordinates

Parameters:
  • marker_indices – list of 3 indices to use to get affine transform, choose indices that form a large triangle, cannot calculate affine transform from a straight line.

  • origin_shift – tuple (x,y) to shift the origin by. Usually necessary to keep image index and coordinates consistent

Returns:

matrix shape (num_images,2,3)

Return type:

M

classmethod load(filename, json=False)

Load from pickle

match_coo(coo, x_origin_shift=0, y_origin_shift=0)

Given coordinate from first image in stack, find the corresponding coordinates in all tilt images that should come from the same (u,v,w)

save(filename, json=False)