本文整理匯總了Python中dipy.direction.ProbabilisticDirectionGetter.from_shcoeff方法的典型用法代碼示例。如果您正苦於以下問題:Python ProbabilisticDirectionGetter.from_shcoeff方法的具體用法?Python ProbabilisticDirectionGetter.from_shcoeff怎麽用?Python ProbabilisticDirectionGetter.from_shcoeff使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類dipy.direction.ProbabilisticDirectionGetter
的用法示例。
在下文中一共展示了ProbabilisticDirectionGetter.from_shcoeff方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: test_ProbabilisticDirectionGetter
# 需要導入模塊: from dipy.direction import ProbabilisticDirectionGetter [as 別名]
# 或者: from dipy.direction.ProbabilisticDirectionGetter import from_shcoeff [as 別名]
def test_ProbabilisticDirectionGetter():
# Test the constructors and errors of the ProbabilisticDirectionGetter
class SillyModel(SphHarmModel):
sh_order = 4
def fit(self, data, mask=None):
coeff = np.zeros(data.shape[:-1] + (15,))
return SphHarmFit(self, coeff, mask=None)
model = SillyModel(gtab=None)
data = np.zeros((3, 3, 3, 7))
# Test if the tracking works on different dtype of the same data.
for dtype in [np.float32, np.float64]:
fit = model.fit(data.astype(dtype))
# Sample point and direction
point = np.zeros(3)
dir = unit_octahedron.vertices[0].copy()
# make a dg from a fit
dg = ProbabilisticDirectionGetter.from_shcoeff(fit.shm_coeff, 90,
unit_octahedron)
state = dg.get_direction(point, dir)
npt.assert_equal(state, 1)
# Make a dg from a pmf
N = unit_octahedron.theta.shape[0]
pmf = np.zeros((3, 3, 3, N))
dg = ProbabilisticDirectionGetter.from_pmf(pmf, 90, unit_octahedron)
state = dg.get_direction(point, dir)
npt.assert_equal(state, 1)
# pmf shape must match sphere
bad_pmf = pmf[..., 1:]
npt.assert_raises(ValueError, ProbabilisticDirectionGetter.from_pmf,
bad_pmf, 90, unit_octahedron)
# pmf must have 4 dimensions
bad_pmf = pmf[0, ...]
npt.assert_raises(ValueError, ProbabilisticDirectionGetter.from_pmf,
bad_pmf, 90, unit_octahedron)
# pmf cannot have negative values
pmf[0, 0, 0, 0] = -1
npt.assert_raises(ValueError, ProbabilisticDirectionGetter.from_pmf,
pmf, 90, unit_octahedron)
# Check basis_type keyword
dg = ProbabilisticDirectionGetter.from_shcoeff(fit.shm_coeff, 90,
unit_octahedron,
basis_type="mrtrix")
npt.assert_raises(ValueError,
ProbabilisticDirectionGetter.from_shcoeff,
fit.shm_coeff, 90, unit_octahedron,
basis_type="not a basis")
示例2: tracking_prob
# 需要導入模塊: from dipy.direction import ProbabilisticDirectionGetter [as 別名]
# 或者: from dipy.direction.ProbabilisticDirectionGetter import from_shcoeff [as 別名]
def tracking_prob(dir_src, dir_out, verbose=False):
wm_name = 'wm_mask_' + par_b_tag + '_' + par_dim_tag + '.nii.gz'
wm_mask, affine = load_nifti(pjoin(dir_src, wm_name), verbose)
sh_name = 'sh_' + par_b_tag + '_' + par_dim_tag + '.nii.gz'
sh, _ = load_nifti(pjoin(dir_src, sh_name), verbose)
sphere = get_sphere('symmetric724')
classifier = ThresholdTissueClassifier(wm_mask.astype('f8'), .5)
classifier = BinaryTissueClassifier(wm_mask)
max_dg = ProbabilisticDirectionGetter.from_shcoeff(sh, max_angle=par_trk_max_angle, sphere=sphere)
seeds = utils.seeds_from_mask(wm_mask, density=2, affine=affine)
streamlines = LocalTracking(max_dg, classifier, seeds, affine, step_size=par_trk_step_size)
streamlines = list(streamlines)
trk_name = 'tractogram_' + par_b_tag + '_' + par_dim_tag + '_' + par_trk_prob_tag + '.trk'
trk_out = os.path.join(dir_out, trk_name)
save_trk(trk_out, streamlines, affine, wm_mask.shape)
dpy_out = trk_out.replace('.trk', '.dpy')
dpy = Dpy(dpy_out, 'w')
dpy.write_tracks(streamlines)
dpy.close()
示例3: _get_direction_getter
# 需要導入模塊: from dipy.direction import ProbabilisticDirectionGetter [as 別名]
# 或者: from dipy.direction.ProbabilisticDirectionGetter import from_shcoeff [as 別名]
def _get_direction_getter(self, strategy_name, pam, pmf_threshold,
max_angle):
"""Get Tracking Direction Getter object.
Parameters
----------
strategy_name: str
String representing direction getter name.
pam: instance of PeaksAndMetrics
An object with ``gfa``, ``peak_directions``, ``peak_values``,
``peak_indices``, ``odf``, ``shm_coeffs`` as attributes.
pmf_threshold : float
Threshold for ODF functions.
max_angle : float
Maximum angle between streamline segments.
Returns
-------
direction_getter : instance of DirectionGetter
Used to get directions for fiber tracking.
"""
dg, msg = None, ''
if strategy_name.lower() in ["deterministic", "det"]:
msg = "Deterministic"
dg = DeterministicMaximumDirectionGetter.from_shcoeff(
pam.shm_coeff,
sphere=pam.sphere,
max_angle=max_angle,
pmf_threshold=pmf_threshold)
elif strategy_name.lower() in ["probabilistic", "prob"]:
msg = "Probabilistic"
dg = ProbabilisticDirectionGetter.from_shcoeff(
pam.shm_coeff,
sphere=pam.sphere,
max_angle=max_angle,
pmf_threshold=pmf_threshold)
elif strategy_name.lower() in ["closestpeaks", "cp"]:
msg = "ClosestPeaks"
dg = ClosestPeakDirectionGetter.from_shcoeff(
pam.shm_coeff,
sphere=pam.sphere,
max_angle=max_angle,
pmf_threshold=pmf_threshold)
elif strategy_name.lower() in ["eudx", ]:
msg = "Eudx"
dg = pam
else:
msg = "No direction getter defined. Eudx"
dg = pam
logging.info('{0} direction getter strategy selected'.format(msg))
return dg
示例4: _get_direction_getter
# 需要導入模塊: from dipy.direction import ProbabilisticDirectionGetter [as 別名]
# 或者: from dipy.direction.ProbabilisticDirectionGetter import from_shcoeff [as 別名]
def _get_direction_getter(self, strategy_name, pam, pmf_threshold=0.1,
max_angle=30.):
"""Get Tracking Direction Getter object.
Parameters
----------
strategy_name: str
string representing direction getter name
Returns
-------
direction_getter : instance of DirectionGetter
Used to get directions for fiber tracking.
"""
dg, msg = None, ''
if strategy_name.lower() in ["deterministic", "det"]:
msg = "Deterministic"
dg = DeterministicMaximumDirectionGetter.from_shcoeff(
pam.shm_coeff,
sphere=pam.sphere,
max_angle=max_angle,
pmf_threshold=pmf_threshold)
elif strategy_name.lower() in ["probabilistic", "prob"]:
msg = "Probabilistic"
dg = ProbabilisticDirectionGetter.from_shcoeff(
pam.shm_coeff,
sphere=pam.sphere,
max_angle=max_angle,
pmf_threshold=pmf_threshold)
elif strategy_name.lower() in ["closestpeaks", "cp"]:
msg = "ClosestPeaks"
dg = ClosestPeakDirectionGetter.from_shcoeff(
pam.shm_coeff,
sphere=pam.sphere,
max_angle=max_angle,
pmf_threshold=pmf_threshold)
elif strategy_name.lower() in ["eudx", ]:
msg = "Eudx"
dg = pam
else:
msg = "No direction getter defined. Deterministic"
dg = DeterministicMaximumDirectionGetter.from_shcoeff(
pam.shm_coeff,
sphere=pam.sphere,
max_angle=max_angle,
pmf_threshold=pmf_threshold)
logging.info('{0} direction getter strategy selected'.format(msg))
return dg
示例5: auto_response
# 需要導入模塊: from dipy.direction import ProbabilisticDirectionGetter [as 別名]
# 或者: from dipy.direction.ProbabilisticDirectionGetter import from_shcoeff [as 別名]
response, ratio = auto_response(gtab, data, roi_radius=10, fa_thr=0.7)
csd_model = ConstrainedSphericalDeconvModel(gtab, response, sh_order=6)
csd_fit = csd_model.fit(data, mask=white_matter)
"""
Next we'll need to make a ``ProbabilisticDirectionGetter``. Because the CSD
model represents the FOD using the spherical harmonic basis, we can use the
``from_shcoeff`` method to create the direction getter. This direction getter
will randomly sample directions from the FOD each time the tracking algorithm
needs to take another step.
"""
from dipy.direction import ProbabilisticDirectionGetter
prob_dg = ProbabilisticDirectionGetter.from_shcoeff(csd_fit.shm_coeff,
max_angle=30.,
sphere=default_sphere)
"""
As with deterministic tracking, we'll need to use a tissue classifier to
restrict the tracking to the white matter of the brain. One might be tempted
to use the GFA of the CSD FODs to build a tissue classifier, however the GFA
values of these FODs don't classify gray matter and white matter well. We will
therefore use the GFA from the CSA model which we fit for the first section of
this example. Alternatively, one could fit a ``TensorModel`` to the data and use
the fractional anisotropy (FA) to build a tissue classifier.
"""
classifier = ThresholdTissueClassifier(csa_peaks.gfa, .25)
"""
示例6: _run_interface
# 需要導入模塊: from dipy.direction import ProbabilisticDirectionGetter [as 別名]
# 或者: from dipy.direction.ProbabilisticDirectionGetter import from_shcoeff [as 別名]
def _run_interface(self, runtime):
import numpy as np
import nibabel as nib
from dipy.io import read_bvals_bvecs
from dipy.core.gradients import gradient_table
from nipype.utils.filemanip import split_filename
# Loading the data
fname = self.inputs.in_file
img = nib.load(fname)
data = img.get_data()
affine = img.get_affine()
FA_fname = self.inputs.FA_file
FA_img = nib.load(FA_fname)
fa = FA_img.get_data()
affine = FA_img.get_affine()
affine = np.matrix.round(affine)
mask_fname = self.inputs.brain_mask
mask_img = nib.load(mask_fname)
mask = mask_img.get_data()
bval_fname = self.inputs.bval
bvals = np.loadtxt(bval_fname)
bvec_fname = self.inputs.bvec
bvecs = np.loadtxt(bvec_fname)
bvecs = np.vstack([bvecs[0,:],bvecs[1,:],bvecs[2,:]]).T
gtab = gradient_table(bvals, bvecs)
# Creating a white matter mask
fa = fa*mask
white_matter = fa >= 0.2
# Creating a seed mask
from dipy.tracking import utils
seeds = utils.seeds_from_mask(white_matter, density=[2, 2, 2], affine=affine)
# Fitting the CSA model
from dipy.reconst.shm import CsaOdfModel
from dipy.data import default_sphere
from dipy.direction import peaks_from_model
csa_model = CsaOdfModel(gtab, sh_order=8)
csa_peaks = peaks_from_model(csa_model, data, default_sphere,
relative_peak_threshold=.8,
min_separation_angle=45,
mask=white_matter)
from dipy.tracking.local import ThresholdTissueClassifier
classifier = ThresholdTissueClassifier(csa_peaks.gfa, .25)
# CSD model
from dipy.reconst.csdeconv import (ConstrainedSphericalDeconvModel, auto_response)
response, ratio = auto_response(gtab, data, roi_radius=10, fa_thr=0.7)
csd_model = ConstrainedSphericalDeconvModel(gtab, response, sh_order=8)
csd_fit = csd_model.fit(data, mask=white_matter)
from dipy.direction import ProbabilisticDirectionGetter
prob_dg = ProbabilisticDirectionGetter.from_shcoeff(csd_fit.shm_coeff,
max_angle=45.,
sphere=default_sphere)
# Tracking
from dipy.tracking.local import LocalTracking
streamlines = LocalTracking(prob_dg, classifier, seeds, affine,
step_size=.5, maxlen=200, max_cross=1)
# Compute streamlines and store as a list.
streamlines = list(streamlines)
# Saving the trackfile
from dipy.io.trackvis import save_trk
_, base, _ = split_filename(fname)
save_trk(base + '_CSDprob.trk', streamlines, affine, fa.shape)
return runtime
示例7: LocalTracking
# 需要導入模塊: from dipy.direction import ProbabilisticDirectionGetter [as 別名]
# 或者: from dipy.direction.ProbabilisticDirectionGetter import from_shcoeff [as 別名]
det_streamline_generator = LocalTracking(pam,
cmc_classifier,
seeds,
affine,
step_size=step_size)
# The line below is failing not sure why
# detstreamlines = Streamlines(det_streamline_generator)
detstreamlines = list(det_streamline_generator)
detstreamlines = Streamlines(detstreamlines)
save_trk('det.trk', detstreamlines, affine=np.eye(4),
vox_size=vox_size, shape=shape)
dg = ProbabilisticDirectionGetter.from_shcoeff(pam.shm_coeff,
max_angle=20.,
sphere=sphere)
# Particle Filtering Tractography
pft_streamline_generator = ParticleFilteringTracking(dg,
cmc_classifier,
seeds,
affine,
max_cross=1,
step_size=step_size,
maxlen=1000,
pft_back_tracking_dist=2,
pft_front_tracking_dist=1,
particle_count=15,
return_all=False)
# The line below is failing not sure why