.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/utils/mni_to_subject.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_mni_to_subject.py: =================================== Transform from MNI to Subject 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 (the same as in subject_to_mni.py), and how to use that to put data into subject space from MNI space. .. GENERATED FROM PYTHON SOURCE LINES 14-45 .. 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 MNI to subject space # first we will create a dataset to transform # this uses the implicitly created "identity" transform, which is used for data # in the native anatomical space (i.e. same dims as the base anatomical image, # and in the same space as the surface) data = cortex.Volume.random('MNI', 'identity') # then transform it into the space defined by the 'fullhead' transform for 'S1' subject_data = mni.transform_mni_to_subject('S1', 'fullhead', data.data, s1_to_mni) # subject_data is a nibabel Nifti1Image subject_data_vol = mni_data.get_data() # the actual array, shape=(100,100,31) # 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_mni_to_subject.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: mni_to_subject.py ` .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: mni_to_subject.ipynb ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_