Пример #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)
Пример #2
0
def bundle_from_refs(brain,braind, refs, divergence_threshold=0.3, fibre_weight=0.7,far_thresh=25,zhang_thresh=15, end_thresh=10):
    '''
    '''
    bundle = set([])
    centres = []
    indices = []

    for ref in refs:        
        
        refd=tm.downsample(ref,3)         
        brain_rf, ind_fr = rm_far_tracks(refd,braind,dist=far_thresh,down=True)        
        brain_rf=[brain[i] for i in ind_fr]        
        #brain_rf,ind_fr = rm_far_tracks(ref,brain,dist=far_thresh,down=False)        
        heavy_weight_fibres, index, centre = refconc(brain_rf, ref, divergence_threshold, fibre_weight)        
        heavy_weight_fibres_z = [i for i in heavy_weight_fibres if pf.zhang_distances(ref,brain_rf[i],'avg')<zhang_thresh]        
        #heavy_weight_fibres_z_e = [i for i in heavy_weight_fibres_z if tm.max_end_distances(brain_rf[i],ref)>end_thresh]        
        hwfind = set([ind_fr[i] for i in heavy_weight_fibres_z])        
        bundle = bundle.union(hwfind)

    bundle_med = []
    
    for i in bundle:        
        minmaxdist = 0.
        for ref in refs:
            minmaxdist=min(minmaxdist,tm.max_end_distances(brain[i],ref))
        if minmaxdist<=end_thresh:
            bundle_med.append(i)            
        #centres.append(centre)        
        #indices.append(index)
    
    #return list(bundle), centres, indices
    return bundle_med
Пример #3
0
def bundle_from_refs(brain,braind, refs, divergence_threshold=0.3, fibre_weight=0.7,far_thresh=25,zhang_thresh=15, end_thresh=10):
    '''
    '''
    bundle = set([])
    # centres = []
    # indices = []

    for ref in refs:        
        
        refd=tm.downsample(ref,3)         
        brain_rf, ind_fr = rm_far_tracks(refd,braind,dist=far_thresh,down=True)        
        brain_rf=[brain[i] for i in ind_fr]        
        #brain_rf,ind_fr = rm_far_tracks(ref,brain,dist=far_thresh,down=False)        
        heavy_weight_fibres, index, centre = refconc(brain_rf, ref, divergence_threshold, fibre_weight)        
        heavy_weight_fibres_z = [i for i in heavy_weight_fibres if pf.zhang_distances(ref,brain_rf[i],'avg')<zhang_thresh]        
        #heavy_weight_fibres_z_e = [i for i in heavy_weight_fibres_z if tm.max_end_distances(brain_rf[i],ref)>end_thresh]        
        hwfind = set([ind_fr[i] for i in heavy_weight_fibres_z])        
        bundle = bundle.union(hwfind)

    bundle_med = []
    
    for i in bundle:        
        minmaxdist = 0.
        for ref in refs:
            minmaxdist=min(minmaxdist,tm.max_end_distances(brain[i],ref))
        if minmaxdist<=end_thresh:
            bundle_med.append(i)            
        #centres.append(centre)        
        #indices.append(index)
    
    #return list(bundle), centres, indices
    return bundle_med
Пример #4
0
def rm_far_tracks(ref, tracks, dist=25, down=False):
    """ Remove tracks which are far away using as a distance metric the average
    euclidean distance of the following three points start point, midpoint and
    end point.

    Parameters
    ----------
    ref : array, shape (N,3)
       xyz points of the reference track
    tracks : sequence 
       of tracks as arrays, shape (N1,3) .. (Nm,3)
    dist : float
       average distance threshold
    down: bool {True, False}
       if down = True then ref and tracks are already downsampled
       if down = False then downsample them
    
    Returns
    -------
    tracksr : sequence
            reduced tracks
    indices : sequence
            indices of tracks
    """

    if down == False:

        tracksd = [tm.downsample(t, 3) for t in tracks]
        refd = tm.downsample(ref, 3)

        indices = [
            i for (i, t) in enumerate(tracksd)
            if np.mean(np.sqrt(np.sum((t - refd)**2, axis=1))) <= dist
        ]

        tracksr = [tracks[i] for i in indices]
        return tracksr, indices

    if down == True:

        indices = [
            i for (i, t) in enumerate(tracks)
            if np.mean(np.sqrt(np.sum((t - ref)**2, axis=1))) <= dist
        ]
        tracksr = [tracks[i] for i in indices]
        return tracksr, indices
