def bundle_thre_seg(self, streamlines=None, cluster_thre=10, dist_thre=10.0, pts=12): """ QuickBundles-based segmentation Parameters ---------- streamlines: streamline data cluster_thre: remove small cluster dist_thre: clustering threshold (distance mm) pts: each streamlines are divided into sections Return ------ sort_index: sort of clusters according to y mean of cluster's centroids data_cluster: cluster data corresponding to sort_index """ if streamlines is None: streamlines = self._fasciculus.get_data() else: streamlines = streamlines bundles = QuickBundles(streamlines, dist_thre, pts) bundles.remove_small_clusters(cluster_thre) clusters = bundles.clusters() data_clusters = [] for key in clusters.keys(): data_clusters.append(streamlines[clusters[key]['indices']]) centroids = bundles.centroids clusters_y_mean = [clu[:, 1].mean() for clu in centroids] sort_index = np.argsort(clusters_y_mean) return sort_index, data_clusters
def bundle_centroids(self, streamlines=None, cluster_thre=10, dist_thre=10.0, pts=12): """ QuickBundles-based segmentation Parameters ---------- streamlines: streamline data cluster_thre: remove small cluster dist_thre: clustering threshold (distance mm) pts: each streamlines are divided into sections Return ------ centroids: cluster's centroids """ if streamlines is None: streamlines = self._fasciculus.get_data() else: streamlines = streamlines bundles = QuickBundles(streamlines, dist_thre, pts) bundles.remove_small_clusters(cluster_thre) centroids = bundles.centroids return nibas.ArraySequence(centroids)
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()
if reduce_length: T=[t for t in T if track_range(100,200)] #iT=np.random.randint(0,len(T),5000) #T=[T[i] for i in iT] #stop #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)