Ejemplo n.º 1
0
def skeletonize_both():
    from dipy.viz import fos
    from dipy.core.track_metrics import downsample
    from dipy.core.track_performance import local_skeleton_clustering, most_similar_track_mam
    
    froi='/home/eg309/Data/ICBM_Wmpm/ICBM_WMPM.nii'
    wI=get_roi(froi,9,0) #4 is genu    
    fname='/home/eg309/Data/PROC_MR10032/subj_03/101/1312211075232351192010092217244332311282470ep2dadvdiffDSI10125x25x25STs004a001_QA_warp.dpy'
    #fname='/home/eg309/Data/PROC_MR10032/subj_03/101/1312211075232351192010092217244332311282470ep2dadvdiffDSI10125x25x25STs004a001_QA_native.dpy'
    #fname='/home/eg309/Data/PROC_MR10032/subj_06/101/13122110752323511930000010092916083910900000227ep2dadvdiffDSI10125x25x25STs004a001_QA_native.dpy'
    fname2='/home/eg309/Data/PROC_MR10032/subj_06/101/13122110752323511930000010092916083910900000227ep2dadvdiffDSI10125x25x25STs004a001_QA_warp.dpy'
    r=fos.ren()
    #'''
    dpr=Dpy(fname,'r')    
    T=dpr.read_indexed(range(2*10**4))
    dpr.close()    
    print len(T)    
    Td=[downsample(t,3) for t in T if length(t)>40]
    C=local_skeleton_clustering(Td,d_thr=20.)
    
    for c in C:
        #color=np.random.rand(3)
        color=fos.red
        if C[c]['N']>0:
            Ttmp=[]
            for i in C[c]['indices']:
                Ttmp.append(T[i])
            si,s=most_similar_track_mam(Ttmp,'avg')
            print si,C[c]['N']                
            fos.add(r,fos.line(Ttmp[si],color))                

    dpr=Dpy(fname2,'r')    
    T=dpr.read_indexed(range(2*10**4))
    dpr.close()    
    print len(T)    
    Td=[downsample(t,3) for t in T if length(t)>40]
    C=local_skeleton_clustering(Td,d_thr=20.)
    #r=fos.ren()
    for c in C:
        #color=np.random.rand(3)
        color=fos.yellow
        if C[c]['N']>0:
            Ttmp=[]
            for i in C[c]['indices']:
                Ttmp.append(T[i])
            si,s=most_similar_track_mam(Ttmp,'avg')
            print si,C[c]['N']                
            fos.add(r,fos.line(Ttmp[si],color))            
    #'''
    fos.add(r,fos.point(wI,fos.green))
    fos.show(r)
Ejemplo n.º 2
0
def tracks_in_roi():
    
    froi='/home/eg309/Data/ICBM_Wmpm/ICBM_WMPM.nii'
    wI=get_roi(froi,35,1) #4 is genu    
    fname='/home/eg309/Data/PROC_MR10032/subj_03/101/1312211075232351192010092217244332311282470ep2dadvdiffDSI10125x25x25STs004a001_QA_warp.dpy'
    dpr=Dpy(fname,'r')    
    T=dpr.read_indexed(range(2*10**4))
    print len(T)
    Troi=[]
    for t in T:        
        if track_roi_intersection_check(t,wI,.5):
            Troi.append(t)
    print(len(Troi))
    dpr.close()
    
    from dipy.viz import fos
    r=fos.ren()
    fos.add(r,fos.line(Troi,fos.red))
    fos.add(r,fos.point(wI,fos.green))
    fos.show(r)
Ejemplo n.º 3
0
def plot_sphere(v, key):
    r = fos.ren()
    fos.add(r, fos.point(v, fos.green, point_radius=0.01))
    fos.show(r, title=key, size=(1000, 1000))
Ejemplo n.º 4
0
def plot_sphere(v,key):
    r = fos.ren()
    fos.add(r,fos.point(v,fos.green, point_radius= 0.01))
    fos.show(r, title=key, size=(1000,1000))
