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.

8.7.3. 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 http://nilearn.github.io/manipulating_images/input_output.html Images used to compute the mask. 3D and 4D images are accepted. Only the shape and affine of target_img will be used here.

thresholdfloat, optional

The value under which the MNI template is cut off. Default value is 0.5

connectedbool, optional

if connected is True, only the largest connected component is kept. Default is True

openingbool or int, optional

if opening is True, a morphological opening is performed, to keep only large structures. If opening is an integer n, it is performed via n erosions. After estimation of the largest connected constituent, 2`n` closing operations are performed followed by n erosions. This corresponds to 1 opening operation of order n followed by a closing operator of order n.

memoryinstance of joblib.Memory or str

Used to cache the function call.

verboseint, optional

Controls the amount of verbosity: higher numbers give more messages

mask_type{‘whole-brain’, ‘gm’, ‘wm’}, optional

Type of mask to be computed: ‘whole-brain’, ‘grey-matter’ (‘gm’) or ‘white-matter’ (‘wm’). Default = ‘whole-brain’

New in version 0.8.1.

Returns
masknibabel.Nifti1Image

The whole-brain mask (3D image)