diff --git a/fury/actors/tests/test_uncertainty.py b/fury/actors/tests/test_uncertainty.py index e99156d67..f4ebdd5d6 100644 --- a/fury/actors/tests/test_uncertainty.py +++ b/fury/actors/tests/test_uncertainty.py @@ -1,14 +1,19 @@ """ This spript includes the implementation of dti_uncertainty actor for the -visualization of the cones of uncertainty which uses matrix perturbation -analysis for its calculation +visualization of the cones of uncertainty along with the diffusion tensors for +comparison """ +from dipy.reconst import dti +from dipy.segment.mask import median_otsu + from fury import actor, window from dipy.io.image import load_nifti from dipy.io.gradients import read_bvals_bvecs -from dipy.data import get_fnames +from dipy.data import get_fnames, read_stanford_hardi + +from fury.primitive import prim_sphere def test_uncertainty(): @@ -16,12 +21,9 @@ def test_uncertainty(): get_fnames('stanford_hardi') data, affine = load_nifti(hardi_fname) - data_ = data[20:24, 68:72, 28:29] - print(data_) - print(data_.shape) + # load the b-values and b-vectors bvals, bvecs = read_bvals_bvecs(hardi_bval_fname, hardi_bvec_fname) - print(bvals, bvecs) from dipy.segment.mask import median_otsu @@ -29,14 +31,43 @@ def test_uncertainty(): numpass=1, autocrop=True, dilate=2) uncertainty_cones = actor.dti_uncertainty( - data=maskdata[20:24, 68:72, 28:29], bvals=bvals, bvecs=bvecs) + data=maskdata[13:43, 44:74, 28:29], bvals=bvals, bvecs=bvecs) scene = window.Scene() scene.background([255, 255, 255]) + scene.add(diffusion_tensors()) + window.show(scene, reset_camera=False) + scene.clear() + scene.add(uncertainty_cones) + window.show(scene, reset_camera=False) - scene.reset_camera() - scene.reset_clipping_range() - window.show(scene, reset_camera=False) +class Sphere: + + vertices = None + faces = None + +def diffusion_tensors(): + # https://dipy.org/documentation/1.0.0./examples_built/reconst_dti/ + img, gtab = read_stanford_hardi() + data = img.get_data() + + maskdata, mask = median_otsu(data, vol_idx=range(10, 50), median_radius=3, + numpass=1, autocrop=True, dilate=2) + tenmodel = dti.TensorModel(gtab) + tenfit = tenmodel.fit(maskdata) + + evals = tenfit.evals[13:43, 44:74, 28:29] + evecs = tenfit.evecs[13:43, 44:74, 28:29] + + vertices, faces = prim_sphere('symmetric724', True) + sphere = Sphere() + sphere.vertices = vertices + sphere.faces = faces + + from dipy.data import get_sphere + sphere = get_sphere('symmetric724') + + return actor.tensor_slicer(evals, evecs, sphere=sphere, scale=0.3) diff --git a/fury/tests/test_actors.py b/fury/tests/test_actors.py index bc3c502d4..751a1c32e 100644 --- a/fury/tests/test_actors.py +++ b/fury/tests/test_actors.py @@ -1736,14 +1736,31 @@ def test_marker_actor(interactive=False): def test_uncertainty_actor(interactive=False): scene = window.Scene() - scene.background((0, 0, 0)) - data = np.array([0, 0, 0]) - bvals = np.array([0, 0, 0]) - bvecs = np.array([0, 0, 0]) + from dipy.data import get_fnames + from dipy.io import read_bvals_bvecs + _, fbvals, fbvecs = get_fnames('small_101D') + bvals, bvecs = read_bvals_bvecs(fbvals, fbvecs) - uncert_cones = actor.dti_uncertainty(data=data, bvals=bvals, bvecs=bvecs, - scales=1.0, opacity=1.0) + n = bvals.shape[0] + data = np.ones((10, 10, 1, n)) * 0.1 + + uncert_cones = actor.dti_uncertainty(data=data, bvals=bvals, bvecs=bvecs) + scene.add(uncert_cones) + + if interactive: + window.show(scene) + + report = window.analyze_scene(scene) + npt.assert_equal(report.actors, 1) + arr = window.snapshot(scene, offscreen=True) + report = window.analyze_snapshot(arr) + npt.assert_equal(report.objects, 100) + scene.clear() + + n = bvals.shape[0] + data = np.ones((5, 5, 5, n)) * 0.5 + uncert_cones = actor.dti_uncertainty(data=data, bvals=bvals, bvecs=bvecs) scene.add(uncert_cones) if interactive: @@ -1751,6 +1768,8 @@ def test_uncertainty_actor(interactive=False): report = window.analyze_scene(scene) npt.assert_equal(report.actors, 1) + scene.clear() + def test_actors_primitives_count(): centers = np.array([[1, 1, 1], [2, 2, 2]])