AFQ.recognition.other_bundles#

Attributes#

Functions#

clean_by_overlap(this_bundle_sls, other_bundle_sls, ...)

Cleans a set of streamlines by only keeping (or removing) those with

clean_relative_to_other_core(core, this_fgarray, ...)

Removes streamlines from a set that lie on the opposite side of a specified

Module Contents#

AFQ.recognition.other_bundles.logger[source]#
AFQ.recognition.other_bundles.clean_by_overlap(this_bundle_sls, other_bundle_sls, overlap, img, remove=False, project=None, other_bundle_min_density=0.05)[source]#

Cleans a set of streamlines by only keeping (or removing) those with significant overlap with another set of streamlines.

Parameters:
this_bundle_slsarray-like

A list or array of streamlines to be cleaned. Assumed to be in RASMM space.

other_bundle_slsarray-like

A reference list or array of streamlines to determine overlapping regions.

overlapint

The minimum number of nodes allowed to overlap between this_bundle_sls and other_bundle_sls. Streamlines with overlaps beyond this threshold are removed.

imgnibabel.Nifti1Image

A reference 3D image that defines the spatial dimensions for the density map.

removebool, optional

If True, streamlines that overlap in less than overlap nodes are removed. If False, streamlines that overlap in more than overlap nodes are removed. Default: False.

project{‘A/P’, ‘I/S’, ‘L/R’, None}, optional

If specified, the overlap calculation is projected along the given axis before cleaning. For example, ‘A/P’ projects the streamlines along the anterior-posterior axis. Default: None.

other_bundle_min_densityfloat, optional

A threshold to binarize the density map of other_bundle_sls. Voxels with density values above this threshold (as a fraction of the maximum density) are considered occupied. Default: 0.05.

Returns:
cleaned_idxndarray of bool

An array of boolean values indicating which streamlines from this_bundle_sls pass the overlap threshold (True for streamlines to keep, False for streamlines to discard).

Notes

This function computes a density map from other_bundle_sls to represent the spatial occupancy of the streamlines. It then calculates the probability of each streamline in this_bundle_sls overlapping with this map. Streamlines that overlap in less than overlap nodes are flagged for removal (or more, if remove is True).

Examples

>>> clean_idx = clean_by_overlap(bundle1, bundle2, 5, img, True)
>>> cleaned_bundle = [s for i, s in enumerate(bundle1) if clean_idx[i]]
AFQ.recognition.other_bundles.clean_relative_to_other_core(core, this_fgarray, other_fgarray, consideration)[source]#

Removes streamlines from a set that lie on the opposite side of a specified core axis compared to another set of streamlines.

Parameters:
core{‘anterior’, ‘posterior’, ‘superior’, ‘inferior’, ‘right’, ‘left’}

The anatomical axis used to define the core direction. This determines the side of the core from which streamlines in this_fgarray are retained.

this_fgarrayndarray

An array of streamlines to be cleaned. Assumed to be in RASMM space.

other_fgarrayndarray

An array of reference streamlines to define the core. Assumed to be in RASMM space.

considerationfloat or string, optional

If float, the distance threshold (in voxels) for considering a streamline’s position relative to the core. All points on the streamline within distance from the core are considered when determining if the streamline lies on the correct side. If no points are within consideration distance, the closest point on the streamline to the core is considered. If string, must be one of ‘entire’ or ‘closest’. If ‘entire’, the entire streamline must lie on the correct side of the core to be retained. If ‘closest’, only the closest point on the streamline to the core is considered.

Returns:
cleaned_idx_corendarray of bool

An array of boolean values indicating which streamlines in this_fgarray lie on the correct side of the core (True for streamlines to keep, False for streamlines to discard).

Notes

This function first calculates the median streamline of other_fgarray, which acts as the core line. It then determines whether each streamline in this_fgarray is on the specified side of this core, based on the specified anatomical axis (core). Streamlines on the opposite side are flagged for removal.

Examples

>>> cleaned_core_idx = clean_relative_to_other_core('anterior',
...                                                 streamlines1,
...                                                 streamlines2,
...                                                 np.eye(4))
>>> cleaned_streamlines = [s for i, s in enumerate(streamlines1)
...                        if cleaned_core_idx[i]]