Ejemplo n.º 5
0
def warp_tracks():
    dn='/home/eg309/Data/TEST_MR10032/subj_03/101/'
    ffa=dn+'1312211075232351192010092217244332311282470ep2dadvdiffDSI10125x25x25STs004a001_bet_FA.nii.gz'    
    finvw=dn+'1312211075232351192010092217244332311282470ep2dadvdiffDSI10125x25x25STs004a001_warps_in_bet_FA.nii.gz'    
    fqadpy=dn+'1312211075232351192010092217244332311282470ep2dadvdiffDSI10125x25x25STs004a001_QA_native.dpy'
    flaff=dn+'1312211075232351192010092217244332311282470ep2dadvdiffDSI10125x25x25STs004a001_affine_transf.mat'
    fref ='/usr/share/fsl/data/standard/FMRIB58_FA_1mm.nii.gz'    
    fdis =dn+'1312211075232351192010092217244332311282470ep2dadvdiffDSI10125x25x25STs004a001_nonlin_displacements.nii.gz'
    fdis2 =dn+'1312211075232351192010092217244332311282470ep2dadvdiffDSI10125x25x25STs004a001_nonlin_displacements_withaff.nii.gz'
    #read some tracks
    dpr=Dpy(fqadpy,'r')
    T=dpr.read_indexed(range(150))
    dpr.close()
    
    #from fa index to ref index
    res=flirt2aff_files(flaff,ffa,fref)
    
    #load the reference img    
    imgref=ni.load(fref)
    refaff=imgref.get_affine()
    
    #load the invwarp displacements
    imginvw=ni.load(finvw)
    invwdata=imginvw.get_data()
    invwaff = imginvw.get_affine()
    
    #load the forward displacements
    imgdis=ni.load(fdis)
    disdata=imgdis.get_data()
    #load the forward displacements + affine
    imgdis2=ni.load(fdis2)
    disdata2=imgdis2.get_data()
    #from their difference create the affine
    disaff=imgdis2.get_data()-disdata  
    
    shift=np.array([disaff[...,0].mean(),disaff[...,1].mean(),disaff[...,2].mean()])
    
    shape=ni.load(ffa).get_data().shape
    
    disaff0=affine_transform(disaff[...,0],res[:3,:3],res[:3,3],shape,order=1)
    disaff1=affine_transform(disaff[...,1],res[:3,:3],res[:3,3],shape,order=1)
    disaff2=affine_transform(disaff[...,2],res[:3,:3],res[:3,3],shape,order=1)
    
    disdata0=affine_transform(disdata[...,0],res[:3,:3],res[:3,3],shape,order=1)
    disdata1=affine_transform(disdata[...,1],res[:3,:3],res[:3,3],shape,order=1)
    disdata2=affine_transform(disdata[...,2],res[:3,:3],res[:3,3],shape,order=1)
    
    #print disgrad0.shape,disgrad1.shape,disgrad2.shape
    #disdiff=np.empty(invwdata.shape)
    #disdiff[...,0]=disgrad0
    #disdiff[...,1]=disgrad1
    #disdiff[...,2]=disgrad2
    #ni.save(ni.Nifti1Image(disdiff,invwaff),'/tmp/disdiff.nii.gz')
    
    di=disdata0
    dj=disdata1
    dk=disdata2
    
    d2i=invwdata[:,:,:,0] + disaff0
    d2j=invwdata[:,:,:,1] + disaff1
    d2k=invwdata[:,:,:,2] + disaff2
    
    #di=disgrad0
    #dj=disgrad1
    #dk=disgrad2
    
    imgfa=ni.load(ffa)
    fadata=imgfa.get_data()
    faaff =imgfa.get_affine()
    
    Tw=[]
    Tw2=[]
    Tw3=[]
    
    froi='/home/eg309/Data/ICBM_Wmpm/ICBM_WMPM.nii'    
    
    roiI=get_roi(froi,3,1) #3 is GCC     
    roiI2=get_roi(froi,4,1) #4 is BCC
    roiI3=get_roi(froi,5,1) #4 is SCC
    roiI=np.vstack((roiI,roiI2,roiI3))  
  
    for t in T:
        if np.min(t[:,2])>=0:#to be removed
            mci=mc(di,t.T,order=1) #interpolations for i displacement
            mcj=mc(dj,t.T,order=1) #interpolations for j displacement
            mck=mc(dk,t.T,order=1) #interpolations for k displacement            
            D=np.vstack((mci,mcj,mck)).T                        
            WI=np.dot(t,res[:3,:3].T)+res[:3,3]+D#+ shift
            W=np.dot(WI,refaff[:3,:3].T)+refaff[:3,3]
            
            mc2i=mc(d2i,t.T,order=1) #interpolations for i displacement
            mc2j=mc(d2j,t.T,order=1) #interpolations for j displacement
            mc2k=mc(d2k,t.T,order=1) #interpolations for k displacement            
            D2=np.vstack((mc2i,mc2j,mc2k)).T                        
            WI2=np.dot(t,res[:3,:3].T)+res[:3,3]+D2 #+ shift
            W2=np.dot(WI2,refaff[:3,:3].T)+refaff[:3,3]
                        
            WI3=np.dot(t,res[:3,:3].T)+res[:3,3]
            W3=np.dot(WI3,refaff[:3,:3].T)+refaff[:3,3]
            
            Tw.append(W)
            Tw2.append(W2)
            Tw3.append(W3)
    

    from dipy.viz import fos
    r=fos.ren()
    fos.add(r,fos.line(Tw,fos.red))
    fos.add(r,fos.line(Tw2,fos.green))    
    fos.add(r,fos.line(Tw3,fos.yellow))
    fos.add(r,fos.sphere((0,0,0),10,color=fos.blue))
    fos.add(r,fos.point(roiI,fos.blue))
    fos.show(r)
