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.image.smooth_img¶
- nilearn.image.smooth_img(imgs, fwhm)[source]¶
Smooth images by applying a Gaussian filter.
Apply a Gaussian filter along the three first dimensions of arr. In all cases, non-finite values in input image are replaced by zeros.
- Parameters:
- imgsNiimg-like object,
SurfaceImage, or iterable of Niimg-like objects orSurfaceImage. Image(s) to smooth (see Input and output: neuroimaging data representation for a detailed description of the valid input types).
- fwhmscalar,
numpy.ndarray, ortuple, orlist,or ‘fast’ or None, optional Smoothing strength, as a full-width at half maximum, in millimeters.
For surface data, only scalar and None are supported.
For volume data, several options are possible:
If a nonzero scalar is given, width is identical in all 3 directions.
If a
numpy.ndarray,tuple, orlistis given, it must have 3 elements, giving the FWHM along each axis. If any of the elements is 0 or None, smoothing is not performed along that axis.If fwhm=”fast”, a fast smoothing will be performed with a filter [0.2, 1, 0.2] in each direction and a normalization to preserve the local average value.
If fwhm is None, no filtering is performed (useful when just removal of non-finite values is needed).
Note
In corner case situations, fwhm is simply kept to None when fwhm is specified as fwhm=0.
- imgsNiimg-like object,
- Returns:
Nifti1Image,SurfaceImage,listofNifti1Image, orlistofSurfaceImageSmoothed input image(s) or surface(s). A
listis returned ifimgswas passed as an iterable.
Examples
Let’s first create a Nifti1Image:
>>> import numpy as np >>> from nibabel import Nifti1Image >>> data = np.array([[[0.0, 0.0, 0.0], ... [0.0, 3.0, 0.0], ... [0.0, 0.0, 0.0]]]) >>> img = Nifti1Image(data, affine=np.eye(4))
Now we can smooth the image:
>>> from nilearn.image import smooth_img, get_data >>> smoothed_img = smooth_img(img, fwhm=2) >>> data = get_data(smoothed_img) >>> data array([[[0.20943692, 0.37378672, 0.20943692], [0.37378672, 0.66710546, 0.37378672], [0.20943692, 0.37378672, 0.20943692]]])
Examples using nilearn.image.smooth_img¶
Basic nilearn example: manipulating and looking at data
Computing a Region of Interest (ROI) mask manually