Giving credit

Table Of Contents

Previous topic

7.7.5. nilearn.masking.intersect_masks

Next topic

7.7.7. nilearn.masking.unmask


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.

7.7.6. nilearn.masking.apply_mask

nilearn.masking.apply_mask(imgs, mask_img, dtype='f', smoothing_fwhm=None, ensure_finite=True)

Extract signals from images using specified mask.

Read the time series from the given Niimg-like object, using the mask.


imgs: list of 4D Niimg-like objects

See Images to be masked. list of lists of 3D images are also accepted.

mask_img: Niimg-like object

See 3D mask array: True where a voxel should be used.

dtype: numpy dtype or ‘f’

The dtype of the output, if ‘f’, any float output is acceptable and if the data is stored on the disk as floats the data type will not be changed.

smoothing_fwhm: float

(optional) Gives the size of the spatial smoothing to apply to the signal, in voxels. Implies ensure_finite=True.

ensure_finite: bool

If ensure_finite is True (default), the non-finite values (NaNs and infs) found in the images will be replaced by zeros.


session_series: numpy.ndarray

2D array of series with shape (image number, voxel number)


When using smoothing, ensure_finite is set to True, as non-finite values would spread accross the image. Examples using nilearn.masking.apply_mask