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.math_img(formula, **imgs)#
Interpret a numpy based string formula using niimg in named parameters.
New in version 0.2.3.
Result of the formula as a Nifti image. Note that the dimension of the result image can be smaller than the input image. The affine is the same as the input image.
To simply compute the mean of multiple images
This function is the Python equivalent of ImCal in SPM or fslmaths in FSL.
Let’s load an image using nilearn datasets module:
>>> from nilearn import datasets >>> anatomical_image = datasets.load_mni152_template()
Now we can use any numpy function on this image:
>>> from nilearn.image import math_img >>> log_img = math_img("np.log(img)", img=anatomical_image)
We can also apply mathematical operations on several images:
>>> result_img = math_img("img1 + img2", ... img1=anatomical_image, img2=log_img)