Beispiel #1
0
def half_split_comparisons():

    res = {}

    for id in range(len(tractography_sizes)):
        res[id] = {}
        first, second = split_halves(id)
        res[id]["lengths"] = [len(first), len(second)]
        print len(first), len(second)
        first_qb = QuickBundles(first, qb_threshold, downsampling)
        n_clus = first_qb.total_clusters
        res[id]["nclusters"] = n_clus
        print "QB for first half has", n_clus, "clusters"
        second_down = [downsample(s, downsampling) for s in second]
        matched_random = get_random_streamlines(first_qb.downsampled_tracks(), n_clus)
        neighbours_first = count_close_tracks(first_qb.virtuals(), first_qb.downsampled_tracks(), adjacency_threshold)
        neighbours_second = count_close_tracks(first_qb.virtuals(), second_down, adjacency_threshold)
        neighbours_random = count_close_tracks(matched_random, second_down, adjacency_threshold)

        maxclose = np.int(np.max(np.hstack((neighbours_first, neighbours_second, neighbours_random))))

        # The numbers of tracks 0, 1, 2, ... 'close' subset tracks
        counts = np.array(
            [
                (
                    np.int(n),
                    len(find(neighbours_first == n)),
                    len(find(neighbours_second == n)),
                    len(find(neighbours_random == n)),
                )
                for n in range(maxclose + 1)
            ],
            dtype="f",
        )
        totals = np.sum(counts[:, 1:], axis=0)
        res[id]["totals"] = totals
        res[id]["counts"] = counts
        # print totals
        # print counts
        missed_fractions = counts[0, 1:] / totals
        res[id]["missed_fractions"] = missed_fractions
        means = np.sum(counts[:, 1:] * counts[:, [0, 0, 0]], axis=0) / totals
        # print means
        res[id]["means"] = means
        # print res
    return res
Beispiel #2
0
def load_tracks(method="pmt"):
    from nibabel import trackvis as tv

    dname = "/home/eg309/Data/orbital_phantoms/dwi_dir/subject1/"

    if method == "pmt":
        fname = "/home/eg309/Data/orbital_phantoms/dwi_dir/workflow/tractography/_subject_id_subject1/cam2trk_pico_twoten/data_fit_pdfs_tracked.trk"
        streams, hdr = tv.read(fname, points_space="voxel")
        tracks = [s[0] for s in streams]
    if method == "dti":
        fname = dname + "dti_tracks.dpy"
    if method == "dsi":
        fname = dname + "dsi_tracks.dpy"
    if method == "gqs":
        fname = dname + "gqi_tracks.dpy"
    if method == "eit":
        fname = dname + "eit_tracks.dpy"
    if method in ["dti", "dsi", "gqs", "eit"]:
        dpr_linear = Dpy(fname, "r")
        tracks = dpr_linear.read_tracks()
        dpr_linear.close()

    if method != "pmt":
        tracks = [t - np.array([96 / 2.0, 96 / 2.0, 55 / 2.0]) for t in tracks if track_range(t, 100 / 2.5, 150 / 2.5)]
    tracks = [t for t in tracks if track_range(t, 100 / 2.5, 150 / 2.5)]

    print "final no of tracks ", len(tracks)
    qb = QuickBundles(tracks, 25.0 / 2.5, 18)
    # from dipy.viz import fvtk
    # r=fvtk.ren()
    # fvtk.add(r,fvtk.line(qb.virtuals(),fvtk.red))
    # fvtk.show(r)
    # show_tracks(tracks)#qb.exemplars()[0])
    # qb.remove_small_clusters(40)
    del tracks
    # load
    tl = TrackLabeler(qb, qb.downsampled_tracks(), vol_shape=None, tracks_line_width=3.0, tracks_alpha=1)

    # return tracks
    w = World()
    w.add(tl)
    # create window
    wi = Window(caption="Fos", bgcolor=(1.0, 1.0, 1.0, 1.0), width=1600, height=900)
    wi.attach(w)
    # create window manager
    wm = WindowManager()
    wm.add(wi)
    wm.run()
Beispiel #3
0
def load_PX_tracks():

    roi = "LH_premotor"

    dn = "/home/hadron/from_John_mon12thmarch"
    dname = "/extra_probtrackX_analyses/_subject_id_subj05_101_32/particle2trackvis_" + roi + "_native/"
    fname = dn + dname + "tract_samples.trk"
    from nibabel import trackvis as tv

    points_space = [None, "voxel", "rasmm"]
    streamlines, hdr = tv.read(fname, as_generator=True, points_space="voxel")
    tracks = [s[0] for s in streamlines]
    del streamlines
    # return tracks

    qb = QuickBundles(tracks, 25.0 / 2.5, 18)
    # tl=Line(qb.exemplars()[0],line_width=1)
    del tracks
    qb.remove_small_clusters(20)

    tl = TrackLabeler(qb, qb.downsampled_tracks(), vol_shape=None, tracks_line_width=3.0, tracks_alpha=1)

    # put the seeds together
    # seeds=np.vstack((seeds,seeds2))
    # shif the seeds
    # seeds=np.dot(mat[:3,:3],seeds.T).T + mat[:3,3]
    # seeds=seeds-shift
    # seeds2=np.dot(mat[:3,:3],seeds2.T).T + mat[:3,3]
    # seeds2=seeds2-shift
    # msk = Point(seeds,colors=(1,0,0,1.),pointsize=2.)
    # msk2 = Point(seeds2,colors=(1,0,.ppppp2,1.),pointsize=2.)
    w = World()
    w.add(tl)
    # w.add(msk)
    # w.add(msk2)
    # w.add(sl)
    # create window
    wi = Window(caption="Fos", bgcolor=(0.3, 0.3, 0.6, 1.0), width=1600, height=900)
    wi.attach(w)
    # create window manager
    wm = WindowManager()
    wm.add(wi)
    wm.run()
    qb=QuickBundles(T, 20., 12)
    #save_pickle(fpkl,qb)
    #qb=load_pickle(fpkl)
    Init()

    title = '[F]oS Streamline Interaction and Segmentation'
    w = Window(caption = title, 
                width = 1200, 
                height = 800, 
                bgcolor = (.5, .5, 0.9), right_panel=True)

    scene = Scene(scenename = 'Main Scene', activate_aabb = False)
    
    #create the interaction system for tracks 
    tl = StreamlineLabeler('Bundle Picker', 
                        qb,qb.downsampled_tracks(), 
                        vol_shape=data.shape[:3], 
                        tracks_alpha=1,
                        affine=affine)

    guil = Guillotine('Volume Slicer', data, affine)

    scene.add_actor(guil)
    scene.add_actor(tl)

    w.add_scene(scene)
    w.refocus_camera()

    Run()
