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.masking.apply_mask#

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

Extract signals from images using specified mask.

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

Parameters:
imgslist of 4D Niimg-like objects

See Input and output: neuroimaging data representation. Images to be masked. list of lists of 3D images are also accepted.

mask_imgNiimg-like object

See Input and output: neuroimaging data representation. 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_fwhmfloat, optional.

If smoothing_fwhm is not None, it gives the full-width at half maximum in millimeters of the spatial smoothing to apply to the signal.

Note

Implies ensure_finite=True.

ensure_finitebool, default=True

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

Returns:
run_seriesnumpy.ndarray

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

Notes

When using smoothing, ensure_finite is set to True, as non-finite values would spread across the image.