Beispiel #1
0
def subsample_streamlines(streamlines,
                          clustering_threshold=6.,
                          removal_distance=2.):
    """ Subsample a group of streamlines (should be used on streamlines from a single bundle or similar structure).
    Streamlines are first clustered using `clustering_threshold`, then for each cluster, similar streamlines (closer than `removal_distance`) are removed.

    Parameters
    ----------
    streamlines : `ArraySequence` object
        Streamlines to subsample
    clustering_threshold : float
        distance threshold for clustering (in the space of the tracks)
    removal_distance : float
        distance threshold for removal (in the space of the tracks)
    Returns
    -------
    `ArraySequence` object
        Downsampled streamlines
    """

    output_streamlines = []

    qb = QuickBundles(streamlines, dist_thr=clustering_threshold, pts=20)
    for i in range(len(qb.centroids)):
        temp_streamlines = qb.label2tracks(streamlines, i)
        output_streamlines.extend(
            remove_similar_streamlines(temp_streamlines,
                                       removal_distance=removal_distance))

    return output_streamlines