.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/utils/subject_to_mni.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note Click :ref:`here ` to download the full example code .. rst-class:: sphx-glr-example-title .. _sphx_glr_auto_examples_utils_subject_to_mni.py: =================================== Transform from Subject to MNI Space =================================== Pycortex has built-in functionality for linearly transforming data to and from standard atlas spaces (e.g. MNI-152). This functionality is built on top of FSL. This example shows how to create a transform from some subject functional space to MNI space, and how to apply that transform to a dataset. .. GENERATED FROM PYTHON SOURCE LINES 13-40 .. code-block:: default import cortex # First let's do this "manually", using cortex.mni from cortex import mni import numpy as np np.random.seed(1234) # This transform is gonna be from one specific functional space for a subject # which is defined by the transform (xfm) s1_to_mni = mni.compute_mni_transform(subject='S1', xfm='fullhead') # s1_to_mni is a 4x4 array describing the transformation in homogeneous corods # Transform data from subject to MNI space # first we will create a dataset to transform data = cortex.Volume.random('S1', 'fullhead') # then transform it! mni_data = mni.transform_to_mni(data, s1_to_mni) # mni_data is a nibabel Nifti1Image mni_data_vol = mni_data.get_data() # the actual array, shape=(182,218,182) # That was the manual method. pycortex can also cache these transforms for you # if you get them using the pycortex database s1_to_mni_db = cortex.db.get_mnixfm('S1', 'fullhead') # this is the same as s1_to_mni, but will return instantly on subsequent calls .. rst-class:: sphx-glr-timing **Total running time of the script:** ( 0 minutes 0.000 seconds) .. _sphx_glr_download_auto_examples_utils_subject_to_mni.py: .. only :: html .. container:: sphx-glr-footer :class: sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: subject_to_mni.py ` .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: subject_to_mni.ipynb ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_