Building Connectivity Matrix from tractogram (.trk) with DiPy


I am working with a DWI dataset from the ADNI database, trying to build the connectivity matrix of a tractogram I computed from a subject with Tractoflow, using the Brainnetome Atlas and its MNI standard space. This work is for the yearly class project of my MSc.

Following a DIPY documentation tutorial (Applying image-based deformations to streamlines) for streamline registration, I tried to register my tractogram to a standard MNI space, using the deform_streamlines() function. Some streamlines seem to be incorrectly modified (I visualized the tracts) by the deformation field I computed from the b0 → MNISpace registration, but that is not the main issue as this step ran with no errors.

The problem comes when I try to generate the connectivity matrix of the mentioned tractogram (following Connectivity Matrices, ROI Intersections, and Density Maps) as it raises an error saying “Slice step cannot be zero”. While building the tractogram, I compressed the streamlines, which seems to be an important thing to mention.

How could I fix this? I can also provide code and the error traceback

Thanks for your help, I hope I am not asking a trivial thing.

Operating system and version: Linux-5.11.0-46-generic-x86_64-with-glibc2.17
Python version: Python 3.8.12 (default, Oct 12 2021, 13:49:34) [GCC 7.5.0]
dipy version: 1.4.1
Numpy 1.22.1
SciPy 1.7.3
Nibabel 3.2.1
H5Py: Not installed
Cvxpy: Not installed
fury 0.7.1
(Working on jupyter notebook. )

1 Like


First, you need to make sure your tractogram is in the same space as your Atlas. You can use the command for the tractoflow singularity:

If it’s not the case please follow this tutorial: DIPY : Docs 1.4.1. - Applying image-based deformations to streamlines


Hello, running into a similar problem. Any suggestion on where to start to debug?

Hi @itellaetxe and @bruno.direito

Sometimes DIPY : Docs 1.4.1. - Applying image-based deformations to streamlines does not properly apply warp map to streamlines. We are currently working on fixing it. For now, you could use scilpy’s scil_apply_transform_to_tractogram script for applying warp map to streamlines. It does require you to run ANTs registration first though.


Thank you for the answer. So i am trying to do everything in the DWI image space. Streamlines actually seem fine using plotting tools - the problem only appears when applying the dwi_affine matrix for the connectivity matrix calculation?
Following your suggestion, I should first apply the deformation (using scil_apply_transform_to_tractogram) and then use a eye(4) affine matrix in dipy’s connectivity matrix function?