Beispiel #5
0
    
    #center
    shift=(np.array(data.shape)-1)/2.    
    T=[t-shift for t in T]
    
    #load initial QuickBundles with threshold 30mm
    #fpkl = 'data/subj_05/101_32/DTI/qb_gqi_1M_linear_30.pkl'
    qb=QuickBundles(T,25.,30)    
    print len(qb.clustering)
    #qb=load_pickle(fpkl)
    qb.remove_small_clusters(1000)
    print len(qb.clustering)

        
    #create the interaction system for tracks 
    tl = TrackLabeler(qb,qb.downsampled_tracks(),vol_shape=data.shape,tracks_line_width=3.,tracks_alpha=1.)   
    #add a interactive slicing/masking tool
    sl = Slicer(affine,data)    
    #add one way communication between tl and sl
    tl.slicer=sl
    #OpenGL coordinate system axes    
    ax = Axes(100)
    x,y,z=data.shape
    #add the actors to the world    
    w=World()
    w.add(tl)
    #w.add(sl)
    #w.add(ax)
    #create a window
    #wi = Window(caption="Interactive bundle selection using fos and QB",\
    #            bgcolor=(0.3,0.3,0.6,1),width=1600,height=1000)    
Beispiel #6
0
    def set_state(self):        
        glEnable(GL_DEPTH_TEST)
        glEnable(GL_BLEND)
        glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)
        glEnable(GL_LINE_SMOOTH)        
        glHint(GL_LINE_SMOOTH_HINT, GL_NICEST)
        glLineWidth(self.line_width)
        
    def unset_state(self):
        glDisable(GL_DEPTH_TEST)
        glDisable(GL_BLEND)
        glDisable(GL_LINE_SMOOTH)
        glLineWidth(self.line_width)

    def delete(self):
        for i in range(len(self.vertex_list)):
            self.vertex_list[i].delete()

tl = TrackLabeler(qb,qb.downsampled_tracks())

w=World()
w.add(tl)

wi = Window(caption="Tractography Labeler by Free On Shades (http://fos.me)")
wi.attach(w)

wm = WindowManager()
wm.add(wi)
wm.run()

Beispiel #7
0
    # load initial QuickBundles with threshold 30mm
    # fpkl = dname+'data/subj_05/101_32/DTI/qb_gqi_1M_linear_30.pkl'
    # qb=QuickBundles(T, 10., 18)
    # save_pickle(fpkl,qb)
    # qb=load_pickle(fpkl)

    qb = QuickBundles(T, 20.0, 12)
    # save_pickle(fpkl,qb)
    # qb=load_pickle(fpkl)
    Init()

    title = "[F]oS Streamline Interaction and Segmentation"
    w = Window(caption=title, width=1200, height=800, bgcolor=(0.5, 0.5, 0.9), right_panel=True)

    scene = Scene(scenename="Main Scene", activate_aabb=False)

    # create the interaction system for tracks
    tl = StreamlineLabeler(
        "Bundle Picker", qb, qb.downsampled_tracks(), vol_shape=data.shape[:3], tracks_alpha=1, affine=affine
    )

    guil = Guillotine("Volume Slicer", data, affine)

    scene.add_actor(guil)
    scene.add_actor(tl)

    w.add_scene(scene)
    w.refocus_camera()

    Run()
Beispiel #8
0
    T = [track for track in T if is_close(track, lT, 5)]

    shift = (np.array(ref_shape) - 1) / 2.0
    T = [t - shift for t in T]
    print len(T)

    # save tracks
    dpr_linear = Dpy(ftracks, "w")
    dpr_linear.write_tracks(T)
    dpr_linear.close()
    # cluster tracks
    qb = QuickBundles(T, 25.0, 25)
    # qb.remove_small_clusters(40)
    del T
    # load
    tl = TrackLabeler(qb, qb.downsampled_tracks(), vol_shape=ref_shape, tracks_line_width=3.0, tracks_alpha=1)
    fT1 = "data/subj_" + subject + "/MPRAGE_32/T1_flirt_out.nii.gz"
    # fT1_ref = '/usr/share/fsl/data/standard/MNI152_T1_1mm_brain.nii.gz'
    img = nib.load(fT1)
    # img = nib.load(fT1)
    sl = Slicer(img.get_affine(), img.get_data())
    tl.slicer = sl

    luigi = Line([t - shift for t in lT], line_width=2)

    # put the seeds together
    seeds = np.vstack((seeds, seeds2))
    # shif the seeds
    seeds = np.dot(mat[:3, :3], seeds.T).T + mat[:3, 3]
    seeds = seeds - shift
    # seeds2=np.dot(mat[:3,:3],seeds2.T).T + mat[:3,3]