-
Notifications
You must be signed in to change notification settings - Fork 181
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9445de6
commit 291b4d2
Showing
2 changed files
with
67 additions
and
17 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,42 +1,73 @@ | ||
""" | ||
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(): | ||
hardi_fname, hardi_bval_fname, hardi_bvec_fname =\ | ||
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 | ||
|
||
maskdata, mask = median_otsu(data, vol_idx=range(10, 50), median_radius=3, | ||
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) |
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