Note
This page is a reference documentation. It only explains the class signature, and not how to use it. Please refer to the user guide for the big picture.
nilearn.input_data.NiftiMasker¶
-
class
nilearn.input_data.
NiftiMasker
(mask_img=None, sessions=None, smoothing_fwhm=None, standardize=False, detrend=False, low_pass=None, high_pass=None, t_r=None, target_affine=None, target_shape=None, mask_strategy='background', mask_args=None, sample_mask=None, memory_level=1, memory=Memory(cachedir=None), verbose=0)¶ Class for masking of Niimg-like objects.
NiftiMasker is useful when preprocessing (detrending, standardization, resampling, etc.) of in-mask voxels is necessary. Use case: working with time series of resting-state or task maps.
Parameters: mask_img : Niimg-like object, optional
See http://nilearn.github.io/building_blocks/manipulating_mr_images.html#niimg. Mask for the data. If not given, a mask is computed in the fit step. Optional parameters (mask_args and mask_strategy) can be set to fine tune the mask extraction.
sessions : numpy array, optional
Add a session level to the preprocessing. Each session will be detrended independently. Must be a 1D array of n_samples elements.
smoothing_fwhm : float, optional
If smoothing_fwhm is not None, it gives the full-width half maximum in millimeters of the spatial smoothing to apply to the signal.
standardize : boolean, optional
If standardize is True, the time-series are centered and normed: their mean is put to 0 and their variance to 1 in the time dimension.
detrend : boolean, optional
This parameter is passed to signal.clean. Please see the related documentation for details
low_pass : False or float, optional
This parameter is passed to signal.clean. Please see the related documentation for details
high_pass : False or float, optional
This parameter is passed to signal.clean. Please see the related documentation for details
t_r : float, optional
This parameter is passed to signal.clean. Please see the related documentation for details
target_affine : 3x3 or 4x4 matrix, optional
This parameter is passed to image.resample_img. Please see the related documentation for details.
target_shape : 3-tuple of integers, optional
This parameter is passed to image.resample_img. Please see the related documentation for details.
mask_strategy: {‘background’ or ‘epi’}, optional :
The strategy used to compute the mask: use ‘background’ if your images present a clear homogeneous background, and ‘epi’ if they are raw EPI images. Depending on this value, the mask will be computed from masking.compute_background_mask or masking.compute_epi_mask. Default is ‘background’.
mask_args : dict, optional
If mask is None, these are additional parameters passed to masking.compute_background_mask or masking.compute_epi_mask to fine-tune mask computation. Please see the related documentation for details.
sample_mask : Any type compatible with numpy-array indexing
Masks the niimgs along time/fourth dimension. This complements 3D masking by the mask_img argument. This masking step is applied before data preprocessing at the beginning of NiftiMasker.transform. This is useful to perform data subselection as part of a scikit-learn pipeline.
memory : instance of joblib.Memory or string
Used to cache the masking process. By default, no caching is done. If a string is given, it is the path to the caching directory.
memory_level : integer, optional
Rough estimator of the amount of memory used by caching. Higher value means more memory for caching.
verbose : integer, optional
Indicate the level of verbosity. By default, nothing is printed
See also
nilearn.masking.compute_background_mask
,nilearn.masking.compute_epi_mask
,nilearn.image.resample_img
,nilearn.masking.apply_mask
,nilearn.signal.clean
Attributes
Methods
-
__init__
(mask_img=None, sessions=None, smoothing_fwhm=None, standardize=False, detrend=False, low_pass=None, high_pass=None, t_r=None, target_affine=None, target_shape=None, mask_strategy='background', mask_args=None, sample_mask=None, memory_level=1, memory=Memory(cachedir=None), verbose=0)¶
-
fit
(imgs=None, y=None)¶ Compute the mask corresponding to the data
Parameters: imgs: list of Niimg-like objects :
See http://nilearn.github.io/building_blocks/manipulating_mr_images.html#niimg. Data on which the mask must be calculated. If this is a list, the affine is considered the same for all.
-
fit_transform
(X, y=None, confounds=None, **fit_params)¶ Fit to data, then transform it
Parameters: X : Niimg-like object
y : numpy array of shape [n_samples]
Target values.
confounds: list of confounds, optional :
List of confounds (2D arrays or filenames pointing to CSV files). Must be of same length than imgs_list.
Returns: X_new : numpy array of shape [n_samples, n_features_new]
Transformed array.
-
get_params
(deep=True)¶ Get parameters for this estimator.
Parameters: deep: boolean, optional :
If True, will return the parameters for this estimator and contained subobjects that are estimators.
Returns: params : mapping of string to any
Parameter names mapped to their values.
-
set_params
(**params)¶ Set the parameters of this estimator.
The method works on simple estimators as well as on nested objects (such as pipelines). The former have parameters of the form
<component>__<parameter>
so that it’s possible to update each component of a nested object.Returns: self :
-
transform
(imgs, confounds=None)¶ Apply mask, spatial and temporal preprocessing
Parameters: imgs: list of Niimg-like objects :
See http://nilearn.github.io/building_blocks/manipulating_mr_images.html#niimg. Data to be preprocessed
confounds: CSV file path or 2D matrix :
This parameter is passed to nilearn.signal.clean. Please see the related documentation for details
-
transform_imgs
(imgs_list, confounds=None, copy=True, n_jobs=1)¶ Prepare multi subject data in parallel
Parameters: imgs_list: list of Niimg-like objects :
See http://nilearn.github.io/building_blocks/manipulating_mr_images.html#niimg. List of imgs file to prepare. One item per subject.
confounds: list of confounds, optional :
List of confounds (2D arrays or filenames pointing to CSV files). Must be of same length than imgs_list.
copy: boolean, optional :
If True, guarantees that output array has no memory in common with input array.
n_jobs: integer, optional :
The number of cpus to use to do the computation. -1 means ‘all cpus’.
-