{ "cells": [ { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "%matplotlib inline" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "\n# Comparing the means of 2 images\n\nThe goal of this example is to illustrate the use of the function\n:func:`nilearn.image.math_img` with a list of images as input.\nWe compare the means of 2 resting state 4D images. The mean of the images\ncould have been computed with nilearn :func:`nilearn.image.mean_img` function.\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Fetching 2 subject movie watching brain development fmri datasets.\n\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "from nilearn import datasets\ndataset = datasets.fetch_development_fmri(n_subjects=2)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Print basic information on the adhd subjects resting state datasets.\n\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "print('Subject 1 resting state dataset at: %s' % dataset.func[0])\nprint('Subject 2 resting state dataset at: %s' % dataset.func[1])" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Comparing the means of the 2 movie watching datasets.\n\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "from nilearn import plotting, image\n\nresult_img = image.math_img(\"np.mean(img1, axis=-1) - np.mean(img2, axis=-1)\",\n img1=dataset.func[0],\n img2=dataset.func[1])\n\nplotting.plot_stat_map(result_img,\n title=\"Comparing means of 2 resting state 4D images.\")\nplotting.show()" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.8.5" } }, "nbformat": 4, "nbformat_minor": 0 }