# Smoothing an image¶

Here we smooth a mean EPI image and plot the result

As we vary the smoothing FWHM, note how we decrease the amount of noise, but also lose spatial details. In general, the best amount of smoothing for a given analysis depends on the spatial extent of the effects that are expected.

```from nilearn import datasets, image, plotting

data = datasets.fetch_development_fmri(n_subjects=1)

# Print basic information on the dataset
print(
f"First subject functional nifti image (4D) are located at: {data.func[0]}"
)

first_epi_file = data.func[0]

# First compute the mean image, from the 4D series of image
```
```[get_dataset_dir] Dataset found in /home/runner/work/nilearn/nilearn/nilearn_data/development_fmri
[get_dataset_dir] Dataset found in /home/runner/work/nilearn/nilearn/nilearn_data/development_fmri/development_fmri
[get_dataset_dir] Dataset found in /home/runner/work/nilearn/nilearn/nilearn_data/development_fmri/development_fmri
First subject functional nifti image (4D) are located at: /home/runner/work/nilearn/nilearn/nilearn_data/development_fmri/development_fmri/sub-pixar123_task-pixar_space-MNI152NLin2009cAsym_desc-preproc_bold.nii.gz
```

Then we smooth, with a varying amount of smoothing, from none to 20mm by increments of 5mm

```for smoothing in range(0, 25, 5):
smoothed_img = image.smooth_img(mean_func, smoothing)
plotting.plot_epi(smoothed_img, title=f"Smoothing {int(smoothing)}mm")

plotting.show()
```
```/opt/hostedtoolcache/Python/3.12.5/x64/lib/python3.12/site-packages/nilearn/image/image.py:222: UserWarning:

The parameter 'fwhm' for smoothing is specified as 0. Setting it to None (no smoothing will be performed)
```

Total running time of the script: (0 minutes 2.760 seconds)

Estimated memory usage: 358 MB

Gallery generated by Sphinx-Gallery