Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/uncertaintyconeimpl' into uncert…
Browse files Browse the repository at this point in the history
…aintyconeimpl

# Conflicts:
#	fury/actor.py
#	fury/actors/tensor.py
#	fury/shaders/sdf/sd_cone.frag
#	fury/shaders/sdf/sd_union.frag
#	fury/tests/test_actors.py
  • Loading branch information
tvcastillod committed Jul 19, 2023
2 parents 7426b2f + 057c22d commit f19ec65
Show file tree
Hide file tree
Showing 2 changed files with 101 additions and 3 deletions.
6 changes: 3 additions & 3 deletions fury/actors/tensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,10 @@ def tensor_ellipsoid(centers, axes, lengths, colors, scales, opacity):

# Normalization
n_evals = "evalsVSOutput = evals/(max(evals.x, max(evals.y, evals.z)));"

# Values constraint to avoid incorrect visualizations
evals = "evalsVSOutput = clamp(evalsVSOutput,0.05,1);"

# Scaling matrix
sc_matrix = \
"""
Expand All @@ -100,7 +100,7 @@ def tensor_ellipsoid(centers, axes, lengths, colors, scales, opacity):

# Rotation matrix
rot_matrix = "mat3 R = mat3(evec1, evec2, evec3);"

# Tensor matrix
t_matrix = "tensorMatrix = inverse(R) * S * R;"

Expand Down
98 changes: 98 additions & 0 deletions fury/actors/tests/test_uncertainty.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
"""
This spript includes the implementation of dti_uncertainty actor for the
visualization of the cones of uncertainty along with the diffusion tensors for
comparison
"""
from dipy.core.gradients import gradient_table
from dipy.reconst import dti
from dipy.segment.mask import median_otsu

import dipy.denoise.noise_estimate as ne

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, 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)

# load the b-values and b-vectors
bvals, bvecs = read_bvals_bvecs(hardi_bval_fname, hardi_bvec_fname)

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)

gtab = gradient_table(bvals, bvecs)

tenmodel = dti.TensorModel(gtab)
tenfit = tenmodel.fit(maskdata[13:43, 44:74, 28:29])

# Eigenvalues and eigenvectors
fevals = tenfit.evals
fevecs = tenfit.evecs

tensor_vals = dti.lower_triangular(tenfit.quadratic_form)
dti_params = dti.eig_from_lo_tri(tensor_vals)

# Predicted signal given tensor parameters
fsignal = dti.tensor_prediction(dti_params, gtab, 1.0)

# Design matrix or B matrix
b_matrix = dti.design_matrix(gtab)

# Standard deviation of the noise
sigma = ne.estimate_sigma(maskdata[13:43, 44:74, 28:29])

uncertainty_cones = actor.uncertainty_cone(evecs=fevecs, evals=fevals,
signal=fsignal, sigma=sigma,
b_matrix=b_matrix)

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)


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)

0 comments on commit f19ec65

Please sign in to comment.