Example #1
0
def show_signals(data,bvals,gradients,sticks=None):
    
    s=data[1:]
    s0=data[0]    
    ls=np.log(s)-np.log(s0)
    ind=np.arange(1,data.shape[-1])
    ob=-1/bvals[1:]
    #lg=np.log(s[1:])-np.log(s0)
    d=ob*(np.log(s)-np.log(s0))    
    r=fvtk.ren()
    all=fvtk.crossing(s,ind,gradients,scale=1)
    #fvtk.add(r,fvtk.line(all,fvtk.coral))    
    #d=d-d.min()        
    #all3=fvtk.crossing(d,ind,gradients,scale=10**4)
    #fvtk.add(r,fvtk.line(all3,fvtk.red))    
    #d=d-d.min()        
    all2=fvtk.crossing(d,ind,gradients,scale=10**4)
    fvtk.add(r,fvtk.line(all2,fvtk.green))    
    #"""
    #d2=d*10**4
    #print d2.min(),d2.mean(),d2.max(),d2.std()    
    for a in all2:    
        fvtk.label(r,str(np.round(np.linalg.norm(a[0]),2)),pos=a[0],scale=(.2,.2,.2),color=(1,0,0))        
    if sticks!=None:
        for s in sticks:
            ln=np.zeros((2,3))
            ln[1]=s
            fvtk.add(r,fvtk.line(d.max()*10**4*ln,fvtk.blue)) 
    #data2=data.reshape(1,len(data))
    #pdi=ProjectiveDiffusivity(data2,bvals,gradients,dotpow=6,width=6,sincpow=2)
    #pd=pdi.spherical_diffusivity(data)
    #print pd
    #"""    
    fvtk.show(r)
Example #2
0
def show_sph_grid():
    r=fvtk.ren()
    print verts.shape, faces.shape
    sph=np.abs(np.dot(gradients[1],verts.T)**2)
    print sph.shape
    cols=fvtk.colors(sph,'jet')
    #fvtk.add(r,fvtk.point(verts,cols,point_radius=.1,theta=10,phi=10))
    
    for (i,v) in enumerate(gradients):    
        fvtk.label(r,str(i),pos=v,scale=(.02,.02,.02))
        if i in [62,76,58]:
            fvtk.label(r,str(i),pos=v,scale=(.05,.05,.05),color=(1,0,0))
    fvtk.show(r)
Example #3
0
def show_zero_level(r,bundle,dist):

    T=[downsample(b,12) for b in bundle]
    C=local_skeleton_clustering(T,dist)
    vs=[]
    colors=np.zeros((len(T),3))
    for c in C:
        vs.append(C[c]['hidden']/C[c]['N'])
        color=np.random.rand(3,)
        #fvtk.add(r,fvtk.line(vs,color,linewidth=4.5))
        for i in C[c]['indices']:
            colors[i]=color
            fvtk.label(r,text=str(i),pos=(bundle[i][-1]),scale=(.5,.5,.5),color=(color[0],color[1],color[2]))    
    fvtk.add(r,fvtk.line(T,colors,linewidth=2.))    
Example #4
0
def test_fvtk_functions():

    # Create a renderer
    r = fvtk.ren()

    # Create 2 lines with 2 different colors
    lines = [np.random.rand(10, 3), np.random.rand(20, 3)]
    colors = np.random.rand(2, 3)
    c = fvtk.line(lines, colors)
    fvtk.add(r, c)

    # create streamtubes of the same lines and shift them a bit
    c2 = fvtk.streamtube(lines, colors)
    c2.SetPosition(2, 0, 0)
    fvtk.add(r, c2)

    # Create a volume and return a volumetric actor using volumetric rendering
    vol = 100 * np.random.rand(100, 100, 100)
    vol = vol.astype('uint8')
    r = fvtk.ren()
    v = fvtk.volume(vol)
    fvtk.add(r, v)

    # Remove all objects
    fvtk.rm_all(r)

    # Put some text
    l = fvtk.label(r, text='Yes Men')
    fvtk.add(r, l)

    # Slice the volume
    fvtk.add(r, fvtk.slicer(vol, plane_i=[50]))

    # Change the position of the active camera
    fvtk.camera(r, pos=(0.6, 0, 0), verbose=False)
Example #5
0
def test_fvtk_functions():
    
    # Create a renderer
    r=fvtk.ren()    
    
    # Create 2 lines with 2 different colors
    lines=[np.random.rand(10,3),np.random.rand(20,3)]    
    colors=np.random.rand(2,3)
    c=fvtk.line(lines,colors)    
    fvtk.add(r,c)    

    # Create a volume and return a volumetric actor using volumetric rendering        
    vol=100*np.random.rand(100,100,100)
    vol=vol.astype('uint8')    
    r = fvtk.ren()
    v = fvtk.volume(vol)
    fvtk.add(r,v)
    
    # Remove all objects
    fvtk.rm_all(r)
    
    # Put some text    
    l=fvtk.label(r,text='Yes Men')
    fvtk.add(r,l)

    # Show everything
    #fvtk.show(r)

    