Пример #5
0
def rm_far_tracks(ref,tracks,dist=25,down=False):
    """ Remove tracks which are far away using as a distance metric the average
    euclidean distance of the following three points start point, midpoint and
    end point.

    Parameters
    ----------
    ref : array, shape (N,3)
       xyz points of the reference track
    tracks : sequence 
       of tracks as arrays, shape (N1,3) .. (Nm,3)
    dist : float
       average distance threshold
    down: bool {True, False}
       if down = True then ref and tracks are already downsampled
       if down = False then downsample them
    
    Returns
    -------
    tracksr : sequence
            reduced tracks
    indices : sequence
            indices of tracks
    """

    if down==False:
        
        tracksd=[tm.downsample(t,3) for t in tracks]
        refd=tm.downsample(ref,3) 
        
        indices=[i for (i,t) in enumerate(tracksd) if np.mean(np.sqrt(np.sum((t-refd)**2,axis=1))) <= dist]
        
        tracksr=[tracks[i] for i in indices]
        return tracksr, indices
    
    if down==True:
        
        indices=[i for (i,t) in enumerate(tracks) if np.mean(np.sqrt(np.sum((t-ref)**2,axis=1))) <= dist]
        tracksr=[tracks[i] for i in indices]
        return tracksr,indices
Пример #6
0
def skeletonize():
    
    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'
    #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'
    fname='/home/eg309/Data/PROC_MR10032/subj_06/101/13122110752323511930000010092916083910900000227ep2dadvdiffDSI10125x25x25STs004a001_QA_warp.dpy'
    
    dpr=Dpy(fname,'r')    
    T=dpr.read_indexed(range(2*10**4))
    dpr.close()
    
    print len(T)    
    from dipy.core.track_metrics import downsample
    from dipy.core.track_performance import local_skeleton_clustering, most_similar_track_mam
    Td=[downsample(t,3) for t in T]
    C=local_skeleton_clustering(Td,d_thr=20.)
    
    #Tobject=np.array(T,dtype=np.object)
    
    from dipy.viz import fos
    r=fos.ren()
    
    #skeleton=[]
    
    for c in C:
        color=np.random.rand(3)
        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))
            
    #print len(skeleton)
    #fos.add(r,fos.line(skeleton,color))    
    #fos.add(r,fos.line(T,fos.red))    
    fos.show(r)
Пример #7
0
def skeletal_tracks(tracks, rand_selected=1000, ball_radius=5, neighb_no=50):
    ''' Filter out unnescessary tracks and keep only a few good ones.  
    Aka the balls along a track method.  
    
    Parameters:
    ----------------
    tracks: sequence
            of tracks
    rand_selected: int
            number of initially selected fibers
    ball_radius: float
            balls along tracks radii
    neighb_no: int
            lowest threshold for the number of tracks included 
    
    Returns:
    -----------
    reps: sequence
            of indices of representative aka skeletal tracks. They should be <= rand_selected
    
    
    '''
    trackno = len(tracks)
    #select 1000 random tracks
    random_indices = (trackno * np.random.rand(rand_selected)).astype(int)

    tracks3points = [tm.downsample(t, 3) for t in tracks]

    #store representative tracks
    representative = []
    representative_indices = []

    #store indices of already visited tracks i.e. which already have a representative track
    visited = []

    import time
    t1 = time.clock()

    # for every index of the possible representative tracks
    for (i, t) in enumerate(random_indices):

        #if track is not already classified
        if i not in visited:

            print(i, t)

            #rm far tracks
            tracksr, indices = rm_far_tracks(tracks3points[t],
                                             tracks3points,
                                             dist=25,
                                             down=True)

            cnt_neighb = 0
            just_visited = []

            #for every possible neighbour track tr with index tri
            for tri in indices:

                cnt_intersected_balls = 0

                #for every point of the possible representative track
                for p in tracks[t]:

                    #if you intersect the sphere surrounding the point of the random track increase a counter
                    if tm.inside_sphere(tracks[tri], p, ball_radius):
                        cnt_intersected_balls += 1

                #if all spheres are covered then accept this track as your neighbour
                if cnt_intersected_balls == len(tracks[t]):

                    cnt_neighb += 1
                    just_visited.append(tri)

            #if the number of possible neighbours is above threshold then accept track[t] as a representative fiber
            if cnt_neighb >= neighb_no:
                representative.append(t)
                visited = visited + just_visited

    print 'Time:', time.clock() - t1

    return representative
