-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Created the apply transfomr workflow.
1) Added a function to load the saved affine matrix from the text file. 2) Added the import of ndimage from scipy in the test_parzenhist.py file. 3) Created a new workflow file apply_transform.
- Loading branch information
Parichit Sharma
committed
Jun 18, 2018
1 parent
c3b4786
commit b765826
Showing
3 changed files
with
59 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
from dipy.workflows.workflow import Workflow | ||
|
||
from dipy.align.imaffine import AffineMap | ||
import nibabel as nib | ||
import numpy as np | ||
from os.path import join as pjoin | ||
from os import path | ||
from dipy.io.image import save_nifti, load_affine_matrix | ||
|
||
|
||
class ApplyTransformFlow(Workflow): | ||
|
||
def run(self, reference_image_file, moving_image_files, affine_matrix_file, | ||
out_file='transformed.nii.gz'): | ||
|
||
""" | ||
Parameters | ||
---------- | ||
reference_image_file : string | ||
Path to the static image file. | ||
moving_image_files : string | ||
Location of the file or folder containing the images to be transformed. | ||
affine_matrix_file : string | ||
The text file containing the affine matrix for transformation. | ||
out_file : string, optional | ||
Name of the transformed file. (default 'transformed.nii.gz') | ||
""" | ||
|
||
io = self.get_io_iterator() | ||
|
||
for ref_image_file, mov_images, affine_matrix_file, out_file in io: | ||
|
||
ref_image = nib.load(ref_image_file) | ||
static_grid2world = ref_image.affine | ||
|
||
image = nib.load(mov_images) | ||
image_data = np.array(image.get_data()) | ||
|
||
affine_matrix = load_affine_matrix(affine_matrix_file) | ||
|
||
img_transformation = AffineMap(affine=affine_matrix, domain_grid_shape=image_data.shape) | ||
transformed = img_transformation.transform(image_data) | ||
|
||
save_nifti(pjoin(path.split(mov_images)[1]+out_file), transformed, affine=static_grid2world) |