AFQ.segmentation
#
Module Contents#
Classes#
Functions#
|
Clean a segmented fiber group based on the Mahalnobis distance of |
|
Clean a collection of streamlines based on an endpoint ROI. |
- class AFQ.segmentation.Segmentation(nb_points=False, nb_streamlines=False, seg_algo='AFQ', clip_edges=False, parallel_segmentation={'engine': 'serial'}, progressive=True, greater_than=50, rm_small_clusters=50, model_clust_thr=1.25, reduction_thr=25, refine=False, pruning_thr=12, b0_threshold=50, prob_threshold=0, roi_dist_tie_break=False, dist_to_waypoint=None, rng=None, return_idx=False, presegment_bundle_dict=None, presegment_kwargs={}, filter_by_endpoints=True, dist_to_atlas=4, save_intermediates=None, cleaning_params={})[source]#
-
- property crosses[source]#
Classify the streamlines by whether they cross the midline. Creates a crosses attribute which is an array of booleans. Each boolean corresponds to a streamline, and is whether or not that streamline crosses the midline.
- segment(bundle_dict, tg, mapping, img, reg_prealign=None, reg_template=None, reset_tg_space=False)[source]#
Segment streamlines into bundles based on either waypoint ROIs [Yeatman2012] or RecoBundles [Garyfallidis2017]. Parameters ———- bundle_dict: dict or AFQ.api.BundleDict
- Meta-data for the segmentation. The format is something like::
- {‘bundle_name’: {
‘include’:[img1, img2], ‘prob_map’: img3, ‘cross_midline’: False, ‘start’: img4, ‘end’: img5}}
- tgStatefulTractogram
Bundles to segment
- mappingDiffeomorphicMap, or equivalent interface
A mapping between DWI space and a template.
- imgNifti1Image
Image to use as reference.
- reg_prealignarray, optional.
The linear transformation to be applied to align input images to the reference space before warping under the deformation field. Default: None.
- reg_templatestr or nib.Nifti1Image, optional.
Template to use for registration. Default: MNI T2.
- reset_tg_spacebool, optional
Whether to reset the space of the input tractogram after segmentation is complete. Default: False.
- Returns
- dictWhere keys are bundle names, values are tractograms of
these bundles.
References
- Yeatman2012
Yeatman, Jason D., Robert F. Dougherty, Nathaniel J.
Myall, Brian A. Wandell, and Heidi M. Feldman. 2012. “Tract Profiles of White Matter Properties: Automating Fiber-Tract Quantification” PloS One 7 (11): e49790. .. [R03e71c6d7dc6-Garyfallidis17] Garyfallidis et al. Recognition of white matter bundles using local and global streamline-based registration and clustering, Neuroimage, 2017.
- _return_empty(bundle)[source]#
Helper function for segment_afq, to return an empty dict under some conditions.
- _add_bundle_to_fiber_group(b_name, sl, idx, to_flip)[source]#
Helper function for segment_afq, to add a bundle to a fiber group.
- segment_afq(tg=None)[source]#
Assign streamlines to bundles using the waypoint ROI approach Parameters ———- tg : StatefulTractogram class instance
- move_streamlines(tg, to='template')[source]#
Streamline-based registration of a whole-brain tractogram to the MNI whole-brain atlas.
- tostr
“template” or “subject”
- segment_reco(tg=None)[source]#
Segment streamlines using the RecoBundles algorithm [Garyfallidis2017] Parameters ———- tg : StatefulTractogram class instance
A whole-brain tractogram to be segmented.
Returns#
- fiber_groupsdict
Keys are names of the bundles, values are Streamline objects. The streamlines in each object have all been oriented to have the same orientation (using dts.orient_by_streamline).
- AFQ.segmentation.clean_bundle(tg, n_points=100, clean_rounds=5, distance_threshold=3, length_threshold=4, min_sl=20, stat='mean', return_idx=False)[source]#
Clean a segmented fiber group based on the Mahalnobis distance of each streamline
- Parameters
- tgStatefulTractogram class instance or ArraySequence
A whole-brain tractogram to be segmented.
- n_pointsint, optional
Number of points to resample streamlines to. Default: 100
- clean_roundsint, optional.
Number of rounds of cleaning based on the Mahalanobis distance from the mean of extracted bundles. Default: 5
- distance_thresholdfloat, optional.
Threshold of cleaning based on the Mahalanobis distance (the units are standard deviations). Default: 3.
- length_threshold: float, optional
Threshold for cleaning based on length (in standard deviations). Length of any streamline should not be more than this number of stdevs from the mean length.
- min_slint, optional.
Number of streamlines in a bundle under which we will not bother with cleaning outliers. Default: 20.
- statcallable or str, optional.
The statistic of each node relative to which the Mahalanobis is calculated. Default: np.mean (but can also use median, etc.)
- return_idxbool
Whether to return indices in the original streamlines. Default: False.
- Returns
- ——-
- A StatefulTractogram class instance containing only the streamlines
- that have a Mahalanobis distance smaller than `clean_threshold` from
- the mean of each one of the nodes.
- AFQ.segmentation.clean_by_endpoints(streamlines, target, target_idx, tol=0, flip_sls=None, accepted_idxs=None)[source]#
Clean a collection of streamlines based on an endpoint ROI. Filters down to only include items that have their start or end points close to the targets. Parameters ———- streamlines : sequence of N by 3 arrays
Where N is number of nodes in the array, the collection of streamlines to filter down to.
- target: Nifti1Image
Nifti1Image containing a boolean representation of the ROI.
- target_idx: int.
Index within each streamline to check if within the target region. Typically 0 for startpoint ROIs or -1 for endpoint ROIs. If using flip_sls, this becomes (len(sl) - this_idx - 1) % len(sl)
- tolint, optional
A distance tolerance (in units that the coordinates of the streamlines are represented in). Default: 0, which means that the endpoint is exactly in the coordinate of the target ROI.
- flip_sls1d array, optional
Length is len(streamlines), whether to flip the streamline.
- accepted_idxs1d array, optional
Boolean array, where entries correspond to eachs streamline, and streamlines that pass cleaning will be set to 1.
Yields#
boolean array of streamlines that survive cleaning.