예제 #1
0
def test_eudx_further():
    """ Cause we love testin.. ;-)
    """

    fimg, fbvals, fbvecs = get_data("small_101D")
    img = ni.load(fimg)
    affine = img.get_affine()
    bvals = np.loadtxt(fbvals)
    gradients = np.loadtxt(fbvecs).T
    data = img.get_data()
    ten = Tensor(data, bvals, gradients, thresh=50)
    x, y, z = data.shape[:3]
    seeds = np.zeros((10 ** 4, 3))
    for i in range(10 ** 4):
        rx = (x - 1) * np.random.rand()
        ry = (y - 1) * np.random.rand()
        rz = (z - 1) * np.random.rand()
        seeds[i] = np.ascontiguousarray(np.array([rx, ry, rz]), dtype=np.float64)

    # print seeds
    # """
    eu = EuDX(a=ten.fa(), ind=ten.ind(), seeds=seeds, a_low=0.2)
    T = [e for e in eu]

    # check that there are no negative elements
    for t in T:
        assert_equal(np.sum(t.ravel() < 0), 0)

    """
예제 #2
0
def test_eudx():
    
    #read bvals,gradients and data
    fimg,fbvals, fbvecs = get_data('small_64D')    
    bvals=np.load(fbvals)
    gradients=np.load(fbvecs)
    img =ni.load(fimg)    
    data=img.get_data()
    
    print(data.shape)    
    gqs = GeneralizedQSampling(data,bvals,gradients)       
    ten = Tensor(data,bvals,gradients,thresh=50)
    seed_list=np.dot(np.diag(np.arange(10)),np.ones((10,3)))    
    iT=iter(EuDX(gqs.qa(),gqs.ind(),seed_list=seed_list))
    T=[]
    for t in iT: 
        T.append(t)    
    iT2=iter(EuDX(ten.fa(),ten.ind(),seed_list=seed_list))
    T2=[]
    for t in iT2: 
        T2.append(t)
    
    print('length T ',sum([length(t) for t in T]))  
    print('length T2',sum([length(t) for t in T2]))  

    print(gqs.QA[1,4,8,0])
    print(gqs.QA.ravel()[ndarray_offset(np.array([1,4,8,0]),np.array(gqs.QA.strides),4,8)])

    assert_equal(gqs.QA[1,4,8,0], gqs.QA.ravel()[ndarray_offset(np.array([1,4,8,0]),np.array(gqs.QA.strides),4,8)])

    #assert_equal, sum([length(t) for t in T ]) , 77.999996662139893
    #assert_equal, sum([length(t) for t in T2]) , 63.499998092651367
    assert_equal(sum([length(t) for t in T ]) , 75.214988201856613)
    assert_equal(sum([length(t) for t in T2]) , 60.202986091375351)
예제 #3
0
def test_eudx():

    # read bvals,gradients and data
    fimg, fbvals, fbvecs = get_data("small_64D")
    bvals = np.load(fbvals)
    gradients = np.load(fbvecs)
    img = ni.load(fimg)
    data = img.get_data()

    print(data.shape)
    gqs = GeneralizedQSampling(data, bvals, gradients)
    ten = Tensor(data, bvals, gradients, thresh=50)
    seed_list = np.dot(np.diag(np.arange(10)), np.ones((10, 3)))
    iT = iter(EuDX(gqs.qa(), gqs.ind(), seeds=seed_list))
    T = []
    for t in iT:
        T.append(t)
    iT2 = iter(EuDX(ten.fa(), ten.ind(), seeds=seed_list))
    T2 = []
    for t in iT2:
        T2.append(t)

    print("length T ", sum([length(t) for t in T]))
    print("length T2", sum([length(t) for t in T2]))

    print(gqs.QA[1, 4, 8, 0])
    print(gqs.QA.ravel()[ndarray_offset(np.array([1, 4, 8, 0]), np.array(gqs.QA.strides), 4, 8)])

    assert_almost_equal(
        gqs.QA[1, 4, 8, 0], gqs.QA.ravel()[ndarray_offset(np.array([1, 4, 8, 0]), np.array(gqs.QA.strides), 4, 8)]
    )

    assert_almost_equal(sum([length(t) for t in T]), 70.999996185302734, places=3)
    assert_almost_equal(sum([length(t) for t in T2]), 56.999997615814209, places=3)
예제 #4
0
def test_phantom():
    
    def f(t):
        x=np.sin(t)
        y=np.cos(t)    
        z=np.linspace(-1,1,len(x))
        return x,y,z

    fimg,fbvals,fbvecs=get_data('small_64D')    
    bvals=np.load(fbvals)
    bvecs=np.load(fbvecs)
    bvecs[np.isnan(bvecs)]=0
    
    N=50 #timepoints
    
    vol=orbital_phantom(bvals=bvals,
                         bvecs=bvecs,
                         func=f,
                         t=np.linspace(0,2*np.pi,N),
                         datashape=(10,10,10,len(bvals)),
                         origin=(5,5,5),
                         scale=(3,3,3),
                         angles=np.linspace(0,2*np.pi,16),
                         radii=np.linspace(0.2,2,6))
    
    ten=Tensor(vol,bvals,bvecs)
    FA=ten.fa()
    FA[np.isnan(FA)]=0
    
    assert_equal(np.round(FA.max()*1000),707)
예제 #5
0
def test_eudx_further():
    """ Cause we love testin.. ;-)
    """

    fimg, fbvals, fbvecs = get_data('small_101D')
    img = ni.load(fimg)
    affine = img.get_affine()
    bvals = np.loadtxt(fbvals)
    gradients = np.loadtxt(fbvecs).T
    data = img.get_data()
    ten = Tensor(data, bvals, gradients, thresh=50)
    x, y, z = data.shape[:3]
    seeds = np.zeros((10**4, 3))
    for i in range(10**4):
        rx = (x - 1) * np.random.rand()
        ry = (y - 1) * np.random.rand()
        rz = (z - 1) * np.random.rand()
        seeds[i] = np.ascontiguousarray(np.array([rx, ry, rz]),
                                        dtype=np.float64)

    #print seeds
    #"""
    eu = EuDX(a=ten.fa(), ind=ten.ind(), seeds=seeds, a_low=.2)
    T = [e for e in eu]

    #check that there are no negative elements
    for t in T:
        assert_equal(np.sum(t.ravel() < 0), 0)
    """
예제 #6
0
def show_phantom_crossing(fname,type='dsi',weight=None):

    btable=np.loadtxt(get_data('dsi515btable'))
    bvals=btable[:,0]
    bvecs=btable[:,1:]

    #fname='/home/eg309/Desktop/t5'
    #fname='/home/eg309/Data/orbital_phantoms/20.0'
    #fname='/tmp/t5'
    fvol = np.memmap(fname, dtype='f8', mode='r', shape=(64,64,64,len(bvals)))
    data=fvol[32-10:32+10,32-10:32+10,31:34,:]
    #data=fvol[32,32,32,:][None,None,None,:]
    ten=Tensor(data,bvals,bvecs,thresh=50)
    FA=ten.fa()
       
    def H(x):
        res=(2*x*np.cos(x) + (x**2-2)*np.sin(x))/x**3
        res[np.isnan(res)]=1/3.
        return res
    
    if type=='dsi':
        mod=DiffusionSpectrum(data,bvals,bvecs,odf_sphere='symmetric642',auto=True,save_odfs=True)        
    if type=='gqi':
        mod=GeneralizedQSampling(data,bvals,bvecs,1.2,odf_sphere='symmetric642',squared=False,save_odfs=True)
    if type=='gqi2':
        mod=GeneralizedQSampling(data,bvals,bvecs,3.,odf_sphere='symmetric642',squared=True,save_odfs=True)
    if type=='eitl':
        ei=EquatorialInversion(data,bvals,bvecs,odf_sphere='symmetric642',auto=False,save_odfs=True,fast=True)
        ei.radius=np.arange(0,5,0.1)
        ei.gaussian_weight=weight
        ei.set_operator('laplacian')
        ei.update()
        ei.fit()
        mod=ei
    if type=='eitl2':
        ei=EquatorialInversion(data,bvals,bvecs,odf_sphere='symmetric642',auto=False,save_odfs=True,fast=True)
        ei.radius=np.arange(0,5,0.1)
        ei.gaussian_weight=weight
        ei.set_operator('laplap')
        ei.update()
        ei.fit()
        mod=ei
    if type=='eits':
        ei=EquatorialInversion(data,bvals,bvecs,odf_sphere='symmetric642',auto=False,save_odfs=True,fast=True)
        ei.radius=np.arange(0,5,0.1)
        ei.gaussian_weight=weight
        ei.set_operator('signal')
        ei.update()
        ei.fit()
        mod=ei   
        
    show_blobs(mod.ODF[:,:,0,:][:,:,None,:],mod.odf_vertices,mod.odf_faces,fa_slice=FA[:,:,0],size=1.5,scale=1.)    
예제 #7
0
def test_eudx():

    #read bvals,gradients and data
    fimg, fbvals, fbvecs = get_data('small_64D')
    bvals = np.load(fbvals)
    gradients = np.load(fbvecs)
    img = ni.load(fimg)
    data = img.get_data()

    print(data.shape)
    gqs = GeneralizedQSampling(data, bvals, gradients)
    ten = Tensor(data, bvals, gradients, thresh=50)
    seed_list = np.dot(np.diag(np.arange(10)), np.ones((10, 3)))
    iT = iter(EuDX(gqs.qa(), gqs.ind(), seeds=seed_list))
    T = []
    for t in iT:
        T.append(t)
    iT2 = iter(EuDX(ten.fa(), ten.ind(), seeds=seed_list))
    T2 = []
    for t in iT2:
        T2.append(t)

    print('length T ', sum([length(t) for t in T]))
    print('length T2', sum([length(t) for t in T2]))

    print(gqs.QA[1, 4, 8, 0])
    print(gqs.QA.ravel()[ndarray_offset(np.array([1, 4, 8, 0]),
                                        np.array(gqs.QA.strides), 4, 8)])

    assert_almost_equal(
        gqs.QA[1, 4, 8, 0],
        gqs.QA.ravel()[ndarray_offset(np.array([1, 4, 8, 0]),
                                      np.array(gqs.QA.strides), 4, 8)])

    assert_almost_equal(sum([length(t) for t in T]),
                        70.999996185302734,
                        places=3)
    assert_almost_equal(sum([length(t) for t in T2]),
                        56.999997615814209,
                        places=3)
        base_filename = base_dir + filename

        nii_filename = base_dir + "DTI/data_resample.nii.gz"
        bvec_filename = base_filename + ".bvec"
        bval_filename = base_filename + ".bval"

        img = nib.load(nii_filename)
        data = img.get_data()
        affine = img.get_affine()

        bvals = np.loadtxt(bval_filename)
        gradients = np.loadtxt(bvec_filename).T  # this is the unitary direction of the gradient

        base_dir2 = base_dir + "DTI/"

        tensors = Tensor(data, bvals, gradients, thresh=50)
        create_save_tracks(tensors.fa(), tensors.ind(), 10 ** 4, 0.2, base_dir2 + "tracks_dti_10K.dpy")
        create_save_tracks(tensors.fa(), tensors.ind(), 10 ** 6, 0.2, base_dir2 + "tracks_dti_1M.dpy")
        create_save_tracks(tensors.fa(), tensors.ind(), 3 * 10 ** 6, 0.2, base_dir2 + "tracks_dti_3M.dpy")

        # =====================  gqi ========================================
        #        gqs=GeneralizedQSampling(data,bvals,gradients)
        #        create_save_tracks(gqs.qa(), gqs.ind(), 10**4, .0239, base_dir2+'tracks_gqi_10K.dpy')
        #        create_save_tracks(gqs.qa(), gqs.ind(), 10**6, .0239, base_dir2+'tracks_gqi_1M.dpy')
        #        create_save_tracks(gqs.qa(), gqs.ind(), 3*10**6, .0239, base_dir2+'tracks_gqi_3M.dpy')
        # =====================  gqi ========================================

        print "Done warped"

        flirt_filename = base_dir2 + "flirt.mat"
        fa_filename = base_dir2 + "fa_resample.nii.gz"
예제 #9
0
        img = nib.load(nii_bet_ecc_filename)

        old_data = img.get_data()
        old_affine = img.get_affine()
                
        
        from dipy.align.aniso2iso import resample
        zooms=img.get_header().get_zooms()[:3]
        print 'old zooms:', zooms
        new_zooms=(2.,2.,2.)
        print 'new zoom', new_zooms        
        data,affine=resample(old_data,old_affine,zooms,new_zooms)
        
        
        print("Computing FA...")
        tensors = Tensor(data, bvals, gradients, thresh=b0_threshold)
        FA = tensors.fa()
        print("FA:", FA.shape)

#        print("Computing EuDX reconstruction.")
#        euler = EuDX(a=FA, ind=tensors.ind(), 
#                     odf_vertices=get_sphere('symmetric362').vertices,                      
#                     seeds=eudx_seeds, a_low=eudx_fa_stop)
#        tensor_tracks_old = [track for track in euler]   
#        tensor_tracks = [track for track in tensor_tracks_old if track.shape[0]>1]

        print("Saving results.")

        fa_filename = basedir_reconstruction + 'fa_resample.nii.gz'
        print "Saving FA:", fa_filename
        fa_img = nib.Nifti1Image(data=FA, affine=affine)
예제 #10
0
파일: test_dsi.py 프로젝트: jgors/dipy
 #D=data[20:90,20:90,18:22]
 #D=data[40:44,40:44,18:22]    
 #del data
 D=data
 
 from time import time
 
 t0=time()    
 ds=DiffusionSpectrum(D,bvals,bvecs,mask=mask)
 t1=time()
 print t1-t0,' secs'
 
 GFA=ds.gfa()
 
 t2=time()
 ten=Tensor(D,bvals,bvecs,mask=mask)
 t3=time()
 print t3-t2,' secs'
 
 FA=ten.fa()
 
 from dipy.tracking.propagation import EuDX
 
 IN=ds.ind()
 
 eu=EuDX(ten.fa(),IN[:,:,:,0],seeds=10000,a_low=0.2)
 tracks=[e for e in eu]
 
 #FAX=np.zeros(IN.shape)
 #for i in range(FAX.shape[-1]):
 #    FAX[:,:,:,i]=GFA
예제 #11
0
    #D=data[20:90,20:90,18:22]
    #D=data[40:44,40:44,18:22]
    #del data
    D = data

    from time import time

    t0 = time()
    ds = DiffusionSpectrum(D, bvals, bvecs, mask=mask)
    t1 = time()
    print t1 - t0, ' secs'

    GFA = ds.gfa()

    t2 = time()
    ten = Tensor(D, bvals, bvecs, mask=mask)
    t3 = time()
    print t3 - t2, ' secs'

    FA = ten.fa()

    from dipy.tracking.propagation import EuDX

    IN = ds.ind()

    eu = EuDX(ten.fa(), IN[:, :, :, 0], seeds=10000, a_low=0.2)
    tracks = [e for e in eu]

    #FAX=np.zeros(IN.shape)
    #for i in range(FAX.shape[-1]):
    #    FAX[:,:,:,i]=GFA
예제 #12
0
bvecs2=np.zeros((w-len(ind)+1,3))

#copy data
cnt=0
for i in range(w):
    if i not in ind[1:]:        
        data2[:,:,:,cnt]=data[:,:,:,i]
        bvals2[cnt]=bvals[i]
        bvecs2[cnt,:]=bvecs[i,:]
        cnt+=1

print 'after',bvals2.shape,bvecs2.shape


#always check the threshold but 50 should be okay
ten=Tensor(data2,bvals2,bvecs2,thresh=50)

#ten.ind is indices of the eigen directions projected on a sphere
#stopping criteria is FA of .2
eu=EuDX(a=ten.fa(),ind=ten.ind(),seeds=5000,a_low=0.2)

#generate tracks
ten_tracks=[track for track in eu]
print 'No tracks ',len(ten_tracks)

#remove short tracks smaller than 40mm i.e. 20 in native units
ten_tracks=[t for t in ten_tracks if length(t)>20]
print 'No reduced tracks ',len(ten_tracks)

raw_input('Press enter...')
예제 #13
0
def humans():   

    no_seeds=10**6
    visualize = False
    save_odfs = False
    dirname = "data/"    
    for root, dirs, files in os.walk(dirname):
        if root.endswith('101_32'):
            
            base_dir = root+'/'
            filename = 'raw'
            base_filename = base_dir + filename
            nii_filename = base_filename + 'bet.nii.gz'
            bvec_filename = base_filename + '.bvec'
            bval_filename = base_filename + '.bval'
            flirt_mat = base_dir + 'DTI/flirt.mat'    
            fa_filename = base_dir + 'DTI/fa.nii.gz'
            fsl_ref = '/usr/share/fsl/data/standard/FMRIB58_FA_1mm.nii.gz'
            dpy_filename = base_dir + 'DTI/res_tracks_dti.dpy'
    
            print bvec_filename
            
            img = nib.load(nii_filename)
            data = img.get_data()

            affine = img.get_affine()
            bvals = np.loadtxt(bval_filename)
            gradients = np.loadtxt(bvec_filename).T # this is the unitary direction of the gradient
            
            tensors = Tensor(data, bvals, gradients, thresh=50)
            FA = tensors.fa()                       
            FA = tensors.fa()
            famask=FA>=.2
            
            ds=DiffusionSpectrum(data,bvals,gradients,odf_sphere='symmetric642',mask=famask,half_sphere_grads=True,auto=True,save_odfs=save_odfs)
            gq=GeneralizedQSampling(data,bvals,gradients,1.2,odf_sphere='symmetric642',mask=famask,squared=False,save_odfs=save_odfs)
            ei=EquatorialInversion(data,bvals,gradients,odf_sphere='symmetric642',mask=famask,half_sphere_grads=True,auto=False,save_odfs=save_odfs,fast=True)
            ei.radius=np.arange(0,5,0.4)
            ei.gaussian_weight=0.05
            ei.set_operator('laplacian')
            ei.update()
            ei.fit()    
            
            ds.PK[FA<.2]=np.zeros(5) 
            ei.PK[FA<.2]=np.zeros(5)
            gq.PK[FA<.2]=np.zeros(5)                   
                        
            print 'create seeds'
            x,y,z,g=ei.PK.shape
            seeds=np.zeros((no_seeds,3))
            sid=0
            while sid<no_seeds:
                rx=(x-1)*np.random.rand()
                ry=(y-1)*np.random.rand()
                rz=(z-1)*np.random.rand()
                seed=np.ascontiguousarray(np.array([rx,ry,rz]),dtype=np.float64)        
                seeds[sid]=seed
                sid+=1
            
            euler = EuDX(a=FA, ind=tensors.ind(), seeds=seeds, a_low=.2)
            dt_tracks = [track for track in euler]                                    
            euler2 = EuDX(a=ds.PK, ind=ds.IN, seeds=seeds, odf_vertices=ds.odf_vertices, a_low=.2)
            ds_tracks = [track for track in euler2]    
            euler3 = EuDX(a=gq.PK, ind=gq.IN, seeds=seeds, odf_vertices=gq.odf_vertices, a_low=.2)
            gq_tracks = [track for track in euler3]
            euler4 = EuDX(a=ei.PK, ind=ei.IN, seeds=seeds, odf_vertices=ei.odf_vertices, a_low=.2)
            ei_tracks = [track for track in euler4]
            
            if visualize:
                renderer = fvtk.ren()
                fvtk.add(renderer, fvtk.line(tensor_tracks, fvtk.red, opacity=1.0))
                fvtk.show(renderer)
            
            print 'Load images to be used for registration'
            img_fa =nib.load(fa_filename)
            img_ref =nib.load(fsl_ref)
            mat=flirt2aff(np.loadtxt(flirt_mat),img_fa,img_ref)
            del img_fa
            del img_ref
            
            print 'transform the tracks'
            dt_linear = transform_tracks(dt_tracks,mat)
            ds_linear = transform_tracks(ds_tracks,mat)
            gq_linear = transform_tracks(gq_tracks,mat)
            ei_linear = transform_tracks(ei_tracks,mat)
                        
            print 'save tensor tracks'
            dpy_filename = base_dir + 'DTI/dt_linear.dpy'
            print dpy_filename
            dpr_linear = Dpy(dpy_filename, 'w')
            dpr_linear.write_tracks(dt_linear)
            dpr_linear.close()
            
            print 'save ei tracks'
            dpy_filename = base_dir + 'DTI/ei_linear.dpy'
            print dpy_filename
            dpr_linear = Dpy(dpy_filename, 'w')
            dpr_linear.write_tracks(ei_linear)
            dpr_linear.close()
            
            print 'save ds tracks'
            dpy_filename = base_dir + 'DTI/ds_linear.dpy'
            print dpy_filename
            dpr_linear = Dpy(dpy_filename, 'w')
            dpr_linear.write_tracks(ds_linear)
            dpr_linear.close()
            
            print 'save gq tracks'
            dpy_filename = base_dir + 'DTI/gq_linear.dpy'
            print dpy_filename
            dpr_linear = Dpy(dpy_filename, 'w')
            dpr_linear.write_tracks(gq_linear)
            dpr_linear.close()
            
            print 'save lengths'
            pkl_filename = base_dir + 'DTI/dt_lengths.pkl'
            save_pickle(pkl_filename,lengths(dt_linear))            
            pkl_filename = base_dir + 'DTI/ei_lengths.pkl'
            save_pickle(pkl_filename,lengths(ei_linear))
            pkl_filename = base_dir + 'DTI/gq_lengths.pkl'
            save_pickle(pkl_filename,lengths(gq_linear))
            pkl_filename = base_dir + 'DTI/ds_lengths.pkl'
            save_pickle(pkl_filename,lengths(ds_linear))
예제 #14
0
    print IND.shape
    print VERTS.shape
    
    all,allo=fvtk.crossing(A,IND,VERTS,scale,True)
    colors=np.zeros((len(all),3))
    for (i,a) in enumerate(all):
        if allo[i][0]==0 and allo[i][1]==0 and allo[i][2]==1:
            pass
        else:            
            colors[i]=cm.boys2rgb(allo[i])
    
    fvtk.add(r,fvtk.line(all,colors))    
    fvtk.show(r)


ten=Tensor(data,bvals,bvecs,mask)
FA=ten.fa()
FA[np.isnan(FA)]=0
eu=EuDX(FA,ten.ind(),seeds=10**4,a_low=fa_thr,length_thr=length_thr)
T =[e for e in eu]
#show(T,FA,ten.ind(),eu.odf_vertices,scale=1)

#r=fvtk.ren()
#fvtk.add(r,fvtk.point(eu.odf_vertices,cm.orient2rgb(eu.odf_vertices),point_radius=.5,theta=30,phi=30))
#fvtk.show(r)                     

gqs=GeneralizedQSampling(data,bvals,bvecs,Lambda=1.,mask=mask,squared=False)
eu2=EuDX(gqs.qa(),gqs.ind(),seeds=10**4,a_low=0,length_thr=length_thr)
T2=[e for e in eu2]
show(T2,gqs.qa(),gqs.ind(),eu2.odf_vertices,scale=1)
예제 #15
0
def create_FA_displacements_warp_FAs(fname,dname):

    fbvals=fname+'.bval'
    fbvecs=fname+'.bvec'       
    fdata=fname+'.nii.gz'
    
    if os.path.isfile(fdata):
        pass
    else:
        fdata=fname+'.nii'
        if os.path.isfile(fdata)==False:
            print('Data do not exist')
            return
     
    dti_dname=os.path.join(dname,'DTI')    
    if os.path.isdir(dti_dname):
        pass
    else:
        os.mkdir(dti_dname)
        
    local=dti_dname
    print('-------------------------')
    print('----Working with DTI-----')
    print('-------------------------')
    print local
    
    print('1.Remove the sculp using bet')
    fdatabet=fname+'_bet.nii.gz'
    bet(fdata,fdatabet)
    
    print('2.Load data and save S0')
    data,affine=load_img(fdatabet)
    fs0=pjoin(local,'S0_bet.nii.gz')
    #print fs0
    save_img(data[...,0],affine,fs0)
    
    print('3.Create Tensors and save FAs')
    bvals=np.loadtxt(fbvals)
    gradients=np.loadtxt(fbvecs).T
    ten=Tensor(data,bvals,gradients,thresh=50)
    ffa=pjoin(local,'FA_bet.nii.gz')
    print ffa
    save_img(ten.fa(),affine,ffa)
    fmd=pjoin(local,'MD_bet.nii.gz')
    #print fmd
    save_img(ten.md(),affine,fmd)
    
    print('4.Create the displacements using fnirt')
    fmat=pjoin(local,'flirt.mat')
    fnon=pjoin(local,'fnirt.nii.gz')
    finv=pjoin(local,'invw.nii.gz')
    fdis=pjoin(local,'dis.nii.gz')
    fdisa=pjoin(local,'disa.nii.gz')
    create_displacements(ffa,fmat,fnon,finv,fdis,fdisa)
    
    print('5.Warp FA')
    ffaw=pjoin(local,'FAW_bet.nii.gz')
    apply_warp(ffa,fmat,fnon,ffaw)
    ##warp_displacements(ffa,fmat,fdis,fref,ffaw2,order=1)
    
    print('6.Warp S0')
    fs0w=pjoin(local,'S0W_bet.nii.gz')
    apply_warp(fs0,fmat,fnon,fs0w)
    ##warp_displacements(fs0,fmat,fdis,fref,fs0w2,order=1)
    
    print('7.Warp MD')
    fmdw=pjoin(local,'MDW_bet.nii.gz')
    apply_warp(fmd,fmat,fnon,fmdw)
    ei=EquatorialInversion(dat,bvals,bvecs,odf_sphere='symmetric642',
            half_sphere_grads=True,auto=False,save_odfs=True,fast=True)
    ei.radius=np.arange(0,5,0.1)
    ei.gaussian_weight=0.05
    ei.set_operator('laplacian')
    ei.update()
    ei.fit()    

    ds=DiffusionSpectrum(dat,bvals,bvecs,
                         odf_sphere='symmetric642',
                         mask=None,
                         half_sphere_grads=True,
                         auto=True,
                         save_odfs=True)
    
    ten=Tensor(dat,bvals,bvecs)
    FA=ten.fa()

    #gq=GeneralizedQSampling(dat,bvals,bvecs,1.2,odf_sphere='symmetric642',squared=False,save_odfs=True)
    #gq2=GeneralizedQSampling(dat,bvals,bvecs,3.,odf_sphere='symmetric642',squared=True,save_odfs=True)    
    #show_blobs(ds.ODF,ds.odf_vertices,ds.odf_faces,FA.squeeze(),size=1.5,scale=1.)
    show_blobs(ei.ODF,ei.odf_vertices,ei.odf_faces,FA.squeeze(),size=1.5,scale=1.)

    """
    #dti reconstruction
    ten=Tensor(data,bvals,bvecs2,mask=mask)
    #generate tensor tracks with random seeds
    eu=EuDX(ten.fa(),ten.ind(),seeds=10000,a_low=0.2)
    tenT=[e for e in eu]
    #dsi reconstruction
    ds=DiffusionSpectrum(data,bvals,bvecs2,mask=mask)