Example #6
0
def test_fvtk_functions():
    # This tests will fail if any of the given actors changed inputs or do
    # not exist

    # Create a renderer
    r = fvtk.ren()

    # Create 2 lines with 2 different colors
    lines = [np.random.rand(10, 3), np.random.rand(20, 3)]
    colors = np.random.rand(2, 3)
    c = fvtk.line(lines, colors)
    fvtk.add(r, c)

    # create streamtubes of the same lines and shift them a bit
    c2 = fvtk.streamtube(lines, colors)
    c2.SetPosition(2, 0, 0)
    fvtk.add(r, c2)

    # Create a volume and return a volumetric actor using volumetric rendering
    vol = 100 * np.random.rand(100, 100, 100)
    vol = vol.astype('uint8')
    r = fvtk.ren()
    v = fvtk.volume(vol)
    fvtk.add(r, v)

    # Remove all objects
    fvtk.rm_all(r)

    # Put some text
    l = fvtk.label(r, text='Yes Men')
    fvtk.add(r, l)

    # Slice the volume
    slicer = fvtk.slicer(vol)
    slicer.display(50, None, None)
    fvtk.add(r, slicer)

    # Change the position of the active camera
    fvtk.camera(r, pos=(0.6, 0, 0), verbose=False)

    fvtk.clear(r)

    # Peak directions
    p = fvtk.peaks(np.random.rand(3, 3, 3, 5, 3))
    fvtk.add(r, p)

    p2 = fvtk.peaks(np.random.rand(3, 3, 3, 5, 3),
                    np.random.rand(3, 3, 3, 5),
                    colors=(0, 1, 0))
    fvtk.add(r, p2)
Example #7
0
def test_fvtk_functions():
    # This tests will fail if any of the given actors changed inputs or do
    # not exist

    # Create a renderer
    r = fvtk.ren()

    # Create 2 lines with 2 different colors
    lines = [np.random.rand(10, 3), np.random.rand(20, 3)]
    colors = np.random.rand(2, 3)
    c = fvtk.line(lines, colors)
    fvtk.add(r, c)

    # create streamtubes of the same lines and shift them a bit
    c2 = fvtk.streamtube(lines, colors)
    c2.SetPosition(2, 0, 0)
    fvtk.add(r, c2)

    # Create a volume and return a volumetric actor using volumetric rendering
    vol = 100 * np.random.rand(100, 100, 100)
    vol = vol.astype('uint8')
    r = fvtk.ren()
    v = fvtk.volume(vol)
    fvtk.add(r, v)

    # Remove all objects
    fvtk.rm_all(r)

    # Put some text
    l = fvtk.label(r, text='Yes Men')
    fvtk.add(r, l)

    # Slice the volume
    slicer = fvtk.slicer(vol)
    slicer.display(50, None, None)
    fvtk.add(r, slicer)

    # Change the position of the active camera
    fvtk.camera(r, pos=(0.6, 0, 0), verbose=False)

    fvtk.clear(r)

    # Peak directions
    p = fvtk.peaks(np.random.rand(3, 3, 3, 5, 3))
    fvtk.add(r, p)

    p2 = fvtk.peaks(np.random.rand(3, 3, 3, 5, 3),
                    np.random.rand(3, 3, 3, 5),
                    colors=(0, 1, 0))
    fvtk.add(r, p2)
def main():
    parser = buildArgsParser()
    args = parser.parse_args()

    bvals, bvecs = read_bvals_bvecs(args.bvals, args.bvecs)

    ren = fvtk.ren()

    if args.points:

        points = fvtk.point(bvecs * bvals[..., None] * 0.01,
                            fvtk.colors.red,
                            point_radius=.5)
        fvtk.add(ren, points)

        if args.antipod:
            points = fvtk.point(-bvecs * bvals[..., None] * 0.01,
                                fvtk.colors.green,
                                point_radius=.5)
            fvtk.add(ren, points)
    else:
        for i in range(bvecs.shape[0]):
            label = fvtk.label(ren,
                               text=str(i),
                               pos=bvecs[i] * bvals[i] * 0.01,
                               color=fvtk.colors.red,
                               scale=(0.5, 0.5, 0.5))
            fvtk.add(ren, label)
            if args.antipod:
                label = fvtk.label(ren,
                                   text=str(i),
                                   pos=-bvecs[i] * bvals[i] * 0.01,
                                   color=fvtk.colors.green,
                                   scale=(0.5, 0.5, 0.5))
                fvtk.add(ren, label)

    fvtk.show(ren)
def show_gt_streamlines(streamlines, radii, cmap='orient', r=None):

    if cmap is None:
        np.random.seed(42)
        colors = np.random.rand(len(streamlines), 3)
    if cmap == 'orient':
        colors = line_colors(streamlines)

    if r is None:
        ren = fvtk.ren()
    else:
        ren = r

    for i in range(len(streamlines)):
        line_actor = fvtk.line(streamlines[i],
                               colors[i],
                               linewidth=(radii[i, 1] ** 2) / 2.)
        fvtk.add(ren, line_actor)
        label_actor = fvtk.label(ren, text=str(np.round(radii[i, 1], 2)),
                                 pos=(streamlines[i][0]),
                                 scale=(.8, .8, .8),
                                 color=(colors[i]))

        fvtk.add(ren, label_actor)

        label_actor_id = fvtk.label(ren, text='[' + str(i) + ']',
                                    pos=(streamlines[i][-1]),
                                    scale=(.8, .8, .8),
                                    color=(colors[i]))

        fvtk.add(ren, label_actor_id)

    if r is None:
        fvtk.show(ren)
    else:
        return ren
