Skip to content

Commit

Permalink
Moved the apply transform code to align.py file.
Browse files Browse the repository at this point in the history
1) Refactored the apply transform code.
2) Renamed the binary for apply transform workflow.
Future Work:
1) Need to do more manual testing for the apply transform workflow.
2) Need to write test cases for the apply transform workflow.
  • Loading branch information
Parichit Sharma committed Jul 4, 2018
1 parent 25c3c90 commit 628a562
Show file tree
Hide file tree
Showing 6 changed files with 283 additions and 183 deletions.
2 changes: 1 addition & 1 deletion bin/dipy_align_transform → bin/dipy_apply_transform
Expand Up @@ -6,7 +6,7 @@ method from the workflows.
"""

from dipy.workflows.flow_runner import run_flow
from dipy.workflows.apply_transform import ApplyTransformFlow
from dipy.workflows.align import ApplyTransformFlow

if __name__ == "__main__":
run_flow(ApplyTransformFlow())
17 changes: 15 additions & 2 deletions dipy/align/imaffine.py
Expand Up @@ -954,7 +954,7 @@ def _init_optimizer(self, static, moving, transform, params0,

def optimize(self, static, moving, transform, params0,
static_grid2world=None, moving_grid2world=None,
starting_affine=None):
starting_affine=None, ret_metric=False):
r''' Starts the optimization process
Parameters
Expand Down Expand Up @@ -993,11 +993,22 @@ def optimize(self, static, moving, transform, params0,
If None:
Start from identity.
The default is None.
ret_metric : boolean, optional
if True, it returns the parameters for measuring the
similarity between the images (default 'False').
The metric containing optimal parameters and
the distance between the images.
Returns
-------
affine_map : instance of AffineMap
the affine resulting affine transformation
xopt : similarity metric
the metric of optimal parameters
fopt : distance
the distance between the images
'''
self._init_optimizer(static, moving, transform, params0,
static_grid2world, moving_grid2world,
Expand Down Expand Up @@ -1074,6 +1085,8 @@ def optimize(self, static, moving, transform, params0,
self.params0 = self.transform.get_identity_parameters()

affine_map.set_affine(self.starting_affine)
if ret_metric:
return affine_map, opt.xopt, opt.fopt
return affine_map


Expand Down Expand Up @@ -1222,4 +1235,4 @@ def transform_origins(static, static_grid2world,
affine_map = AffineMap(transform,
static.shape, static_grid2world,
moving.shape, moving_grid2world)
return affine_map
return affine_map
20 changes: 19 additions & 1 deletion dipy/io/image.py
Expand Up @@ -45,4 +45,22 @@ def load_affine_matrix(fname):
fname : str
The file containing the saved affine matrix.
"""
return np.loadtxt(fname)
return np.loadtxt(fname)

def save_quality_assur_metric(fname, xopt, fopt):
"""
Parameters
__________
fname: string
File name to save the metric values.
xopt: numpy array
The metric containing the
optimal parameters for
image registration.
fopt: int
The distance between the registered images.
"""
np.savetxt(fname, xopt, header="Optimal Parameter metric")
with open(fname, 'a') as f:
f.write('# Distance after registration\n')
f.write(str(fopt))

0 comments on commit 628a562

Please sign in to comment.