7. Reference documentation: all nilearn functions

This is the class and function reference of nilearn. Please refer to the full user guide for further details, as the class and function raw specifications may not be enough to give full guidelines on their uses.

List of modules

7.1. nilearn.connectome: Functional Connectivity

Tools for computing functional connectivity matrices and also implementation of algorithm for sparse multi subjects learning of Gaussian graphical models.


ConnectivityMeasure([cov_estimator, kind, …])

A class that computes different kinds of functional connectivity matrices.

GroupSparseCovariance([alpha, tol, …])

Covariance and precision matrix estimator.

GroupSparseCovarianceCV([alphas, …])

Sparse inverse covariance w/ cross-validated choice of the parameter.


sym_to_vec(symmetric[, discard_diagonal])

DEPRECATED: Function ‘sym_to_vec’ has been renamed to ‘sym_matrix_to_vec’ and will be removed in future releases.

sym_matrix_to_vec(symmetric[, discard_diagonal])

Return the flattened lower triangular part of an array.

vec_to_sym_matrix(vec[, diagonal])

Return the symmetric matrix given its flattened lower triangular part.

group_sparse_covariance(subjects, alpha[, …])

Compute sparse precision matrices and covariance matrices.


Return correlation matrix for a given covariance matrix.


Return partial correlation matrix for a given precision matrix.

7.2. nilearn.datasets: Automatic Dataset Fetching

Helper functions to download NeuroImaging datasets

User guide: See the Fetching open datasets from Internet section for further details.


fetch_atlas_craddock_2012([data_dir, url, …])

Download and return file names for the Craddock 2012 parcellation

fetch_atlas_destrieux_2009([lateralized, …])

Download and load the Destrieux cortical atlas (dated 2009)

fetch_atlas_harvard_oxford(atlas_name[, …])

Load Harvard-Oxford parcellations from FSL.

fetch_atlas_msdl([data_dir, url, resume, …])

Download and load the MSDL brain atlas.


Download and load the Power et al.


Load the Seitzman et al.

fetch_atlas_smith_2009([data_dir, mirror, …])

Download and load the Smith ICA and BrainMap atlas (dated 2009)

fetch_atlas_yeo_2011([data_dir, url, …])

Download and return file names for the Yeo 2011 parcellation.

fetch_atlas_aal([version, data_dir, url, …])

Downloads and returns the AAL template for SPM 12.

fetch_atlas_basc_multiscale_2015([version, …])

Downloads and loads multiscale functional brain parcellations

fetch_atlas_allen_2011([data_dir, url, …])

Download and return file names for the Allen and MIALAB ICA atlas (dated 2011).

fetch_atlas_pauli_2017([version, data_dir, …])

Download the Pauli et al.


Load the Dosenbach et al.

fetch_abide_pcp([data_dir, n_subjects, …])

Fetch ABIDE dataset

fetch_adhd([n_subjects, data_dir, url, …])

Download and load the ADHD resting-state dataset.

fetch_development_fmri([n_subjects, …])

Fetch movie watching based brain development dataset (fMRI)

fetch_haxby([data_dir, n_subjects, …])

Download and loads complete haxby dataset

fetch_icbm152_2009([data_dir, url, resume, …])

Download and load the ICBM152 template (dated 2009)

fetch_icbm152_brain_gm_mask([data_dir, …])

Downloads ICBM152 template first, then loads ‘gm’ mask image.

fetch_localizer_button_task([data_dir, url, …])

Fetch left vs right button press contrast maps from the localizer.

fetch_localizer_contrasts(contrasts[, …])

Download and load Brainomics/Localizer dataset (94 subjects).


Fetch calculation task contrast maps from the localizer.

fetch_miyawaki2008([data_dir, url, resume, …])

Download and loads Miyawaki et al.

fetch_nyu_rest([n_subjects, sessions, …])

Download and loads the NYU resting-state test-retest dataset.

fetch_surf_nki_enhanced([n_subjects, …])

Download and load the NKI enhanced resting-state dataset,

fetch_surf_fsaverage([mesh, data_dir])

Download a Freesurfer fsaverage surface

fetch_atlas_surf_destrieux([data_dir, url, …])

Download and load Destrieux et al, 2010 cortical atlas.

fetch_atlas_talairach(level_name[, …])

Download the Talairach atlas.

fetch_atlas_schaefer_2018([n_rois, …])

Download and return file names for the Schaefer 2018 parcellation

fetch_oasis_vbm([n_subjects, …])

Download and load Oasis “cross-sectional MRI” dataset (416 subjects).

fetch_megatrawls_netmats([dimensionality, …])

Downloads and returns Network Matrices data from MegaTrawls release in HCP.

fetch_cobre([n_subjects, data_dir, url, verbose])

Fetch COBRE datasets preprocessed using NIAK 0.17 under CentOS version 6.3 with Octave version 4.0.2 and the Minc toolkit version 0.3.18.

fetch_neurovault([max_images, …])

