Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

Software setup

Authors
Affiliations
Dartmouth College
Johns Hopkins University

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:

  1. MATLAB (R2020a or newer recommended; R2025a+ for the best live-script experience) with the Statistics and Machine Learning Toolbox and Image Processing Toolbox

  2. SPMSPM25 (or SPM12 with MATLAB ≤ R2023b)

  3. CanlabCore — the core object-oriented tools (fmri_data, atlas, region, statistic_image, …)

  4. Neuroimaging_Pattern_Masks (optional, large) — atlases, signature patterns, and masks used in the applied chapters

  5. 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 nltools

Verify:

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.

Cover of Elements of Functional Magnetic Resonance Imaging The book: Elements of Functional Magnetic Resonance Imaging — Wager & Lindquist, MIT Press