Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implementing the Diffeomorphic registration #1616

Closed
wants to merge 39 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
535efaa
Crated a new branch with clean history for the affine registration wo…
parichit Jul 31, 2018
802f3c4
Pasted the stable (latest) code from the PR 1581 in the image.py file.
parichit Jul 31, 2018
df43e44
Pasted the stable (latest) code from PR 1581 into the test_align.py f…
parichit Jul 31, 2018
b6ace1c
Pasted the stable code from PR1581 to imaffine.py file.
parichit Jul 31, 2018
36717ba
Fixed the PEP8 issues.
parichit Jul 31, 2018
468a9a3
Pasted the stable code from PR 1581 for the command line wrapper into…
parichit Jul 31, 2018
c6a6264
Changed the function call in the 'RIGID' transform to invoke 'center …
parichit Aug 2, 2018
095cb7f
added a new line at the end of file in dipy_align_affine command to f…
parichit Aug 2, 2018
cd4191d
Fixed the PEP8 space complaints in the align.py file.
parichit Aug 2, 2018
d55dfb2
Updated the parameter documentation in the ImageRegistrationFlow() cl…
parichit Aug 7, 2018
e5c0979
Decreased the decimal precision to 1 decimal places (in checking the …
parichit Aug 8, 2018
fdb3105
1) Updated the parameter documentation for optimal parameters and sim…
parichit Aug 13, 2018
8f1d3d1
Pasted the code in image.py file from PR1598.
parichit Jul 31, 2018
747aaf0
Pasted the clean and stable code in align.py from PR1598.
parichit Jul 31, 2018
c56bf95
Pasted the clean and stable code in test_align.py from PR1598.
parichit Jul 31, 2018
254e8cc
Pasted the clean and stable code in dipy_apply_affine wrapper from PR…
parichit Jul 31, 2018
cdfc141
1) Fixed the PEP8 formatting issue in the dipy_align_affine and dipy_…
parichit Aug 2, 2018
375ed34
1) Renamed the ApplyTransformFlow to ApplyAffineFlow to distinguish i…
parichit Aug 2, 2018
5774d91
Fixed the PEP8 warning in the test_align.py for the test_apply_transf…
parichit Aug 7, 2018
8f7c8ba
Changed the name of the function to test_apply_affine_transform() and…
parichit Aug 8, 2018
d47644d
Fixed the output file creation error due to output directory prependi…
parichit Aug 13, 2018
e0b046e
Updated the parameter documentation for the ApplyAffineFlow() class.
parichit Aug 13, 2018
0c616a4
Modifed the align.py workflow to include sYn_registration class.
parichit Jul 31, 2018
68a571b
Created the command line wrapper for syn registration workflow.
parichit Aug 2, 2018
5d9d77d
1) Added the optional parameters to the Syn_registration workflow to …
parichit Aug 2, 2018
95e1e30
1) Added the command line wrapper for the diffeomorphic registration …
parichit Aug 13, 2018
328c22f
removed the redundant print statement.
parichit Aug 13, 2018
385c702
Pasted the code in image.py file from PR1598.
parichit Jul 31, 2018
647e3ee
Pasted the clean and stable code in align.py from PR1598.
parichit Jul 31, 2018
a534eee
Pasted the clean and stable code in test_align.py from PR1598.
parichit Jul 31, 2018
b7ae538
Pasted the clean and stable code in dipy_apply_affine wrapper from PR…
parichit Jul 31, 2018
f90a602
1) Fixed the PEP8 formatting issue in the dipy_align_affine and dipy_…
parichit Aug 2, 2018
5cca33a
1) Renamed the ApplyTransformFlow to ApplyAffineFlow to distinguish i…
parichit Aug 2, 2018
b323c7d
Fixed the PEP8 warning in the test_align.py for the test_apply_transf…
parichit Aug 7, 2018
58a4e0f
Changed the name of the function to test_apply_affine_transform() and…
parichit Aug 8, 2018
5bd2093
Fixed the output file creation error due to output directory prependi…
parichit Aug 13, 2018
f19b2f5
Updated the parameter documentation for the ApplyAffineFlow() class.
parichit Aug 13, 2018
2742987
Created the command line wrapper for syn registration workflow.
parichit Aug 2, 2018
63b2519
Fixed the conflicts after the rebasing.
parichit Aug 13, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 7 additions & 0 deletions bin/dipy_align_affine
@@ -0,0 +1,7 @@
#!python

from dipy.workflows.flow_runner import run_flow
from dipy.workflows.align import ImageRegistrationFlow

if __name__ == "__main__":
run_flow(ImageRegistrationFlow())
7 changes: 7 additions & 0 deletions bin/dipy_align_syn
@@ -0,0 +1,7 @@
#!python

from dipy.workflows.flow_runner import run_flow
from dipy.workflows.align import SynRegistrationFlow

if __name__ == "__main__":
run_flow(SynRegistrationFlow())
7 changes: 7 additions & 0 deletions bin/dipy_apply_affine
@@ -0,0 +1,7 @@
#!python

from dipy.workflows.flow_runner import run_flow
from dipy.workflows.align import ApplyAffineFlow

if __name__ == "__main__":
run_flow(ApplyAffineFlow())
6 changes: 6 additions & 0 deletions bin/dipy_syn_register
@@ -0,0 +1,6 @@
#!python
from dipy.workflows.flow_runner import run_flow
from dipy.workflows.align import SynRegistrationFlow

if __name__ == "__main__":
run_flow(SynRegistrationFlow())
13 changes: 12 additions & 1 deletion 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,20 @@ 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 : optimal parameters
the optimal parameters (translation, rotation shear etc.)
fopt : Similarity metric
the value of the function at the optimal parameters.
'''
self._init_optimizer(static, moving, transform, params0,
static_grid2world, moving_grid2world,
Expand Down Expand Up @@ -1074,6 +1083,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
44 changes: 43 additions & 1 deletion dipy/io/image.py
@@ -1,14 +1,15 @@
from __future__ import division, print_function, absolute_import

import nibabel as nib
import numpy as np


def load_nifti(fname, return_img=False, return_voxsize=False,
return_coords=False):
img = nib.load(fname)
data = img.get_data()
vox_size = img.header.get_zooms()[:3]

ret_val = [data, img.affine]

if return_img:
Expand All @@ -24,3 +25,44 @@ def load_nifti(fname, return_img=False, return_voxsize=False,
def save_nifti(fname, data, affine, hdr=None):
result_img = nib.Nifti1Image(data, affine, header=hdr)
result_img.to_filename(fname)


def load_affine_matrix(fname):
"""
Parameters
---------
fname : str
The file containing the saved affine matrix.
"""
return np.loadtxt(fname)


def save_affine_matrix(fname, affine):
"""
Parameters
---------
fname : string
File name to save the affine matrix.
affine : numpy array
The object containing the affine matrix.
"""
np.savetxt(fname, affine)


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))