Ejemplo n.º 6
0
    I=np.array(np.where(roidata==no)).T    
    wI=np.dot(roiaff[:3,:3],I.T).T+roiaff[:3,3]
    wI=wI.astype('f4')
    return wI
    


from dipy.viz import fos

r=fos.ren()
#fos.add(r,fos.point(wI,fos.blue))
#fos.add(r,fos.point(wI2,fos.yellow))
#fos.add(r,fos.point(wI3,fos.green))
#fos.add(r,fos.point(wrefI,fos.cyan))
#fos.add(r,fos.point(wrefI,fos.yellow))
fos.add(r,fos.point(get_roi(froi,3),fos.blue))
fos.add(r,fos.point(get_roi(froi,4),fos.yellow))
fos.add(r,fos.point(get_roi(froi,5),fos.green))

fos.add(r,fos.line(Tfinal,fos.red))
fos.show(r)

print roiaff
print roiaff2
print roiaff3
print daff




Ejemplo n.º 7
0
    I=np.array(np.where(roidata==no)).T    
    wI=np.dot(roiaff[:3,:3],I.T).T+roiaff[:3,3]
    wI=wI.astype('f4')
    return wI
    


from dipy.viz import fos

r=fos.ren()
#fos.add(r,fos.point(wI,fos.blue))
#fos.add(r,fos.point(wI2,fos.yellow))
#fos.add(r,fos.point(wI3,fos.green))
#fos.add(r,fos.point(wrefI,fos.cyan))
#fos.add(r,fos.point(wrefI,fos.yellow))
fos.add(r,fos.point(get_roi(froi,3),fos.blue))
fos.add(r,fos.point(get_roi(froi,4),fos.yellow))
fos.add(r,fos.point(get_roi(froi,5),fos.green))

fos.add(r,fos.line(Tfinal,fos.red))
fos.show(r)

print roiaff
print roiaff2
print roiaff3
print daff