Пример #8
0
from dipy.core import track_performance as pf
import time
import numpy as np


#fname='/home/eg01/Data/PBC/pbc2009icdm/brain1/brain1_scan1_fiber_track_mni.trk'
fname='/home/eg309/Data/PBC/pbc2009icdm/brain1/brain1_scan1_fiber_track_mni.trk'

print 'Loading file...'
streams,hdr=tv.read(fname)

print 'Copying tracks...'
T=[i[0] for i in streams]

print 'Representing tracks using only 3 pts...'
tracks=[tm.downsample(t,3) for t in T]

print 'Deleting unnecessary data...'
del streams,hdr

print 'Hidden Structure Clustering...'
now=time.clock()
C=pf.local_skeleton_clustering(tracks,d_thr=20)
print 'Done in', time.clock()-now,'s.'

print 'Reducing the number of points...'
T=[pf.approximate_ei_trajectory(t) for t in T]

print 'Showing initial dataset.'
r=fos.ren()
fos.add(r,fos.line(T,fos.white,opacity=0.1))
Пример #9
0
#Apply thresholds

tracks1=[t for t in tracks1 if tm.length(t) > min_len]
tracks2=[t for t in tracks2 if tm.length(t) > min_len]
tracks3=[t for t in tracks3 if tm.length(t) > min_len]

print 'After thresholding'

print len(tracks1)
print len(tracks2)
print len(tracks3)

print 'Downsampling'

tracks1z=[tm.downsample(t,down) for t in tracks1] 
tracks2z=[tm.downsample(t,down) for t in tracks2] 
tracks3z=[tm.downsample(t,down) for t in tracks3] 

print 'Detecting random tracks'

lt1=len(tracks1)
lt2=len(tracks2)
lt3=len(tracks3)

if rand_tracks==-1:
	#use already stored indices
	t_ind=corr_mat_demo[:,1]
else:
	
	#find the size in number of tracks of the smallest dataset
