AFQ.recognition.cleaning#
Attributes#
Functions#
|
Retain streamlines whose core is oriented along the primary axis |
|
Clean a segmented fiber group based on the Mahalanobis distance of |
|
Clean a segmented fiber group based on the Mahalnobis distance of |
|
Use Isolation Forest (IF) to clean streamlines. |
Module Contents#
- AFQ.recognition.cleaning.clean_by_orientation(streamlines, primary_axis, core_only=0.6)[source]#
Retain streamlines whose core is oriented along the primary axis and have endpoints that are also oriented along the primary axis and have a majority of their steps along the primary axis.
- Parameters:
- streamlinessequence of N by 3 arrays
Where N is number of nodes in the array, the collection of streamlines to filter down to.
- core_onlyfloat, optional
If non-zero, only the core of the bundle is used for cleaning. The core is defined as the middle 60% of each streamline, thus our default is 0.6. This means streamlines are allowed to deviate in the starting and ending 20% of the bundle. This is useful for allowing more diverse endpoints. Default: 0.6
- Returns:
- cleaned_idx, indices of streamlines that passed cleaning
- AFQ.recognition.cleaning.clean_by_orientation_mahalanobis(streamlines, n_points=100, core_only=0, min_sl=20, distance_threshold=3, length_threshold=4, clean_rounds=5, remove_lengths='long')[source]#
Clean a segmented fiber group based on the Mahalanobis distance of each streamline’s local orientation (the step between consecutive nodes), rather than its position.
- Parameters:
- streamlinesArraySequence or sequence of N by 3 arrays
The streamlines of the bundle to be cleaned.
- n_pointsint, optional
Number of points to resample streamlines to. Default: 100
- core_onlyfloat, optional
If non-zero, only the core of the bundle is used for cleaning. For example, 0.6 uses the middle 60% of each streamline, allowing streamlines to deviate in the starting and ending 20%. Default: 0
- min_slint, optional.
Minimum number of streamlines to keep. If a round of cleaning would leave fewer than this, the min_sl streamlines with the smallest total Mahalanobis distance are kept instead. Default: 20.
- 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), where length is the number of points in each streamline. If 0, no cleaning by length is done. Default: 4.
- clean_roundsint, optional.
Number of rounds of cleaning based on the Mahalanobis distance from the mean orientation of each node. Default: 5
- remove_lengthsstr
Specifies which streamlines to remove based on their length. Options are “long” (remove long streamlines), “short” (remove short streamlines), or “both” (remove both long and short streamlines). Default: “long”
- Returns:
- idxndarray
Indices of the streamlines that passed cleaning.
- AFQ.recognition.cleaning.clean_bundle(tg, n_points=100, clean_rounds=5, distance_threshold=4, length_threshold=4, min_sl=20, stat=np.mean, core_only=0.6, return_idx=False, remove_lengths='long')[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: 4.
- 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.)
- core_onlyfloat, optional
If non-zero, only the core of the bundle is used for cleaning. The core is defined as the middle 60% of each streamline, thus our default is 0.6. This means streamlines are allowed to deviate in the starting and ending 20% of the bundle. This is useful for allowing more diverse endpoints. Default: 0.6
- return_idxbool
Whether to return indices in the original streamlines. Default: False.
- remove_lengthsstr
Specifies which streamlines to remove based on their length. Options are “long” (remove long streamlines), “short” (remove short streamlines), or “both” (remove both long and short streamlines). Default: “long”
- 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.recognition.cleaning.clean_by_isolation_forest(tg, n_points=100, distance_threshold=3, length_threshold=4, n_rounds=5, min_sl=20, n_jobs=None, random_state=None)[source]#
Use Isolation Forest (IF) to clean streamlines. Nodes are passed to IF, and nodes are assigned anamoly scores. These are re-mapped back on to the streamlines. Streamlines with maximum outlier scores too many s.d. away from the mean outlier score are removed. This is done in several rounds. This is better for cleaning bundles that are not tube-like.
- 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
- distance_thresholdint, optional
Streamlines with average node anamoly score below this many s.d. of average node anaomly score are removed. 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. Default: 4.
- n_roundsint, optional.
Number of rounds of cleaning based on Isolation Forest. Default: 5
- min_slint, optional.
Number of streamlines in a bundle under which we will not bother with cleaning outliers. Default: 20.
- n_jobsint, optional
Number of parallel jobs to use for LOF. Default: None (single-threaded).
- random_stateint, optional
Random state for IsolationForest. Default: None
- Returns:
- indices of streamlines that passed cleaning