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