Пример #10
0
def skeletal_tracks(tracks,rand_selected=1000,ball_radius=5,neighb_no=50):
    ''' Filter out unnescessary tracks and keep only a few good ones.  
    Aka the balls along a track method.  
    
    Parameters:
    ----------------
    tracks: sequence
            of tracks
    rand_selected: int
            number of initially selected fibers
    ball_radius: float
            balls along tracks radii
    neighb_no: int
            lowest threshold for the number of tracks included 
    
    Returns:
    -----------
    reps: sequence
            of indices of representative aka skeletal tracks. They should be <= rand_selected
    
    
    '''
    trackno=len(tracks)
    #select 1000 random tracks
    random_indices=(trackno*np.random.rand(rand_selected)).astype(int)
    
    tracks3points=[tm.downsample(t,3) for t in tracks]
    
    #store representative tracks
    representative=[]       
    representative_indices=[]       
    
    #store indices of already visited tracks i.e. which already have a representative track
    visited=[]
    
    import time
    t1=time.clock()
    
    # for every index of the possible representative tracks
    for (i,t) in enumerate(random_indices):        
        
        #if track is not already classified 
        if i not in visited:
            
            print(i,t)
            
            #rm far tracks
            tracksr,indices=rm_far_tracks(tracks3points[t],tracks3points,dist=25,down=True)
                    
            cnt_neighb=0            
            just_visited=[]
            
            #for every possible neighbour track tr with index tri
            for tri in indices:                   
                
                cnt_intersected_balls=0
                
                #for every point of the possible representative track 
                for p in tracks[t]:
                    
                    #if you intersect the sphere surrounding the point of the random track increase a counter
                    if tm.inside_sphere(tracks[tri],p,ball_radius): cnt_intersected_balls+=1
                
                #if all spheres are covered then accept this track as your neighbour
                if cnt_intersected_balls ==len(tracks[t]): 
                    
                    cnt_neighb+=1                
                    just_visited.append(tri)
            
            #if the number of possible neighbours is above threshold then accept track[t] as a representative fiber
            if cnt_neighb>=neighb_no: 
                representative.append(t)                
                visited=visited+just_visited
    
    print 'Time:',time.clock()-t1
    
    return representative
