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)

Compute the whole-brain mask. This mask is calculated through the resampling of the MNI152 template mask onto the target image.

Parameters:

target_img : Niimg-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.

threshold : float, optional

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

connected : bool, optional

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

opening : bool 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.

memory : instance of joblib.Memory or str

Used to cache the function call.

verbose : int, optional

Controls the amount of verbosity: higher numbers give more messages

Returns:

mask : nibabel.Nifti1Image

The whole-brain mask (3D image)