Permalink
Browse files

Added the test case.

  • Loading branch information...
parichit committed Aug 3, 2018
1 parent 3a086da commit fe09b3aaf57df963842031b9a23e55f6e12a853e
Showing with 75 additions and 1 deletion.
  1. +67 −0 dipy/workflows/tests/test_vis.py
  2. +8 −1 dipy/workflows/vis_registration.py
@@ -0,0 +1,67 @@
#!python

import nibabel as nib
from nibabel.tmpdirs import TemporaryDirectory
from numpy.testing import run_module_suite
import os.path
from os.path import join as pjoin

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 dipy.workflows.align import ImageRegistrationFlow
from dipy.workflows.vis_registration import VisualizeRegisteredImage


def test_mosaic():

with TemporaryDirectory() as temp_out_dir:

static, moving, static_g2w, moving_g2w, smask, mmask, M \
= setup_random_transform(transform=regtransforms[('AFFINE', 3)],
rfactor=0.1)

save_nifti(pjoin(temp_out_dir, 'b0.nii.gz'), data=static,
affine=static_g2w)
save_nifti(pjoin(temp_out_dir, 't1.nii.gz'), data=moving,
affine=moving_g2w)

static_image_file = pjoin(temp_out_dir, 'b0.nii.gz')
moving_image_file = pjoin(temp_out_dir, 't1.nii.gz')

image_registeration_flow = ImageRegistrationFlow()
vis_registered = VisualizeRegisteredImage()

out_moved = pjoin(temp_out_dir, "affine_moved.nii.gz")
out_affine = pjoin(temp_out_dir, "affine_affine.txt")

image_registeration_flow.run(static_image_file,
moving_image_file,
transform='affine',
out_dir=temp_out_dir,
out_moved=out_moved,
out_affine=out_affine,
save_metric=True,
level_iters=[100, 10, 1],
out_quality='affine_q.txt')

moved_data = nib.load(out_moved)
moved_img = moved_data.get_data()
moving_grid2wordld = moved_data.affine

overlapped = vis_registered.create_mosaic(static,
moved_img, moving_grid2wordld, fname=None)

x, y, z = overlapped.shape[:3]

assert overlapped[x//2, :, :, 2] is 0
assert overlapped[:, y//2, :, 2] is 0
assert overlapped[:, :, z//2, 2] is 0

if __name__ == "__main__":
run_module_suite()





@@ -97,7 +97,7 @@ def adjust_color_range(self, img):
The numpy array with scaled down range of color values.
"""

# Interpolating to range 0-15 for reducing the color values.
# Interpolating to range 0-14 for reducing the color values.
img[..., 0] = np.interp(img[..., 0], (img[..., 0].min(),
img[..., 0].max()), (0, 14))
img[..., 1] = np.interp(img[..., 1], (img[..., 1].min(),
@@ -138,6 +138,13 @@ def create_mosaic(self, static_img, moved_img, affine, fname):

overlay, value_range = self.process_image_data(static_img,
moved_img)

print(overlay.shape)
print(overlay[50,50,50,:])

if fname is None:
return overlay

renderer = window.Renderer()
renderer.background((0.5, 0.5, 0.5))

0 comments on commit fe09b3a

Please sign in to comment.