scilpy.segment package

scilpy.segment.models module

scilpy.segment.models.remove_similar_streamlines(streamlines, threshold=5)[source]

Remove similar streamlines, shuffling streamlines will impact the results. Only provide a small set of streamlines (below 2000 if possible).

Parameters:
  • streamlines (list of numpy.ndarray) – Input streamlines to remove duplicates from.

  • threshold (float) – Distance threshold to consider two streamlines similar, in mm.

Returns:

streamlines

Return type:

list of numpy.ndarray

scilpy.segment.recobundlesx module

class scilpy.segment.recobundlesx.RecobundlesX(memmap_filenames, clusters_indices, wb_centroids, rng=None)[source]

Bases: object

This class is a ‘remastered’ version of the Dipy Recobundles class. Made to be used in sync with the voting_scheme. Adapted in many way for HPC processing and increase control over parameters and logging. However, in essence they do the same thing. https://github.com/nipy/dipy/blob/master/dipy/segment/bundles.py

References

[Garyfallidis17]

Garyfallidis et al. Recognition of white matter bundles using local and global streamline-based registration and clustering, Neuroimage, 2017.

cleanup()[source]
get_final_pruned_indices()[source]

Public getter for the final indices recognize by the algorithm.

prune_far_from_model(pruning_thr=10)[source]

Wrapper function to prune clusters from the tractogram too far from the model.

Parameters:

pruning_thr (float, distance in) – thresholds = [32, 16, 24, neighbors_cluster_thr]

recognize(model_bundle, model_clust_thr=8, pruning_thr=8, slr_transform_type='similarity', identifier=None)[source]
Parameters:
  • model_bundle (list or ArraySequence) – Model bundle as loaded by the nibabel API.

  • model_clust_thr (obj) – Distance threshold (mm) for model clustering (QBx)

  • pruning_thr (int) – Distance threshold (mm) for the final pruning.

  • slr_transform_type (str) – Define the transformation for the local SLR. [translation, rigid, similarity, scaling]

  • identifier (str) – Identify the current bundle being recognized for the logging.

Returns:

clusters – Streamlines that were recognized by Recobundles and these parameters.

Return type:

list

scilpy.segment.streamlines module

scilpy.segment.streamlines.filter_cuboid(sft, cuboid_radius, cuboid_center, filter_type, is_exclude)[source]
Parameters:
  • sft (StatefulTractogram) – StatefulTractogram containing the streamlines to segment.

  • cuboid_radius (numpy.ndarray (3)) – Size in mm, x/y/z of the cuboid.

  • cuboid_center (numpy.ndarray (3)) – Center x/y/z of the cuboid.

  • filter_type (str) – One of the 3 following choices, ‘any’, ‘all’, ‘either_end’, ‘both_ends’.

  • is_exclude (bool) – Value to indicate if the ROI is an AND (false) or a NOT (true).

  • is_in_vox (bool) – Value to indicate if the ROI is in voxel space.

Returns:

ids – Filtered sft. Ids of the streamlines passing through the mask.

Return type:

tuple

scilpy.segment.streamlines.filter_ellipsoid(sft, ellipsoid_radius, ellipsoid_center, filter_type, is_exclude, is_in_vox=False)[source]
Parameters:
  • sft (StatefulTractogram) – StatefulTractogram containing the streamlines to segment.

  • ellipsoid_radius (numpy.ndarray (3)) – Size in mm, x/y/z of the ellipsoid.

  • ellipsoid_center (numpy.ndarray (3)) – Center x/y/z of the ellipsoid.

  • filter_type (str) – One of the 3 following choices, ‘any’, ‘all’, ‘either_end’, ‘both_ends’.

  • is_exclude (bool) – Value to indicate if the ROI is an AND (false) or a NOT (true).

  • is_in_vox (bool) – Value to indicate if the ROI is in voxel space.

Returns:

ids – Filtered sft. Ids of the streamlines passing through the mask.

Return type:

tuple

scilpy.segment.streamlines.filter_grid_roi(sft, mask, filter_type, is_exclude, filter_distance=0)[source]
Parameters:
  • sft (StatefulTractogram) – StatefulTractogram containing the streamlines to segment.

  • mask (numpy.ndarray) – Binary mask in which the streamlines should pass.

  • filter_type (str) – One of the 4 following choices, ‘any’, ‘all’, ‘either_end’, ‘both_ends’.

  • is_exclude (bool) – Value to indicate if the ROI is an AND (false) or a NOT (true).

Returns:

  • new_sft (StatefulTractogram) – Filtered sft.

  • ids (list) – Ids of the streamlines passing through the mask.

scilpy.segment.streamlines.filter_grid_roi_both(sft, mask_1, mask_2)[source]

Filters streamlines with one end in a mask and the other in another mask.

Parameters:
  • sft (StatefulTractogram) – StatefulTractogram containing the streamlines to segment.

  • mask_1 (numpy.ndarray) – Binary mask in which the streamlines should start or end.

  • mask_2 (numpy.ndarray) – Binary mask in which the streamlines should start or end.

Returns:

  • new_sft (StatefulTractogram) – Filtered sft.

  • ids (list) – Ids of the streamlines passing through the mask.

scilpy.segment.streamlines.pre_filtering_for_geometrical_shape(sft, size, center, filter_type, is_in_vox)[source]
Parameters:
  • sft (StatefulTractogram) – StatefulTractogram containing the streamlines to segment.

  • size (numpy.ndarray (3)) – Size in mm, x/y/z of the ROI.

  • center (numpy.ndarray (3)) – Center x/y/z of the ROI.

  • filter_type (str) – One of the 3 following choices, ‘any’, ‘all’, ‘either_end’, ‘both_ends’.

  • is_in_vox (bool) – Value to indicate if the ROI is in voxel space.

Returns:

ids – Filtered sft. Ids of the streamlines passing through the mask.

Return type:

tuple

scilpy.segment.streamlines.streamlines_in_mask(sft, target_mask, all_in=False)[source]
Parameters:
  • sft (StatefulTractogram) – StatefulTractogram containing the streamlines to segment.

  • target_mask (numpy.ndarray) – Binary mask in which the streamlines should pass.

Returns:

ids – Ids of the streamlines passing through the mask.

Return type:

list

scilpy.segment.tractogram_from_roi module

scilpy.segment.voting_scheme module

class scilpy.segment.voting_scheme.VotingScheme(config, atlas_directory, transformation, output_directory, minimal_vote_ratio=0.5)[source]

Bases: object

scilpy.segment.voting_scheme.single_recognize(args)[source]

Wrapper function to multiprocess recobundles execution.

Parameters:
  • rbx (Object) – Initialize RBx object with QBx ClusterMap as values

  • model_filepath (str) – Path to the model bundle file

  • params (tuple) –

    bundle_pruning_thrfloat

    Threshold for pruning the model bundle

    streamlines: ArraySequence

    Streamlines of the model bundle

  • bundle_names (list) – List of string with bundle names for models (to get bundle_id)

  • seed (int) – Value to initialize the RandomState of numpy

Returns:

transf_neighbor

bundle_id(int)

Unique value to each bundle to identify them.

recognized_indices(numpy.ndarray)

Streamlines indices from the original tractogram.

Return type:

tuple