本文整理汇总了Python中dipy.io.dpy.Dpy.write_tracks方法的典型用法代码示例。如果您正苦于以下问题:Python Dpy.write_tracks方法的具体用法?Python Dpy.write_tracks怎么用?Python Dpy.write_tracks使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类dipy.io.dpy.Dpy
的用法示例。
在下文中一共展示了Dpy.write_tracks方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: warp_tracks
# 需要导入模块: from dipy.io.dpy import Dpy [as 别名]
# 或者: from dipy.io.dpy.Dpy import write_tracks [as 别名]
def warp_tracks(input_tracks_filename, input_flirt_fmatrix, input_fa_filename, output_filename = None, input_ref = '/usr/share/fsl/data/standard/FMRIB58_FA_1mm.nii.gz'):
print 'Loading fa, flirt matrix ...'
img_fa = nib.load(input_fa_filename)
flirt_affine= np.loadtxt(input_flirt_fmatrix)
img_ref =nib.load(input_ref)
#create affine matrix from flirt
mat=flirt2aff(flirt_affine,img_fa,img_ref)
#read tracks
print 'Loading tracks ...'
tensor_tracks = load_tracks(input_tracks_filename)
#linear tranform for tractography
tracks_warped_linear = transform_tracks(tensor_tracks,mat)
if output_filename == None:
filename_save = input_tracks_filename.split('.')[0]+'_linear.dpy'
else:
filename_save = os.path.abspath(output_filename)
#save tracks_warped_linear
print 'Saving warped tracks into :', filename_save
dpr_linear = Dpy(filename_save, 'w')
dpr_linear.write_tracks(tracks_warped_linear)
dpr_linear.close()
return filename_save
示例2: tracking_prob
# 需要导入模块: from dipy.io.dpy import Dpy [as 别名]
# 或者: from dipy.io.dpy.Dpy import write_tracks [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: tracking_eudx
# 需要导入模块: from dipy.io.dpy import Dpy [as 别名]
# 或者: from dipy.io.dpy.Dpy import write_tracks [as 别名]
def tracking_eudx(dir_src, dir_out, verbose=False):
# Loading FA and evecs data
fa_name = 'data_' + par_b_tag + '_' + par_dim_tag + '_FA.nii.gz'
FA, affine = load_nifti(pjoin(dir_src, fa_name), verbose)
evecs_name = 'data_' + par_b_tag + '_' + par_dim_tag + '_EV.nii.gz'
evecs, _ = load_nifti(pjoin(dir_src, evecs_name), verbose)
# Computation of streamlines
sphere = get_sphere('symmetric724')
peak_indices = quantize_evecs(evecs, sphere.vertices)
streamlines = EuDX(FA.astype('f8'),
ind=peak_indices,
seeds=par_eudx_seeds,
odf_vertices= sphere.vertices,
a_low=par_eudx_threshold)
# Saving tractography
voxel_size = (par_dim_vox,) * 3
dims = FA.shape[:3]
hdr = nib.trackvis.empty_header()
hdr['voxel_size'] = voxel_size
hdr['voxel_order'] = 'LAS'
hdr['dim'] = dims
hdr['vox_to_ras'] = affine
strm = ((sl, None, None) for sl in streamlines)
trk_name = 'tractogram_' + par_b_tag + '_' + par_dim_tag + '_' + par_rec_tag + '_' + par_eudx_tag + '.trk'
trk_out = os.path.join(dir_out, trk_name)
nib.trackvis.write(trk_out, strm, hdr, points_space='voxel')
dpy_out = trk_out.replace('.trk', '.dpy')
dpy = Dpy(dpy_out, 'w')
dpy.write_tracks(streamlines)
dpy.close()
示例4: test_dpy
# 需要导入模块: from dipy.io.dpy import Dpy [as 别名]
# 或者: from dipy.io.dpy.Dpy import write_tracks [as 别名]
def test_dpy():
fd,fname = mkstemp()
dpw = Dpy(fname,'w')
A=np.ones((5,3))
B=2*A.copy()
C=3*A.copy()
dpw.write_track(A)
dpw.write_track(B)
dpw.write_track(C)
dpw.write_tracks([C,B,A])
dpw.close()
dpr = Dpy(fname,'r')
assert_equal(dpr.version()=='0.0.1',True)
T=dpr.read_tracksi([0,1,2,0,0,2])
print(T)
T2=dpr.read_tracks()
assert_equal(len(T2),6)
dpr.close()
assert_array_equal(A,T[0])
assert_array_equal(C,T[5])
os.remove(fname)
示例5: warp_tracks_linearly
# 需要导入模块: from dipy.io.dpy import Dpy [as 别名]
# 或者: from dipy.io.dpy.Dpy import write_tracks [as 别名]
def warp_tracks_linearly(flirt_filename,fa_filename, tracks_filename,linear_filename):
import nibabel as nib
from dipy.external.fsl import flirt2aff
fsl_ref = '/usr/share/fsl/data/standard/FMRIB58_FA_1mm.nii.gz'
img_fa = nib.load(fa_filename)
flirt_affine= np.loadtxt(flirt_filename)
img_ref =nib.load(fsl_ref)
#create affine matrix from flirt
mat=flirt2aff(flirt_affine,img_fa,img_ref)
#read tracks
tensor_tracks = load_whole_tract(tracks_filename)
#linear tranform for tractography
tracks_warped_linear = transform_tracks(tensor_tracks,mat)
#save tracks_warped_linear
dpr_linear = Dpy(linear_filename, 'w')
dpr_linear.write_tracks(tracks_warped_linear)
dpr_linear.close()
示例6: save_dpy
# 需要导入模块: from dipy.io.dpy import Dpy [as 别名]
# 或者: from dipy.io.dpy.Dpy import write_tracks [as 别名]
def save_dpy(streamlines, filename):
''' Save tractography to a .dpy file'''
print "Save tracks as .dpy"
tracks = [track for track in streamlines]
dpw = Dpy(filename, 'w')
dpw.write_tracks(tracks)
dpw.close()
示例7: create_save_tracks
# 需要导入模块: from dipy.io.dpy import Dpy [as 别名]
# 或者: from dipy.io.dpy.Dpy import write_tracks [as 别名]
def create_save_tracks(anisotropy,indices, seeds, low_thresh,filename):
euler = EuDX(anisotropy,
ind=indices,
#odf_vertices=get_sphere('symmetric362'),
seeds=seeds, a_low=low_thresh)
#odf_vertices=get_sphere('symmetric362').vertices,
tracks = [track for track in euler]
dpw = Dpy(filename, 'w')
dpw.write_tracks(tracks)
dpw.close()
开发者ID:baothien,项目名称:tiensy,代码行数:13,代码来源:quickbundle_for_all_origin_linear_data_no_transform_for_Beijing.py
示例8: create_save_tracks
# 需要导入模块: from dipy.io.dpy import Dpy [as 别名]
# 或者: from dipy.io.dpy.Dpy import write_tracks [as 别名]
def create_save_tracks(anisotropy, indices, seeds, low_thresh, filename):
euler = EuDX(
anisotropy, ind=indices, odf_vertices=get_sphere("symmetric362").vertices, seeds=seeds, a_low=low_thresh
)
tensor_tracks_old = [track for track in euler]
tracks = [track for track in tensor_tracks_old if track.shape[0] > 1]
dpw = Dpy(filename, "w")
dpw.write_tracks(tracks)
dpw.close()
示例9: save_tractogram
# 需要导入模块: from dipy.io.dpy import Dpy [as 别名]
# 或者: from dipy.io.dpy.Dpy import write_tracks [as 别名]
def save_tractogram(fname, streamlines, affine, vox_size=None, shape=None,
header=None, reduce_memory_usage=False,
tractogram_file=None):
""" Saves tractogram files (*.trk or *.tck or *.dpy)
Parameters
----------
fname : str
output trk filename
streamlines : list of 2D arrays, generator or ArraySequence
Each 2D array represents a sequence of 3D points (points, 3).
affine : array_like (4, 4)
The mapping from voxel coordinates to streamline points.
vox_size : array_like (3,), optional
The sizes of the voxels in the reference image (default: None)
shape : array, shape (dim,), optional
The shape of the reference image (default: None)
header : dict, optional
Metadata associated to the tractogram file(*.trk). (default: None)
reduce_memory_usage : {False, True}, optional
If True, save streamlines in a lazy manner i.e. they will not be kept
in memory. Otherwise, keep all streamlines in memory until saving.
tractogram_file : class TractogramFile, optional
Define tractogram class type (TrkFile vs TckFile)
Default is None which means auto detect format
"""
if 'dpy' in os.path.splitext(fname)[1].lower():
dpw = Dpy(fname, 'w')
dpw.write_tracks(Streamlines(streamlines))
dpw.close()
return
tractogram_file = tractogram_file or detect_format(fname)
if tractogram_file is None:
raise ValueError("Unknown format for 'fname': {}".format(fname))
if vox_size is not None and shape is not None:
if not isinstance(header, dict):
header = {}
header[Field.VOXEL_TO_RASMM] = affine.copy()
header[Field.VOXEL_SIZES] = vox_size
header[Field.DIMENSIONS] = shape
header[Field.VOXEL_ORDER] = "".join(aff2axcodes(affine))
if reduce_memory_usage and not callable(streamlines):
sg = lambda: (s for s in streamlines)
else:
sg = streamlines
tractogram_loader = LazyTractogram if reduce_memory_usage else Tractogram
tractogram = tractogram_loader(sg)
tractogram.affine_to_rasmm = affine
track_file = tractogram_file(tractogram, header=header)
nib.streamlines.save(track_file, fname)
示例10: create_save_tracks
# 需要导入模块: from dipy.io.dpy import Dpy [as 别名]
# 或者: from dipy.io.dpy.Dpy import write_tracks [as 别名]
def create_save_tracks(anisotropy,indices, seeds, low_thresh,filename):
#this is new features in new dipy -current 121011 0.6.0.dev
#print "Computing EuDX reconstruction."
euler = EuDX(anisotropy,
ind=indices,
odf_vertices=get_sphere('symmetric362').vertices,
seeds=seeds, a_low=low_thresh)
euler = EuDX(anisotropy, ind=indices, seeds=seeds, a_low=low_thresh)
tracks = [track for track in euler]
dpw = Dpy(filename, 'w')
dpw.write_tracks(tracks)
dpw.close()
示例11: roi_intersection
# 需要导入模块: from dipy.io.dpy import Dpy [as 别名]
# 或者: from dipy.io.dpy.Dpy import write_tracks [as 别名]
def roi_intersection(fdpy,fatlas,roi_no,froidpy):
dpr=Dpy(fdpy,'r')
T=dpr.read_tracksi(range(10000))
dpr.close()
Troi=[]
wI=get_roi(fatlas,roi_no,0)
for (i,t) in enumerate(T):
if i%1000==0:
print i
if track_roi_intersection_check(t,wI,.5):
Troi.append(t)
print(len(Troi))
dpw=Dpy(froidpy,'w')
dpw.write_tracks(Troi)
dpw.close()
'''
示例12: create_save_tracks
# 需要导入模块: from dipy.io.dpy import Dpy [as 别名]
# 或者: from dipy.io.dpy.Dpy import write_tracks [as 别名]
def create_save_tracks(anisotropy, indices, vertices, seeds, low_thresh, filename):
from dipy.tracking.eudx import EuDX
eu = EuDX(FA, peak_indices, odf_vertices=vertices, seeds=seeds, a_low=low_thresh)
tensor_tracks_old = [streamline for streamline in eu]
# euler = EuDX(anisotropy,
# ind=indices,
# odf_vertices=get_sphere('symmetric362').vertices,
# seeds=seeds, a_low=low_thresh)
# tensor_tracks_old = [track for track in euler]
# print len(tensor_tracks_old)
tracks = [track for track in tensor_tracks_old if track.shape[0] > 1]
dpw = Dpy(filename, "w")
dpw.write_tracks(tracks)
dpw.close()
开发者ID:baothien,项目名称:tiensy,代码行数:20,代码来源:4_reconstruction_and_quickbundle_for_all_new_TensorModel_201303_for_PBC.py
示例13: runStream
# 需要导入模块: from dipy.io.dpy import Dpy [as 别名]
# 或者: from dipy.io.dpy.Dpy import write_tracks [as 别名]
def runStream(csd_peaks, roi_file, roi_label=1, ang_thr=45., a_low=0.2, step_size=0.1, seeds_per_voxel=30, out_name=None):
img = nib.load(roi_file)
affine = img.get_affine()
mask_data = img.get_data()
p = np.asarray(np.where(mask_data == roi_label))
p = p.transpose()
# seed_points = None
# for i in p:
# points = np.random.uniform(size=[seeds_per_voxel,3]) + (i-0.5)
# if seed_points is None:
# seed_points = points
# else:
# seed_points = np.concatenate([seed_points, points], axis=0)
import dipy.tracking.utils as utils
seeds = utils.seeds_from_mask(mask_data==1, density=seeds_per_voxel)
print '# of seeds: ',len(seeds)
sphere = get_sphere('symmetric724')
print "seed eudx tractography"
eu = EuDX(csd_peaks.peak_values,
csd_peaks.peak_indices,
odf_vertices=sphere.vertices,
step_sz=step_size,
seeds=seeds,
ang_thr=ang_thr,
a_low=a_low)
csa_streamlines_mult_peaks = [streamline for streamline in eu]
out_file = 'tracts.dipy'
if out_name:
out_file = out_name+'_'+out_file
from dipy.io.trackvis import save_trk
save_trk(out_file, csa_streamlines_mult_peaks, affine,
mask.shape)
dpw = Dpy(out_file, 'w')
dpw.write_tracks(csa_streamlines_mult_peaks)
print 'write tracts to %s' % out_file
return (csa_streamlines_mult_peaks, out_file)
示例14: compute_tracking
# 需要导入模块: from dipy.io.dpy import Dpy [as 别名]
# 或者: from dipy.io.dpy.Dpy import write_tracks [as 别名]
def compute_tracking(src_dti_dir, out_trk_dir, subj_name):
# Loading FA and evecs data
src_fa_file = os.path.join(src_dti_dir, subj_name + par_fa_suffix)
fa_img = nib.load(src_fa_file)
FA = fa_img.get_data()
affine = fa_img.get_affine()
src_evecs_file = os.path.join(src_dti_dir, subj_name + par_evecs_suffix)
evecs_img = nib.load(src_evecs_file)
evecs = evecs_img.get_data()
# Computation of streamlines
sphere = get_sphere('symmetric724')
peak_indices = dti.quantize_evecs(evecs, sphere.vertices)
streamlines = EuDX(FA.astype('f8'),
ind=peak_indices,
seeds=par_eudx_seeds,
odf_vertices= sphere.vertices,
a_low=par_eudx_threshold)
# Saving tractography
voxel_size = fa_img.get_header().get_zooms()[:3]
dims = FA.shape[:3]
seed = par_eudx_seeds
seed = "_%d%s" % (seed/10**6 if seed>10**5 else seed/10**3,
'K' if seed < 1000000 else 'M')
hdr = nib.trackvis.empty_header()
hdr['voxel_size'] = voxel_size
hdr['voxel_order'] = 'LAS'
hdr['dim'] = dims
hdr['vox_to_ras'] = affine
strm = ((sl, None, None) for sl in streamlines
if length(sl) > par_trk_min and length(sl) < par_trk_max)
out_trk_file = os.path.join(out_trk_dir, subj_name + seed + par_trk_suffix)
nib.trackvis.write(out_trk_file, strm, hdr, points_space='voxel')
tracks = [track for track in streamlines]
out_dipy_file = os.path.join(out_trk_dir,subj_name + seed + par_dipy_suffix)
dpw = Dpy(out_dipy_file, 'w')
dpw.write_tracks(tracks)
dpw.close()
示例15: test_dpy
# 需要导入模块: from dipy.io.dpy import Dpy [as 别名]
# 或者: from dipy.io.dpy.Dpy import write_tracks [as 别名]
def test_dpy():
fname = 'test.bin'
with InTemporaryDirectory():
dpw = Dpy(fname, 'w')
A = np.ones((5, 3))
B = 2 * A.copy()
C = 3 * A.copy()
dpw.write_track(A)
dpw.write_track(B)
dpw.write_track(C)
dpw.write_tracks([C, B, A])
dpw.close()
dpr = Dpy(fname, 'r')
assert_equal(dpr.version() == '0.0.1', True)
T = dpr.read_tracksi([0, 1, 2, 0, 0, 2])
T2 = dpr.read_tracks()
assert_equal(len(T2), 6)
dpr.close()
assert_array_equal(A, T[0])
assert_array_equal(C, T[5])