예제 #17
0
        base_filename = base_dir + filename        

        nii_filename = base_filename + '_bet.nii.gz'
        bvec_filename = base_filename + '.bvec'
        bval_filename = base_filename + '.bval'        

        img = nib.load(nii_filename)
        data = img.get_data()
        affine = img.get_affine()

        bvals = np.loadtxt(bval_filename)
        gradients = np.loadtxt(bvec_filename).T # this is the unitary direction of the gradient

        base_dir2 = base_dir+ 'DTI/'   
        
        tensors = Tensor(data, bvals, gradients, thresh=50)
        create_save_tracks(tensors.fa(), tensors.ind(), 10**4, .2, base_dir2+'tracks_dti_10K_new.dpy')
      #  create_save_tracks(tensors.fa(), tensors.ind(), 10**6, .2, base_dir2+'tracks_dti_1M.dpy')
      #  create_save_tracks(tensors.fa(), tensors.ind(), 3*10**6, .2, base_dir2+'tracks_dti_3M.dpy')
#        
#        gqs=GeneralizedQSampling(data,bvals,gradients)
#        create_save_tracks(gqs.qa(), gqs.ind(), 10**4, .0239, base_dir2+'tracks_gqi_10K.dpy')
#        create_save_tracks(gqs.qa(), gqs.ind(), 10**6, .0239, base_dir2+'tracks_gqi_1M.dpy')
#        create_save_tracks(gqs.qa(), gqs.ind(), 3*10**6, .0239, base_dir2+'tracks_gqi_3M.dpy')
#        
             
        flirt_filename =base_dir2+'flirt.mat'
        fa_filename= base_dir2 + 'fa.nii.gz' 
        
        tracks_filename =  base_dir2+'tracks_dti_10K_new.dpy'
        linear_filename =  base_dir2+'tracks_dti_10K_linear_new.dpy'        
예제 #18
0
    ftracks=[ftracks_dti,ftracks_dsi,ftracks_gqi,ftracks_eit]

    #load data
    fraw=dname+'data.nii.gz'
    fbval=dname+'bvals'
    fbvec=dname+'bvecs'
    img = nib.load(fraw)
    data = img.get_data()
    affine = img.get_affine()
    bvals = np.loadtxt(fbval)
    gradients = np.loadtxt(fbvec).T

    print 'Data shape',data.shape
    t=time()
    #calculate FA
    tensors = Tensor(data, bvals, gradients, thresh=50)
    FA = tensors.fa()
    print 'ten',time()-t
    famask=FA>=.2

    maskimg=nib.Nifti1Image(famask.astype(np.uint8),affine)
    nib.save(maskimg,dname+'mask.nii.gz')

    #create seeds for first mask
    seeds=get_seeds(famask,3,1)
    print 'no of seeds', len(seeds)

    t=time()
    #GQI
    gqs=GeneralizedQSampling(data,bvals,gradients,1.2,
                odf_sphere='symmetric642',