Download data from neurovault.org that match certain criteria.

fetch_neurovault_ids([collection_ids, …])

Download specific images and collections from neurovault.org.


Fetch a contrast map from NeuroVault showing the effect of mental subtraction upon auditory instructions

fetch_neurovault_motor_task([data_dir, verbose])

Fetch left vs right button press group contrast map from NeuroVault.


Returns the directories in which nilearn looks for data.


Load skullstripped 2mm version of the MNI152 originally distributed with FSL


Load brain mask from MNI152 T1 template

7.3. nilearn.decoding: Decoding

Decoding tools and algorithms.


SpaceNetClassifier([penalty, loss, …])

Classification learners with sparsity and spatial priors.

SpaceNetRegressor([penalty, l1_ratios, …])

Regression learners with sparsity and spatial priors.

SearchLight(mask_img[, process_mask_img, …])

Implement search_light analysis using an arbitrary type of classifier.

7.4. nilearn.decomposition: Multivariate decompositions

The nilearn.decomposition module includes a subject level variant of the ICA called Canonical ICA.


CanICA([mask, n_components, smoothing_fwhm, …])

Perform Canonical Independent Component Analysis.

DictLearning([n_components, n_epochs, …])

Perform a map learning algorithm based on spatial component sparsity, over a CanICA initialization.

7.5. nilearn.image: Image processing and resampling utilities

Mathematical operations working on Niimg-like objects like -a (3+n)-D block of data, and an affine.


clean_img(imgs[, sessions, detrend, …])

Improve SNR on masked fMRI signals.

concat_imgs(niimgs[, dtype, ensure_ndim, …])

Concatenate a list of 3D/4D niimgs of varying lengths.

coord_transform(x, y, z, affine)

Convert the x, y, z coordinates from one image space to another


Copy an image to a nibabel.Nifti1Image.

crop_img(img[, rtol, copy, pad, return_offset])

Crops img as much as possible


Get the image data as a numpy array.

high_variance_confounds(imgs[, n_confounds, …])

Return confounds signals extracted from input signals with highest variance.

index_img(imgs, index)

Indexes into a 4D Niimg-like object in the fourth dimension.


Iterates over a 4D Niimg-like object in the fourth dimension.


Return the largest connected component of an image or list of images.

load_img(img[, wildcards, dtype])

Load a Niimg-like object from filenames or list of filenames.

math_img(formula, \*\*imgs)

Interpret a numpy based string formula using niimg in named parameters.

mean_img(imgs[, target_affine, …])

Compute the mean of the images (in the time dimension of 4th dimension)

new_img_like(ref_niimg, data[, affine, …])

Create a new image of the same class as the reference image

resample_img(img[, target_affine, …])

Resample a Niimg-like object

resample_to_img(source_img, target_img[, …])

Resample a Niimg-like source image on a target Niimg-like image (no registration is performed: the image should already be aligned).

reorder_img(img[, resample])

Returns an image with the affine diagonal (by permuting axes).

smooth_img(imgs, fwhm)

Smooth images by applying a Gaussian filter.


Performs swapping of hemispheres in the indicated nifti.

threshold_img(img, threshold[, mask_img, copy])

Threshold the given input image, mostly statistical or atlas images.

7.6. nilearn.input_data: Loading and Processing files easily

The nilearn.input_data module includes scikit-learn tranformers and tools to preprocess neuro-imaging data.

User guide: See the NiftiMasker: applying a mask to load time-series section for further details.


NiftiMasker([mask_img, sessions, …])

Applying a mask to extract time-series from Niimg-like objects.

MultiNiftiMasker([mask_img, smoothing_fwhm, …])

Class for masking of Niimg-like objects.

NiftiLabelsMasker(labels_img[, …])

Class for masking of Niimg-like objects.

NiftiMapsMasker(maps_img[, mask_img, …])

Class for masking of Niimg-like objects.

NiftiSpheresMasker(seeds[, radius, …])

Class for masking of Niimg-like objects using seeds.

7.7. nilearn.masking: Data Masking Utilities

Utilities to compute and operate on brain masks

User guide: See the Masking the data: from 4D image to 2D array section for further details.


compute_epi_mask(epi_img[, lower_cutoff, …])

Compute a brain mask from fMRI data in 3D or 4D ndarrays.

compute_multi_epi_mask(epi_imgs[, …])

Compute a common mask for several sessions or subjects of fMRI data.

compute_gray_matter_mask(target_img[, …])

Compute a mask corresponding to the gray matter part of the brain.


Compute a mask corresponding to the gray matter part of the brain for a list of images.

compute_background_mask(data_imgs[, …])

Compute a brain mask for the images by guessing the value of the background from the border of the image.

compute_multi_background_mask(data_imgs[, …])

Compute a common mask for several sessions or subjects of data.

intersect_masks(mask_imgs[, threshold, …])

Compute intersection of several masks

apply_mask(imgs, mask_img[, dtype, …])

