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.compute_brain_mask#
- nilearn.masking.compute_brain_mask(target_img, threshold=0.5, connected=True, opening=2, memory=None, verbose=0, mask_type='whole-brain')[source]#
Compute the whole-brain, grey-matter or white-matter mask. This mask is calculated using MNI152 1mm-resolution template mask onto the target image.
- Parameters
- target_imgNiimg-like object
See https://nilearn.github.io/stable/manipulating_images/input_output.html # noqa:E501 Images used to compute the mask. 3D and 4D images are accepted. Only the shape and affine of
target_img
will be used here.- threshold
float
, optional The value under which the MNI template is cut off. Default=0.5
- connected
bool
, optional If connected is True, only the largest connect component is kept. Default=True.
- opening
bool
orint
, optional This parameter determines whether a morphological opening is performed, to keep only large structures. This step is useful to remove parts of the skull that might have been included.
opening
can be:A boolean : If False, no opening is performed. If True, it is equivalent to
opening=1
.An integer n: The opening is performed via n erosions (see
scipy.ndimage.binary_erosion
). The largest connected component is then estimated ifconnected
is set to True, and 2`n` dilation operations are performed (seescipy.ndimage.binary_dilation
) followed by n erosions. This corresponds to 1 opening operation of order n followed by a closing operator of order n.
Note
Turning off opening (
opening=False
) will also prevent any smoothing applied to the image during the mask computation.Default=2.
- memoryinstance of
joblib.Memory
orstr
Used to cache the masking process. By default, no caching is done. If a
str
is given, it is the path to the caching directory.- verbose
int
, optional Verbosity level (0 means no message). Default=0.
- mask_type{‘whole-brain’, ‘gm’, ‘wm’}, optional
Type of mask to be computed:
‘whole-brain’: Computes the whole-brain mask.
‘gm’: Computes the grey-matter mask.
‘wm’: Computes the white-matter mask.
Default = ‘whole-brain’.
New in version 0.8.1.
- Returns
- mask
nibabel.nifti1.Nifti1Image
The whole-brain mask (3D image).
- mask