You can use most of this site with no setup at all — in-browser and Colab options cover the Python exercises. Set up software locally when you’re ready to work with your own data.
MATLAB + CANlab tools¶
The MATLAB exercises use the CANlab Core Tools, an object-oriented framework for fMRI analysis, along with SPM.
Requirements:
MATLAB (R2020a or newer recommended; R2025a+ for the best live-script experience) with the Statistics and Machine Learning Toolbox and Image Processing Toolbox
SPM — SPM25 (or SPM12 with MATLAB ≤ R2023b)
CanlabCore — the core object-oriented tools (
fmri_data,atlas,region,statistic_image, …)Neuroimaging
_Pattern _Masks (optional, large) — atlases, signature patterns, and masks used in the applied chapters CANlab
_help _examples (optional) — extended walkthroughs and sample data
Install:
% Clone the repositories (or download ZIPs from GitHub), then:
addpath(genpath('/path/to/spm')); % SPM
addpath(genpath('/path/to/CanlabCore')); % CANlab Core
savepath;
% Verify your setup:
which fmri_data
obj = load_image_set('emotionreg'); % downloads a small sample dataset
plot(obj);Full documentation, walkthroughs, and help are at canlab.github.io.
Python + nilearn¶
The Python exercises primarily use nilearn (statistical learning for neuroimaging), with nibabel, numpy/scipy, pandas, matplotlib, and scikit-learn. Some tutorials also feature nltools from the Cosan Lab, whose design is closely aligned with the CANlab MATLAB tools.
# With conda (recommended):
conda create -n elements-fmri python=3.12
conda activate elements-fmri
pip install nilearn nibabel matplotlib pandas scikit-learn statsmodels jupyterlab
# Optional:
pip install nltoolsVerify:
import nilearn
from nilearn import datasets, plotting
img = datasets.load_mni152_template()
plotting.plot_anat(img)Data used in the tutorials¶
Tutorial datasets are small, openly licensed, and downloaded automatically by the exercises themselves (from this site, OpenNeuro, Neurovault, or package data). No manual data setup is needed.
The book: Elements of Functional Magnetic Resonance Imaging — Wager & Lindquist, MIT Press