Note

This page is a reference documentation. It only explains the function signature, and not how to use it. Please refer to the user guide for the big picture.

nilearn.image.get_data

nilearn.image.get_data(img)[source]

Get the image data as a numpy.ndarray.

Parameters:
imgNiimg-like object or iterable of Niimg-like objects

See Input and output: neuroimaging data representation.

Returns:
numpy.ndarray

3D or 4D numpy array depending on the shape of img. This function preserves the type of the image data. If img is an in-memory Nifti image it returns the image data array itself – not a copy.

Examples

>>> import numpy as np
>>> from nibabel import Nifti1Image
>>> from nilearn.image import get_data
>>> img = Nifti1Image(
...     np.arange(24).reshape((2, 3, 4)), affine=np.eye(4), dtype=np.int32
... )
>>> data = get_data(img)
>>> data
array([[[ 0,  1,  2,  3],
        [ 4,  5,  6,  7],
        [ 8,  9, 10, 11]],
       [[12, 13, 14, 15],
        [16, 17, 18, 19],
        [20, 21, 22, 23]]])

Examples using nilearn.image.get_data

Different classifiers in decoding the Haxby dataset

Different classifiers in decoding the Haxby dataset

Searchlight analysis of face vs house recognition

Searchlight analysis of face vs house recognition

Voxel-Based Morphometry on Oasis dataset

Voxel-Based Morphometry on Oasis dataset

Clustering methods to learn a brain parcellation from fMRI

Clustering methods to learn a brain parcellation from fMRI

Comparing connectomes on different reference atlases

Comparing connectomes on different reference atlases

Example of generic design in second-level models

Example of generic design in second-level models

Second-level fMRI model: one sample test

Second-level fMRI model: one sample test

Computing a Region of Interest (ROI) mask manually

Computing a Region of Interest (ROI) mask manually

Visualization of affine resamplings

Visualization of affine resamplings

Massively univariate analysis of a calculation task from the Localizer dataset

Massively univariate analysis of a calculation task from the Localizer dataset

Massively univariate analysis of a motor task from the Localizer dataset

Massively univariate analysis of a motor task from the Localizer dataset

Massively univariate analysis of face vs house recognition

Massively univariate analysis of face vs house recognition

NeuroVault meta-analysis of stop-go paradigm studies

NeuroVault meta-analysis of stop-go paradigm studies