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.unmask¶
- nilearn.masking.unmask(X, mask_img, order='F')[source]¶
Take masked data and bring them back into 3D/4D.
This function can be applied to a list of masked data.
- Parameters:
- X
numpy.ndarray(orlistof) Masked data. shape: (samples #, features #). If X is one-dimensional, it is assumed that samples# == 1.
- mask_imgNiimg-like object
See Input and output: neuroimaging data representation. Must be 3-dimensional.
- order“F” or “C”, default=’F’
Data ordering in output array. This function is slightly faster with Fortran ordering.
- X
- Returns:
- data
nibabel.nifti1.Nifti1Imageor list ofnibabel.nifti1.Nifti1Image Unmasked data. Depending on the shape of X, data can have different shapes:
X.ndim == 2: Shape: (mask.shape[0], mask.shape[1], mask.shape[2], X.shape[0])
X.ndim == 1: Shape: (mask.shape[0], mask.shape[1], mask.shape[2])
- data
Examples
>>> import numpy as np >>> import nibabel as nib >>> from nilearn.masking import unmask >>> from nilearn.image import get_data >>> >>> # Define a 2x2x1 mask, so that it can be displayed in 2D. >>> # The two nonzero entries mark the in-mask voxels. >>> mask_data = np.array([[[1], [0]], ... [[1], [0]]]) >>> mask_img = nib.Nifti1Image(mask_data.astype("uint8"), np.eye(4)) >>> get_data(mask_img)[:, :, 0] array([[1, 0], [1, 0]], dtype=uint8) >>> >>> # Provide previously masked data as a 1D array and bring it back to 3D. >>> signal_1d = np.array([10.0, 20.0]) >>> image_3d = unmask(signal_1d, mask_img) >>> get_data(image_3d)[:, :, 0] array([[10., 0.], [20., 0.]])