Skip to content

Commit

Permalink
ENH: more args are available in function calls (#352)
Browse files Browse the repository at this point in the history
  • Loading branch information
dgursoy committed Nov 5, 2018
1 parent 48bf3ec commit 8de12aa
Showing 1 changed file with 79 additions and 12 deletions.
91 changes: 79 additions & 12 deletions tomopy/prep/alignment.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,9 @@

def align_seq(
prj, ang, fdir='.', iters=10, pad=(0, 0),
blur=True, save=False, debug=True):
blur=True, center=None, algorithm='sirt',
upsample_factor=10, rin=0.5, rout=0.8,
save=False, debug=True):
"""
Aligns the projection image stack using the sequential
re-projection algorithm :cite:`Gursoy:17`.
Expand All @@ -93,6 +95,36 @@ def align_seq(
Padding for projection images in x and y-axes.
blur : bool, optional
Blurs the edge of the image before registration.
center: array, optional
Location of rotation axis.
algorithm : {str, function}
One of the following string values.
'art'
Algebraic reconstruction technique :cite:`Kak:98`.
'gridrec'
Fourier grid reconstruction algorithm :cite:`Dowd:99`,
:cite:`Rivers:06`.
'mlem'
Maximum-likelihood expectation maximization algorithm
:cite:`Dempster:77`.
'sirt'
Simultaneous algebraic reconstruction technique.
'tv'
Total Variation reconstruction technique
:cite:`Chambolle:11`.
'grad'
Gradient descent method with a constant step size
upsample_factor : integer, optional
The upsampling factor. Registration accuracy is
inversely propotional to upsample_factor.
rin : scalar, optional
The inner radius of blur function. Pixels inside
rin is set to one.
rout : scalar, optional
The outer radius of blur function. Pixels outside
rout is set to zero.
save : bool, optional
Saves projections and corresponding reconstruction
for each algorithm iteration.
Expand Down Expand Up @@ -123,15 +155,15 @@ def align_seq(
# Register each image frame-by-frame.
for n in range(iters):
# Reconstruct image.
rec = recon(prj, ang, algorithm='sirt')
rec = recon(prj, ang, center=center, algorithm=algorithm)

# Re-project data and obtain simulated data.
sim = project(rec, ang, pad=False)
sim = project(rec, ang, center=center, pad=False)

# Blur edges.
if blur:
_prj = blur_edges(prj, 0.1, 0.5)
_sim = blur_edges(sim, 0.1, 0.5)
_prj = blur_edges(prj, rin, rout)
_sim = blur_edges(sim, rin, rout)
else:
_prj = prj
_sim = sim
Expand All @@ -143,7 +175,8 @@ def align_seq(
for m in range(prj.shape[0]):

# Register current projection in sub-pixel precision
shift, error, diffphase = register_translation(_prj[m], _sim[m], 2)
shift, error, diffphase = register_translation(
_prj[m], _sim[m], upsample_factor)
err[m] = np.sqrt(shift[0]*shift[0] + shift[1]*shift[1])
sx[m] += shift[0]
sy[m] += shift[1]
Expand All @@ -168,7 +201,9 @@ def align_seq(

def align_joint(
prj, ang, fdir='.', iters=10, pad=(0, 0),
blur=True, save=False, debug=True):
blur=True, center=None, algorithm='sirt',
upsample_factor=10, rin=0.5, rout=0.8,
save=False, debug=True):
"""
Aligns the projection image stack using the joint
re-projection algorithm :cite:`Gursoy:17`.
Expand All @@ -187,6 +222,36 @@ def align_joint(
Padding for projection images in x and y-axes.
blur : bool, optional
Blurs the edge of the image before registration.
center: array, optional
Location of rotation axis.
algorithm : {str, function}
One of the following string values.
'art'
Algebraic reconstruction technique :cite:`Kak:98`.
'gridrec'
Fourier grid reconstruction algorithm :cite:`Dowd:99`,
:cite:`Rivers:06`.
'mlem'
Maximum-likelihood expectation maximization algorithm
:cite:`Dempster:77`.
'sirt'
Simultaneous algebraic reconstruction technique.
'tv'
Total Variation reconstruction technique
:cite:`Chambolle:11`.
'grad'
Gradient descent method with a constant step size
upsample_factor : integer, optional
The upsampling factor. Registration accuracy is
inversely propotional to upsample_factor.
rin : scalar, optional
The inner radius of blur function. Pixels inside
rin is set to one.
rout : scalar, optional
The outer radius of blur function. Pixels outside
rout is set to zero.
save : bool, optional
Saves projections and corresponding reconstruction
for each algorithm iteration.
Expand Down Expand Up @@ -224,15 +289,16 @@ def align_joint(
_rec = rec

# Reconstruct image.
rec = recon(prj, ang, algorithm='sirt', num_iter=2, init_recon=_rec)
rec = recon(prj, ang, center=center, algorithm=algorithm,
num_iter=1, init_recon=_rec)

# Re-project data and obtain simulated data.
sim = project(rec, ang, pad=False)
sim = project(rec, ang, center=center, pad=False)

# Blur edges.
if blur:
_prj = blur_edges(prj, 0.0, 0.5)
_sim = blur_edges(sim, 0.0, 0.5)
_prj = blur_edges(prj, rin, rout)
_sim = blur_edges(sim, rin, rout)
else:
_prj = prj
_sim = sim
Expand All @@ -244,7 +310,8 @@ def align_joint(
for m in range(prj.shape[0]):

# Register current projection in sub-pixel precision
shift, error, diffphase = register_translation(_prj[m], _sim[m], 2)
shift, error, diffphase = register_translation(
_prj[m], _sim[m], upsample_factor)
err[m] = np.sqrt(shift[0]*shift[0] + shift[1]*shift[1])
sx[m] += shift[0]
sy[m] += shift[1]
Expand Down

0 comments on commit 8de12aa

Please sign in to comment.