Permalink
Browse files

1) Apply transform code is integrated with the align.py file.

2) Wrote the test cases for the apply transform for automated testing.
3) Did manual testing of the apply transform workflow.
  • Loading branch information...
Parichit Sharma
Parichit Sharma committed Jul 4, 2018
1 parent 628a562 commit 054b352f17243792db8f058fe34afafddb8b900f
Showing with 64 additions and 6 deletions.
  1. +1 −4 dipy/workflows/align.py
  2. +63 −2 dipy/workflows/tests/test_align.py
@@ -567,7 +567,4 @@ def run(self, reference_image_file, moving_image_files, affine_matrix_file,
img_transformation = AffineMap(affine=affine_matrix, domain_grid_shape=image_data.shape)
transformed = img_transformation.transform(image_data)

if out_file == 'transformed.nii.gz':
save_nifti(pjoin(path.split(moving_image_file)[1]+out_file), transformed, affine=static_grid2world)
else:
save_nifti(out_file, transformed, affine=static_grid2world)
save_nifti(out_dir+out_file, transformed, affine=static_grid2world)
@@ -1,5 +1,8 @@
import numpy.testing as npt
import numpy as np


from time import sleep
import nibabel as nib
from nibabel.tmpdirs import TemporaryDirectory

@@ -8,15 +11,14 @@

import os.path
from os.path import join as pjoin
import shutil

from dipy.align.tests.test_parzenhist import setup_random_transform
from dipy.align.transforms import (Transform,
regtransforms)
from dipy.io.image import save_nifti
from glob import glob

from dipy.workflows.align import ImageRegistrationFlow
from dipy.workflows.align import ApplyTransformFlow


def test_reslice():
@@ -156,3 +158,62 @@ def test_err():
test_affine()
test_err()


def test_apply_transform():
with TemporaryDirectory() as temp_out_dir:

factors = {
('TRANSLATION', 3): (2.0, None, np.array([2.3, 4.5, 1.7])),
('RIGID', 3): (0.1, None, np.array([0.1, 0.15, -0.11, 2.3, 4.5,
1.7])),
('AFFINE', 3): (0.1, None, np.array([0.99, -0.05, 0.03, 1.3,
0.05, 0.99, -0.10, 2.5,
-0.07, 0.10, 0.99, -1.4]))}

for i in factors.keys():
static, moving, static_g2w, moving_g2w, \
smask, mmask, M = setup_random_transform(
transform=regtransforms[i], rfactor=factors[i][0])

some = str(i[0]) + '_static.nii.gz'
one = str(i[0]) + '_moving.nii.gz'

save_nifti(pjoin(temp_out_dir, some), data=static,
affine=static_g2w)

save_nifti(pjoin(temp_out_dir, one), data=moving,
affine=moving_g2w)


static_image_file = pjoin(temp_out_dir, 'TRANSLATION_static.nii.gz')
moving_image_file = pjoin(temp_out_dir, 'TRANSLATION_moving.nii.gz')

out_moved = pjoin(temp_out_dir, "trans_moved.nii.gz")
out_affine = pjoin(temp_out_dir, "trans_affine.txt")

image_registeration_flow = ImageRegistrationFlow()

image_registeration_flow.run(static_image_file,
moving_image_file,
transform='trans',
out_dir=temp_out_dir,
out_moved=out_moved,
out_affine=out_affine,
level_iters=[100, 10, 1])

npt.assert_equal(os.path.exists(out_moved), True)
npt.assert_equal(os.path.exists(out_affine), True)


apply_trans = ApplyTransformFlow()
two = pjoin(temp_out_dir,'*moving*')
apply_trans.run(static_image_file, two, out_affine)

npt.assert_equal(os.path.exists(pjoin(temp_out_dir,'transformed.nii.gz')), True)


if __name__ == "__main__":
test_reslice()
test_image_registration()
test_apply_transform()

0 comments on commit 054b352

Please sign in to comment.