Example #10
0
def test_fvtk_functions():

    # Create a renderer
    r = fvtk.ren()

    # Create 2 lines with 2 different colors
    lines = [np.random.rand(10, 3), np.random.rand(20, 3)]
    colors = np.random.rand(2, 3)
    c = fvtk.line(lines, colors)
    fvtk.add(r, c)

    # Create a volume and return a volumetric actor using volumetric rendering
    vol = 100 * np.random.rand(100, 100, 100)
    vol = vol.astype('uint8')
    r = fvtk.ren()
    v = fvtk.volume(vol)
    fvtk.add(r, v)

    # Remove all objects
    fvtk.rm_all(r)

    # Put some text
    l = fvtk.label(r, text='Yes Men')
    fvtk.add(r, l)
Example #11
0
print('tripletons %d' % lens.count(3))

"""
Find and display the skeleton of most representative tracks in each cluster:
"""

skeleton=[]

fvtk.clear(r)

for c in C:
    
    bundle=[T[i] for i in C[c]['indices']]
    si,s=td.most_similar_track_mam(bundle,'avg')    
    skeleton.append(bundle[si])
    fvtk.label(r,text=str(len(bundle)),pos=(bundle[si][-1]),scale=(2,2,2))

fvtk.add(r,fvtk.line(skeleton,colors,opacity=1))
#fvtk.show(r)
fvtk.record(r,n_frames=1,out_path='fornix_most',size=(600,600))

"""
.. figure:: fornix_most1000000.png
   :align: center

   **Showing skeleton with the most representative tracks as the skeletal representation**.
   
   The numbers are depicting the number of tracks in each cluster. This is a very compact way to see the underlying
   structures an alternative would be to draw the representative tracks with different widths.
   
"""
Example #12
0
print 'With mam_threshold %f we find %d correspondence pairs' % (mam_threshold, np.size(track2track,0))

#fvtk.clear(r)

"""
Now plot the corresponding tracks in the same colours
"""

for row in track2track:

    color=np.random.rand(3)
    T=[T1[int(row[0])],T3s[int(row[1])]]
    fvtk.add(r,fvtk.line(T,color,linewidth=10))
    pos1=T1[int(row[0])][0]
    pos3=T3s[int(row[1])][0]
    fvtk.add(r,fvtk.label(r,str(int(row[0])),tuple(pos1),(5,5,5)))
    fvtk.add(r,fvtk.label(r,str(int(row[0])),tuple(pos3),(5,5,5)))

#fvtk.show(r,png_magnify=1)










print('doubletons %d' % lens.count(2))
print('tripletons %d' % lens.count(3))
"""
Find and display the skeleton of most representative tracks in each cluster:
"""

skeleton = []

fvtk.clear(r)

for c in C:

    bundle = [T[i] for i in C[c]['indices']]
    si, s = td.most_similar_track_mam(bundle, 'avg')
    skeleton.append(bundle[si])
    fvtk.label(r, text=str(len(bundle)), pos=(bundle[si][-1]), scale=(2, 2, 2))

fvtk.add(r, fvtk.line(skeleton, colors, opacity=1))
#fvtk.show(r)
fvtk.record(r, n_frames=1, out_path='fornix_most', size=(600, 600))
"""
.. figure:: fornix_most1000000.png
   :align: center

   **Showing skeleton with the most representative tracks as the skeletal representation**.
   
   The numbers are depicting the number of tracks in each cluster. This is a very compact way to see the underlying
   structures an alternative would be to draw the representative tracks with different widths.
   
"""
"""
Example #14
0
#fvtk.clear(r)

"""
Now plot the corresponding tracks in the same colours

.. figure:: find_corr1000000.png
   :align: center

   **Showing correspondence between these two modest tractographies**.

   The labels on the corresponding tracks are the indices of the first tractography on the left.

"""

for row in track2track:
    color=np.random.rand(3)
    T=[T1[int(row[0])],T3s[int(row[1])]]
    fvtk.add(r,fvtk.line(T,color,linewidth=5))
    pos1=T1[int(row[0])][0]
    pos3=T3s[int(row[1])][0]
    fvtk.add(r,fvtk.label(r,str(int(row[0])),tuple(pos1),(5,5,5)))
    fvtk.add(r,fvtk.label(r,str(int(row[0])),tuple(pos3),(5,5,5)))

# To see in an interactive window:
#fvtk.show(r,png_magnify=1,size=(600,600))

# To make the illustration
print('Saving illustration as find_corr1000000.png')
fvtk.record(r,n_frames=1,out_path='find_corr',size=(600,600))