Giving credit

Previous topic

8.5.1. Comparing the means of 2 images

Next topic

8.5.3. Negating an image with math_img

8.5.2. 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 loose spatial details. In general, the best amount of smoothing for a given analysis depends on the spatial extent of the effects that are expected.

  • ../../_images/sphx_glr_plot_smooth_mean_image_001.png
  • ../../_images/sphx_glr_plot_smooth_mean_image_002.png
  • ../../_images/sphx_glr_plot_smooth_mean_image_003.png
  • ../../_images/sphx_glr_plot_smooth_mean_image_004.png
  • ../../_images/sphx_glr_plot_smooth_mean_image_005.png


First subject functional nifti image (4D) are located at: /home/parietal/gvaroqua/nilearn_data/adhd/data/0010042/0010042_rest_tshift_RPI_voreg_mni.nii.gz

from nilearn import datasets, plotting, image

data = datasets.fetch_adhd(n_subjects=1)

# Print basic information on the dataset
print('First subject functional nifti image (4D) are located at: %s' %

first_epi_file = data.func[0]

# First the compute the mean image, from the 4D series of image
mean_func = image.mean_img(first_epi_file)

# 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)
                      title="Smoothing %imm" % smoothing)

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

Generated by Sphinx-Gallery