Beispiel #1
0
def test_qbundles():
    streams, hdr = nib.trackvis.read(get_fnames('fornix'))
    T = [s[0] for s in streams]
    qb = QuickBundles(T, 10., 12)
    qb.virtuals()
    qb.exemplars()
    assert_equal(4, qb.total_clusters)
Beispiel #2
0
def test_qbundles():
    streams, hdr = nib.trackvis.read(get_data('fornix'))
    T = [s[0] for s in streams]
    qb = QuickBundles(T, 10., 12)
    qb.virtuals()
    qb.exemplars()
    assert_equal(4, qb.total_clusters)
Beispiel #3
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 #4
0
def test_qbundles():
    streams, hdr = nib.trackvis.read(get_data('fornix'))
    T = [s[0] for s in streams]
    Trk = np.array(T, dtype=np.object)
    qb = QuickBundles(T, 10., 12)
    Tqb = qb.virtuals()
    # Tqbe,Tqbei=qb.exemplars(T)
    Tqbe, Tqbei = qb.exemplars()
    assert_equal(4, qb.total_clusters)
Beispiel #5
0
from pyglet.window import key
from fos.core.utils import screen_to_model
import fos.core.collision as cll
from pyglet.gl import *
#dipy modules
from dipy.segment.quickbundles import QuickBundles


streams,hdr = nib.trackvis.read(get_track_filename())
#center the data
T=[s[0] for s in streams]
mean_T=np.mean(np.concatenate(T),axis=0)
T=[t-mean_T for t in T]

qb=QuickBundles(T,10.,12)
Tqb=qb.virtuals()
Tqbe,Tqbei=qb.exemplars()

class TrackLabeler(Actor):   
    
    def __init__(self,qb,tracks,colors=None,line_width=2.,affine=None):
        
        self.virtuals=qb.virtuals()
        self.tracks=tracks           
        if affine is None:
            self.affine = np.eye(4, dtype = np.float32)
        else:
            self.affine = affine            
        #aabb - bounding box things
        ccurves=np.concatenate(tracks)
        self.min=np.min(ccurves,axis=0)