Extract signals from images using specified mask.

unmask(X, mask_img[, order])

Take masked data and bring them back into 3D/4D

7.8. nilearn.regions: Operating on regions

The nilearn.regions class module includes region extraction procedure on a 4D statistical/atlas maps and its function.


connected_regions(maps_img[, …])

Extraction of brain connected regions into separate regions.

connected_label_regions(labels_img[, …])

Extract connected regions from a brain atlas image defined by labels (integers).

img_to_signals_labels(imgs, labels_img[, …])

Extract region signals from image.

signals_to_img_labels(signals, labels_img[, …])

Create image from region signals defined as labels.

img_to_signals_maps(imgs, maps_img[, mask_img])

Extract region signals from image.

signals_to_img_maps(region_signals, maps_img)

Create image from region signals defined as maps.


RegionExtractor(maps_img[, mask_img, …])

Class for brain region extraction.

Parcellations(method[, n_parcels, …])

Learn parcellations on fMRI images.

ReNA(mask_img[, n_clusters, scaling, …])

Recursive Neighbor Agglomeration (ReNA): Recursively merges the pair of clusters according to 1-nearest neighbors criterion [R1413c64648a2-1].

7.9. nilearn.mass_univariate: Mass-univariate analysis

Defines a Massively Univariate Linear Model estimated with OLS and permutation test


permuted_ols(tested_vars, target_vars[, …])

Massively univariate group analysis with permuted OLS.

7.10. nilearn.plotting: Plotting brain data

Plotting code for nilearn


find_cut_slices(img[, direction, n_cuts, …])

Find ‘good’ cross-section slicing positions along a given axis.

find_xyz_cut_coords(img[, mask_img, …])

Find the center of the largest activation connected component.

find_parcellation_cut_coords(labels_img[, …])

Return coordinates of center of mass of 3D parcellation atlas


Return coordinates of center probabilistic atlas 4D image

plot_anat([anat_img, cut_coords, …])

Plot cuts of an anatomical image (by default 3 cuts: Frontal, Axial, and Lateral)

plot_img(img[, cut_coords, output_file, …])

Plot cuts of a given image (by default Frontal, Axial, and Lateral)

plot_epi([epi_img, cut_coords, output_file, …])

Plot cuts of an EPI image (by default 3 cuts: Frontal, Axial, and Lateral)

plot_matrix(mat[, title, labels, figure, …])

Plot the given matrix.

plot_roi(roi_img[, bg_img, cut_coords, …])

Plot cuts of an ROI/mask image (by default 3 cuts: Frontal, Axial, and Lateral)

plot_stat_map(stat_map_img[, bg_img, …])

Plot cuts of an ROI/mask image (by default 3 cuts: Frontal, Axial, and Lateral)

plot_glass_brain(stat_map_img[, …])

Plot 2d projections of an ROI/mask image (by default 3 projections: Frontal, Axial, and Lateral).

plot_connectome(adjacency_matrix, node_coords)

Plot connectome on top of the brain glass schematics.

plot_connectome_strength(adjacency_matrix, …)

Plot connectome strength on top of the brain glass schematics.

plot_prob_atlas(maps_img[, bg_img, …])

Plot the probabilistic atlases onto the anatomical image by default MNI template

plot_surf(surf_mesh[, surf_map, bg_map, …])

Plotting of surfaces with optional background and data

plot_surf_roi(surf_mesh, roi_map[, bg_map, …])

Plotting ROI on a surface mesh with optional background

plot_surf_stat_map(surf_mesh, stat_map[, …])

Plotting a stats map on a surface mesh with optional background

view_surf(surf_mesh[, surf_map, bg_map, …])

Insert a surface plot of a surface map into an HTML page.

view_img_on_surf(stat_map_img[, surf_mesh, …])

Insert a surface plot of a statistical map into an HTML page.

view_connectome(adjacency_matrix, node_coords)

Insert a 3d plot of a connectome into an HTML page.

view_markers(marker_coords[, marker_color, …])

Insert a 3d plot of markers in a brain into an HTML page.

view_img(stat_map_img[, bg_img, cut_coords, …])

Interactive html viewer of a statistical map, with optional background


Show all the figures generated by nilearn and/or matplotlib.


OrthoSlicer(cut_coords[, axes, black_bg, …])

A class to create 3 linked axes for plotting orthogonal cuts of 3D maps.

7.11. nilearn.signal: Preprocessing Time Series

Preprocessing functions for time series.

All functions in this module should take X matrices with samples x features


clean(signals[, sessions, detrend, …])

Improve SNR on masked fMRI signals.

high_variance_confounds(series[, …])

Return confounds time series extracted from series with highest variance.

7.12. nilearn.surface: Manipulating surface data

Functions for surface manipulation.



Loading data to be represented on a surface mesh.


Loading a surface mesh geometry

vol_to_surf(img, surf_mesh[, radius, …])

Extract surface data from a Nifti image.