Пример #11
0
    def init(self):


        br1path='/home/eg01/Data_Backup/Data/Eleftherios/CBU090133_METHODS/20090227_145404/Series_003_CBU_DTI_64D_iso_1000/dtk_dti_out/dti_FACT.trk'

        br2path='/home/eg01/Data_Backup/Data/Eleftherios/CBU090134_METHODS/20090227_154122/Series_003_CBU_DTI_64D_iso_1000/dtk_dti_out/dti_FACT.trk'

        br3path='/home/eg01/Data_Backup/Data/Eleftherios/CBU090133_METHODS/20090227_145404/Series_003_CBU_DTI_64D_iso_1000/dtk_dti_out/dti_RK2.trk'


        min_len=20

        down=20

        rand_tracks=-1 #default 10 min_search_len=70
        
        min_search_len=70
        
        max_search_len=140


        corr_mat_demo=np.array([[ 1, 10560,  3609],[ 2, 17872, 15377],[ 3,  6447,  3897], [4, 18854,  6409], [ 5, 14416,  4515], [ 7,  9956, 13913], [8, 10853, 15572], [ 9, 13280,  8461], [ 0, 11275,  9224]])


        print 'Minimum track length', min_len, 'mm'
        print 'Number of segments for downsampling',down
        print 'Number of tracks for detection',rand_tracks
        print 'Minimum searched track length', min_search_len, 'mm'
        print 'Maximum searched track length', max_search_len, 'mm'

        tracks1,hdr1=tv.read(br1path)

        tracks2,hdr2=tv.read(br2path)

        tracks3,hdr3=tv.read(br3path)

        #Load only track points, no scalars or parameters.

        tracks1=[t[0] for t in tracks1]

        tracks2=[t[0] for t in tracks2]

        tracks3=[t[0] for t in tracks3]

        print 'Before thresholding'

        print len(tracks1)

        print len(tracks2)

        print len(tracks3)

        print hdr1['dim']

        print hdr2['dim']

        print hdr3['dim']

        #Apply thresholds

        tracks1=[t for t in tracks1 if tm.length(t) > min_len]

        tracks2=[t for t in tracks2 if tm.length(t) > min_len]

        tracks3=[t for t in tracks3 if tm.length(t) > min_len]

        print 'After thresholding'

        print len(tracks1)
        print len(tracks2)
        print len(tracks3)

        print 'Downsampling'

        tracks1z=[tm.downsample(t,down) for t in tracks1]

        tracks2z=[tm.downsample(t,down) for t in tracks2]

        tracks3z=[tm.downsample(t,down) for t in tracks3] 

        print 'Detecting random tracks'

        lt1=len(tracks1)

        lt2=len(tracks2)

        lt3=len(tracks3)

        if rand_tracks==-1:
            
	    #use already stored indices
            t_ind=corr_mat_demo[:,1]
            
				
	t_ind=np.array(t_ind)

        print 'Indices of tracks for detection', t_ind

        print 'Finding corresponding tracks'

        global track2track        
        track2track= self.corresponding_tracks(t_ind,tracks1z,tracks2z)

        global track2track2
        track2track2=self.corresponding_tracks(t_ind,tracks1z,tracks3z)

        print 'First Correspondance Matrix'
        print track2track

        print 'Second Correspondance Matrix'
        print track2track2

        print 'first brain'
        print track2track[:,1].T

        print 'second brain'
        print track2track[:,2].T

        print 'third brain'
        print track2track2[:,2].T


        #fos.add(r,fos.line(tracks1,fos.red,opacity=0.01))
        #fos.add(r,fos.line(tracks2,fos.cyan,opacity=0.01))

        tracks1zshift = tracks1z
        tracks2zshift = tracks2z
        tracks3zshift = tracks3z

        m1z=np.concatenate(tracks1zshift).mean(axis=0)
        
        m2z=np.concatenate(tracks2zshift).mean(axis=0)

        m3z=np.concatenate(tracks3zshift).mean(axis=0)

        #tracks1zshift=[t+np.array([-70,0,0]) for t in tracks1z]

        #tracks2zshift=[t+np.array([70,0,0]) for t in tracks2z]

        tracks1zshift=[t-m1z for t in tracks1z]
        
        tracks2zshift=[t-m2z for t in tracks2z]
          
        tracks3zshift=[t-m3z for t in tracks3z]


        global t1

        #devel07

        t1=tracks.Tracks(None,data_ext=tracks1zshift)

        t1.angular_speed = 0.1

        t1.brain_color=[1,0,0]

        t1.manycolors=False

        t1.opacity = 0.01

        t1.orbit_demo=True

        t1.orbit_anglez_rate = 0.
                
        t1.orbit_anglex_rate = 0.

        t1.orbit_angley_rate = .2

        

        t1.init()

        t1.position = np.array([-120,0,-30])

        print 't1p',t1.position

        

        global t2

        #devel07

        t2=tracks.Tracks(None,data_ext=tracks2zshift)

        t2.angular_speed = 0.1

        t2.brain_color=[0,1,1]

        t2.manycolors=False

        t2.opacity = 0.01

        t2.orbit_demo=True

        t2.orbit_anglez_rate = 0.
                
        t2.orbit_anglex_rate = 0.

        t2.orbit_angley_rate = .2

        t2.init()
        
        t2.position = np.array([0,0,-30])

        print 't2p', t2.position
        
        

        global t3

        #devel07

        t3=tracks.Tracks(None,data_ext=tracks3zshift)

        t3.angular_speed = 0.1

        t3.manycolors=False

        t3.brain_color=[0,0,1]

        t3.opacity = 0.01

        t3.orbit_demo=True

        t3.orbit_anglez_rate = 0.
                
        t3.orbit_anglex_rate = 0.

        t3.orbit_angley_rate = .2        

        t3.init()
        
        #t3.position = -
        #np.concatenate(tracks3zshift).mean(axis=0)+np.array([70,0,0])

        t3.position = np.array([120,0,-30])

        print 't3p', t3.position
        
        

        self.slots={0:{'actor':t1,'slot':( 0, 800*MS ) },
                    1:{'actor':t2,'slot':( 0, 800*MS ) },
                    2:{'actor':t3,'slot':( 0, 800*MS ) }}
Пример #12
0
    return C


def most(C):

    for c in C:
        pass  # pf.most_similar_track_mam()


T = pkl.load_pickle(fname)

print 'Reducing the number of points...'
T = [pf.approx_polygon_track(t) for t in T]

print 'Reducing further to tracks with 3 pts...'
T2 = [tm.downsample(t, 3) for t in T]

print 'LARCH ...'
print 'Splitting ...'
t = time.clock()
C = pf.larch_3split(T2, None, 5.)
print time.clock() - t, len(C)

