Skip to content

Commit

Permalink
Added also_shift to tilt_maximage
Browse files Browse the repository at this point in the history
  • Loading branch information
AndrewHerzing committed Jun 18, 2024
1 parent c136cc0 commit bff118f
Showing 1 changed file with 20 additions and 4 deletions.
24 changes: 20 additions & 4 deletions tomotools/align.py
Original file line number Diff line number Diff line change
Expand Up @@ -685,7 +685,7 @@ def fit_line(x, m, b):
return final


def tilt_maximage(stack, limit=10, delta=0.1, plot_results=False):
def tilt_maximage(stack, limit=10, delta=0.1, plot_results=False, also_shift=False):
"""
Perform automated determination of the tilt axis of a TomoStack.
Expand All @@ -703,6 +703,9 @@ def tilt_maximage(stack, limit=10, delta=0.1, plot_results=False):
plot_results : boolean
If True, plot the maximum image along with the lines determined
by Hough analysis
also_shift : boolean
If True, also calculate and apply the global shift perpendicular to the tilt
by minimizing the sum of the reconstruction
Returns
----------
Expand Down Expand Up @@ -737,9 +740,22 @@ def tilt_maximage(stack, limit=10, delta=0.1, plot_results=False):

plt.tight_layout()

rotated = stack.trans_stack(angle=-rotation_angle)
rotated.metadata.Tomography.tiltaxis = -rotation_angle
return rotated
ali = stack.trans_stack(angle=-rotation_angle)
ali.metadata.Tomography.tiltaxis = -rotation_angle

if also_shift:
idx = ali.data.shape[2] // 2
shifts = np.arange(-20, 20, 1)
nshifts = shifts.shape[0]
shifted = ali.isig[0:nshifts, :].deepcopy()
for i in range(0, nshifts):
shifted.data[:, :, i] = np.roll(ali.isig[idx, :].data, int(shifts[i]))
shifted_rec = shifted.reconstruct('SIRT', 100, constrain=True)
tilt_shift = shifts[shifted_rec.sum((1, 2)).data.argmin()]
print("Calculated tilt shift: %s pixels" % tilt_shift)
ali = ali.trans_stack(yshift=-tilt_shift)
ali.metadata.Tomography.yshift = -tilt_shift
return ali


def align_to_other(stack, other):
Expand Down

0 comments on commit bff118f

Please sign in to comment.