def rm_far_ends(ref, tracks, dist=25): ''' rm tracks with far endpoints 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 endpoint distance threshold Returns ------- tracksr : sequence reduced tracks indices : sequence indices of tracks ''' indices = [ i for (i, t) in enumerate(tracks) if tm.max_end_distances(t, ref) <= dist ] tracksr = [tracks[i] for i in indices] return tracksr, indices
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
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
def rm_far_ends(ref,tracks,dist=25): ''' rm tracks with far endpoints 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 endpoint distance threshold Returns ------- tracksr : sequence reduced tracks indices : sequence indices of tracks ''' indices=[i for (i,t) in enumerate(tracks) if tm.max_end_distances(t,ref) <= dist] tracksr=[tracks[i] for i in indices] return tracksr,indices