Extracting signals from a brain parcellationΒΆ

Here we show how to extract signals from a brain parcellation and compute a correlation matrix.

We also show the importance of defining good confounds signals: the first correlation matrix is computed after regressing out simple confounds signals: movement regressors, white matter and CSF signals, ... The second one is without any confounds: all regions are connected to each other.

One reference that discusses the importance of confounds is Varoquaux and Craddock, Learning and comparing functional connectomes across subjects, NeuroImage 2013.

This is just a code example, see the corresponding section in the documentation for more.

Python source code: plot_signal_extraction.py

from nilearn import datasets

# Retrieve our atlas
dataset = datasets.fetch_atlas_harvard_oxford('cort-maxprob-thr25-2mm')
atlas_filename, labels = dataset.maps, dataset.labels

print('Atlas ROIs are located in nifti image (4D) at: %s' %
      atlas_filename)  # 4D data

# And one subject of resting-state data
data = datasets.fetch_adhd(n_subjects=1)

# To extract signals on a parcellation defined by labels, we use the
# NiftiLabelsMasker
from nilearn.input_data import NiftiLabelsMasker
masker = NiftiLabelsMasker(labels_img=atlas_filename, standardize=True,
                           memory='nilearn_cache', verbose=5)


# Here we go from nifti files to the signal time series in a numpy
# array. Note how we give confounds to be regressed out during signal
# extraction
time_series = masker.fit_transform(data.func[0], confounds=data.confounds)

import numpy as np
correlation_matrix = np.corrcoef(time_series.T)

# Plot the correlation matrix
from matplotlib import pyplot as plt
plt.figure(figsize=(10, 10))
plt.imshow(correlation_matrix, interpolation="nearest")

# Add labels and adjust margins
x_ticks = plt.xticks(range(len(labels) - 1), labels[1:], rotation=90)
y_ticks = plt.yticks(range(len(labels) - 1), labels[1:])
plt.gca().yaxis.tick_right()
plt.subplots_adjust(left=.01, bottom=.3, top=.99, right=.62)


###############################################################################
# Same thing without confounds, to stress the importance of confounds

time_series = masker.fit_transform(data.func[0])

correlation_matrix = np.corrcoef(time_series.T)

plt.figure(figsize=(10, 10))
plt.imshow(correlation_matrix, interpolation="nearest")

x_ticks = plt.xticks(range(len(labels) - 1), labels[1:], rotation=90)
y_ticks = plt.yticks(range(len(labels) - 1), labels[1:])
plt.gca().yaxis.tick_right()
plt.subplots_adjust(left=.01, bottom=.3, top=.99, right=.62)
plt.suptitle('No confounds', size=27)

plt.show()

Total running time of the example: 0.00 seconds ( 0 minutes 0.00 seconds)