How to get connectome from atlas in nilearn

I am almost new in using nilearn. Sorry if it seems easy.
Is there any example or guide for extracting connectome graph network or adjacency matrix from anatomical parcellation atlas in nilearn?

I usually see connectome matrix from diffusion tensor imaging. So it would be nice also having a connectome with anatomical regions.

Thank you in advance for any guide.

Hello, I think what you’re looking for is this example.

To have access to all Nilearn ressources on functional connectivity see the related documentation section for big picture explanations and the list of all available examples for code demos.

1 Like

Thank you, I saw this before, but I am looking for having a coonectome witch each node as a anatomical region an connections from structural network for examlple DTI.

I am trying to map DTI nodes and connections on anatomical parcellation.

Almost I know the procedure to use voxel indices and count the voxel in each region, but still struggling :no_mouth:.

An example is always more straight forward.

Ok, it looks to me like once you have the parcellation of your choice the example cited (or its equivalent for probabilistic atlas) should be stratightforward to apply.

If you want to post the parcellation, I can take a look on how to do it.

Here is some code to extract connectome data (Hagmann 2008) with 998 nodes and the coordinates of nodes (998x3) in talairach coordinates system.
(I put the complete code here)

mat_cont = sio.loadmat("data/hagmann_998.mat")
C = mat_cont['CIJ_fbden_average']
L = mat_cont['CIJ_edgelength_average']
xyz = mat_cont['talairach']

Just as an example let’s try destrieux 2009 atlas.

destrieux = nilearn.datasets.fetch_atlas_destrieux_2009()
coordinates, int_labels = plotting.find_parcellation_cut_coords(

The voxel indices are not match with number of labels from destrieux.labels so I write a bit script to match the nodes and voxel labels.

labels_int_string = [[destrieux.labels[i][0],
                     for i in range(1, len(destrieux.labels))]

ofile = open("data/destrieux_2009_labels.txt", "w")
int_labels_dest = [destrieux.labels[j][0]
                   for j in range(len(destrieux.labels))]
my_list = []
for i in int_labels:
    if i in int_labels_dest:
        ofile.write("{:3d} {:s} \n".format(
            i, destrieux.labels[i][1].decode('UTF-8')))

Now mapping:
I followed a nibabel page for converting coordinates to voxel index.

How to get affine matrix? to invert and get voxel indices of each node?

import numpy.linalg as npl
 epi_vox2anat_vox = npl.inv(anat_img.affine).dot(epi_img.affine)

It is clear?