for c in C:
    print c, C[c]['rep3'] / C[c]['N']

r = show_rep3(C)

print 'Merging ...'
t = time.clock()
C = merge(C, 5.)
Пример #13
0

def most(C):

    for c in C:
        
        pass'pf.most_similar_track_zhang()


T=pkl.load_pickle(fname)

print 'Reducing the number of points...'
T=[pf.approximate_ei_trajectory(t) for t in T]

print 'Reducing further to tracks with 3 pts...'
T2=[tm.downsample(t,3) for t in T]

print 'LARCH ...'
print 'Splitting ...'
t=time.clock()
C=pf.larch_3split(T2,None,5.)
print time.clock()-t, len(C)

for c in C: print c, C[c]['rep3']/C[c]['N']

r=show_rep3(C)


print 'Merging ...'
t=time.clock()
C=merge(C,5.)
Пример #14
0
    def display(self):


        if self.near_pick!= None:

            #print self.near_pick

            if np.sum(np.equal(self.near_pick, self.near_pick_prev))< 3:        

                self.process_picking(self.near_pick, self.far_pick)             
              
                self.near_pick_prev = self.near_pick

                self.far_pick_prev = self.far_pick
      

                
        
    
        x,y,z=self.position

        if self.orbit_demo and self.angle_table == None:

            gl.glPushMatrix()

            self.orbit_anglex+=self.orbit_anglex_rate
            
            gl.glRotatef(self.orbit_anglex,1,0,0)

            gl.glPushMatrix()

            self.orbit_anglez+=self.orbit_anglez_rate

            x,y,z=self.position

           

            gl.glRotatef(self.orbit_anglez,0,0,1)

            gl.glTranslatef(x,y,z) 


            #gl.glPolygonMode(gl.GL_FRONT_AND_BACK, gl.GL_LINE)

            gl.glCallList(self.list_index)

            gl.glFinish()

            gl.glPopMatrix()

            gl.glPopMatrix()


        elif self.orbit_demo == True and self.angle_table != None:

            
            
            gl.glPushMatrix()

            #print angle_table

            #print table_ind

            global angle_table_index

            table_ind=angle_table_index

            anglex=angle_table[table_ind,0]

            #print anglex

            gl.glRotatef(anglex,1,0,0)
            
            
            gl.glPushMatrix()

            angley=angle_table[table_ind,1]

            gl.glRotatef(angley,0,1,0)
            

            gl.glPushMatrix()

            anglez=angle_table[table_ind,2]

            gl.glRotatef(anglez,0,0,1)


            gl.glTranslate(x,y,z)
            
            gl.glCallList(self.list_index)

            gl.glFinish()

            gl.glPopMatrix()

            gl.glPopMatrix()

            gl.glPopMatrix()

            angle_table_index += 1

            if angle_table_index >= angle_table.shape[0]:
                
                angle_table_index = angle_table.shape[0] - 1

            

            '''

            gl.glPushMatrix()

            gl.glRotatef(self.angle_table[self.angle_table_index,0],1,0,0)

            #x,y,z = self.position
            
            gl.glPushMatrix()

            gl.glRotatef(self.angle_table[self.angle_table_index,1],0,1,0)

            gl.glPushMatrix()

            gl.glRotatef(self.angle_table[self.angle_table_index,2],0,0,1)

            gl.glTranslate(x,y,z)
            
            gl.glCallList(self.list_index)

            gl.glFinish()

            gl.glPopMatrix()

            gl.glPopMatrix()

            gl.glPopMatrix()

            self.angle_table_index += 1

            if self.angle_table_index >= self.angle_table.shape[0]:
                
                self.angle_table_index = self.angle_table.shape[0] - 1

            '''
            
        else:

            gl.glCallList(self.list_index)




            if self.picked_track != None:

                self.display_one_track(self.picked_track)



            if self.yellow_indices != None:

                for i in self.yellow_indices:


                    self.display_one_track(i)


        if self.text != None:

            gl.glDisable(gl.GL_LIGHTING)
            
            gl.glColor3f(0.,0.47,.76)

            for (i,t) in enumerate(self.data):

                #gl.glRasterPos3f(t[0][0],t[0][1],t[0][2])
            
                label = self.text+str(i)

                t2=tm.downsample(t,3)

                gl.glRasterPos3f(t2[1][0],t2[1][1],t2[1][2])
                
                for c in label:

                    glut.glutBitmapCharacter(glut.GLUT_BITMAP_TIMES_ROMAN_24, ord(c))
                

                '''

                if i == 22: #cortico spinal track

                    gl.glRasterPos3f(t[0][0],t[0][1],t[0][2])


                    label='spine'

                    for c in label:

                        glut.glutBitmapCharacter(glut.GLUT_BITMAP_TIMES_ROMAN_24, ord(c))

                    gl.glRasterPos3f(t[-1][0],t[-1][1],t[-1][2])


                    label='motor'

                    for c in label:

                        glut.glutBitmapCharacter(glut.GLUT_BITMAP_TIMES_ROMAN_24, ord(c))

                    

                    label='corticospinal'

                    t2=tm.downsample(t,len(label)+3)

                    for (ci,c) in enumerate(label[::-1]):
                        
                        gl.glRasterPos3f(t2[ci+2][0],t2[ci+2][1],t2[ci+2][2])

                        glut.glutBitmapCharacter(glut.GLUT_BITMAP_TIMES_ROMAN_24, ord(c))

                else:

                    pass

                '''
                

                '''

                    gl.glRasterPos3f(t[0][0],t[0][1],t[0][2])

                    for c in label:

                        glut.glutBitmapCharacter(glut.GLUT_BITMAP_TIMES_ROMAN_24, ord(c))

                '''
                
            gl.glEnable(gl.GL_LIGHTING)

        gl.glFinish()        
#fname='/home/eg309/Data/PBC/pbc2009icdm/brain1/brain1_scan1_fiber_track_mni.trk'

opacity = 0.5

print 'Loading file...'
streams, hdr = tv.read(fname)

print 'Copying tracks...'
T = [i[0] for i in streams]

T = T[:len(T) / 5]

#T=T[:1000]

print 'Representing tracks using only 3 pts...'
tracks = [tm.downsample(t, 3) for t in T]

print 'Deleting unnecessary data...'
del streams, hdr

print 'Local Skeleton Clustering...'
now = time.clock()
C = pf.local_skeleton_clustering(tracks, d_thr=20)
print 'Done in', time.clock() - now, 's.'

print 'Reducing the number of points...'
T = [pf.approx_polygon_track(t) for t in T]

print 'Showing initial dataset.'

#r=fos.ren()
Пример #16
0
    def multiple_colors(self):

        from dipy.viz.colormaps import boys2rgb

        from dipy.core.track_metrics import mean_orientation, length, downsample

        colors=np.random.rand(1,3).astype(np.float32)

        print colors

        self.list_index = gl.glGenLists(1)

        gl.glNewList( self.list_index,gl.GL_COMPILE)

        #gl.glPushMatrix()

        gl.glDisable(gl.GL_LIGHTING)
        
        #!!!gl.glEnable(gl.GL_LINE_SMOOTH)

        gl.glDisable(gl.GL_DEPTH_TEST)

        #gl.glDepthFunc(gl.GL_NEVER)

        gl.glEnable(gl.GL_BLEND)

        gl.glBlendFunc(gl.GL_SRC_ALPHA,gl.GL_ONE_MINUS_SRC_ALPHA)

        #gl.glBlendFunc(gl.GL_SRC_ALPHA_SATURATE,gl.GL_ONE_MINUS_SRC_ALPHA)
        
        #gl.glBlendFunc(gl.GL_SRC_ALPHA,gl.GL_ONE)

        #!!!gl.glHint(gl.GL_LINE_SMOOTH_HINT,gl.GL_DONT_CARE)

        #gl.glHint(gl.GL_LINE_SMOOTH_HINT,gl.GL_NICEST)

        gl.glLineWidth(self.line_width)

        #gl.glDepthMask(gl.GL_FALSE)


        gl.glEnableClientState(gl.GL_VERTEX_ARRAY)        

        for d in self.data:

            if length(d)> self.min_length:
            
                #mo=mean_orientation(d)

                if self.manycolors:
                
                    ds=downsample(d,6)

                    mo=ds[3]-ds[2]

                    mo=mo/np.sqrt(np.sum(mo**2))

                    mo.shape=(1,3)
            
                    color=boys2rgb(mo)

                    color4=np.array([color[0][0],color[0][1],color[0][2],self.opacity],np.float32)
                    

                else:

                    color4=np.array([self.brain_color[0],self.brain_color[1],\
                                         self.brain_color[2],self.opacity],np.float32)


                if self.fadein == True:

                    color4[3] += self.fadein_speed

                if self.fadeout == True:

                    color4[3] -= self.fadeout_speed

                gl.glColor4fv(color4)                

                gl.glVertexPointerf(d)
                               
                gl.glDrawArrays(gl.GL_LINE_STRIP, 0, len(d))

        

        gl.glDisableClientState(gl.GL_VERTEX_ARRAY)

        #gl.glDisable(gl.GL_BLEND)
        
        gl.glEnable(gl.GL_LIGHTING)

        gl.glEnable(gl.GL_DEPTH_TEST)
        
        #gl.glPopMatrix()

        gl.glEndList()
Пример #17
0
    def multiple_colors(self):

        from dipy.viz.colormaps import boys2rgb

        from dipy.core.track_metrics import mean_orientation, length, downsample

        colors=np.random.rand(1,3).astype(np.float32)

        print colors

        self.list_index = gl.glGenLists(1)

        gl.glNewList( self.list_index,gl.GL_COMPILE)

        gl.glPushMatrix()

        gl.glDisable(gl.GL_LIGHTING)
        
        gl.glEnable(gl.GL_LINE_SMOOTH)

        gl.glEnable(gl.GL_BLEND)

        gl.glBlendFunc(gl.GL_SRC_ALPHA,gl.GL_ONE_MINUS_SRC_ALPHA)

        #gl.glBlendFunc(gl.GL_SRC_ALPHA_SATURATE,gl.GL_ONE_MINUS_SRC_ALPHA)
        
        #gl.glBlendFunc(gl.GL_SRC_ALPHA,gl.GL_ONE)

        gl.glHint(gl.GL_LINE_SMOOTH_HINT,gl.GL_DONT_CARE)

        #gl.glHint(gl.GL_LINE_SMOOTH_HINT,gl.GL_NICEST)

        gl.glLineWidth(self.line_width)

        #gl.glDepthMask(gl.GL_FALSE)


        gl.glEnableClientState(gl.GL_VERTEX_ARRAY)        

        for d in self.data:

            if length(d)> self.min_length:
            
                #mo=mean_orientation(d)

                if self.manycolors:
                
                    ds=downsample(d,6)

                    mo=ds[3]-ds[2]

                    mo=mo/np.sqrt(np.sum(mo**2))

                    mo.shape=(1,3)
            
                    color=boys2rgb(mo)

                    color4=np.array([color[0][0],color[0][1],color[0][2],self.opacity],np.float32)
                    gl.glColor4fv(color4)

                else:

                    color4=np.array([self.brain_color[0],self.brain_color[1],\
                                         self.brain_color[2],self.opacity],np.float32)

                    gl.glColor4fv(color4)
                    

                gl.glVertexPointerf(d)
                               
                gl.glDrawArrays(gl.GL_LINE_STRIP, 0, len(d))

        

        gl.glDisableClientState(gl.GL_VERTEX_ARRAY)


        #gl.glDisable(gl.GL_BLEND)
        
        gl.glEnable(gl.GL_LIGHTING)
        
        gl.glPopMatrix()

        gl.glEndList()