.. _sphx_glr_auto_examples_02_preprocessing_plot_fmri_coregistration.py: Functional and anatomical coregistration ======================================== Standard functional preprocessing and registration of functional image to the anatomical. Retrieve data ------------- .. code-block:: python from sammba import data_fetchers retest = data_fetchers.fetch_zurich_test_retest(subjects=[0], correct_headers=True) retest contains paths to images and data description .. code-block:: python anat_filename = retest.anat[0] func_filename = retest.func[0] print(func_filename) .. rst-class:: sphx-glr-script-out Out:: /home/salma/nilearn_data/zurich_retest/baseline/1366/rsfMRI_corrected.nii.gz We use the `Coregistrator`, which coregisters the anatomical to a given modality .. code-block:: python from sammba.registration import Coregistrator coregistrator = Coregistrator(output_dir='animal_1366', brain_volume=400, use_rats_tool=False, caching=True) print(coregistrator) .. rst-class:: sphx-glr-script-out Out:: Coregistrator(brain_volume=400, caching=True, clipping_fraction=0.2, output_dir='animal_1366', use_rats_tool=False, verbose=True) `Coregistrator` comes with a parameter `clipping_fraction=.2` which sometimes needs to be changed to get a good brain mask. You can check how this parameter impacts the brain segmentation .. code-block:: python from sammba.segmentation import brain_extraction_report print(brain_extraction_report(anat_filename, brain_volume=400, clipping_fractions=[.1, .2, .9, None], use_rats_tool=False)) .. rst-class:: sphx-glr-script-out Out:: AP length RL width IS height symmetry volume fraction 0.10 13.50 9.70 6.10 0.90 373.50 fraction 0.20 12.90 9.70 6.20 0.91 384.19 fraction 0.90 19.00 14.00 7.00 1.00 1862.00 no fraction 19.00 14.00 7.00 1.00 1862.00 Anatomical to functional registration ------------------------------------- .. code-block:: python coregistrator.fit_anat(anat_filename) coregistrator.fit_modality(func_filename, 'func', t_r=1., prior_rigid_body_registration=True) The paths to the registered functional and anatomical images are accessible through the `coregistrator` attributes .. code-block:: python registered_func_filename = coregistrator.undistorted_func_ registered_anat_filename = coregistrator.anat_in_func_space_ Check out the results --------------------- .. code-block:: python from nilearn import plotting, image display = plotting.plot_epi(image.mean_img(registered_func_filename), title='coreg anat edges on top of mean coreg EPI') display.add_edges(registered_anat_filename) plotting.show() .. image:: /auto_examples/02_preprocessing/images/sphx_glr_plot_fmri_coregistration_001.png :align: center **Total running time of the script:** ( 0 minutes 50.045 seconds) .. container:: sphx-glr-footer .. container:: sphx-glr-download :download:`Download Python source code: plot_fmri_coregistration.py ` .. container:: sphx-glr-download :download:`Download Jupyter notebook: plot_fmri_coregistration.ipynb ` .. rst-class:: sphx-glr-signature `Generated by Sphinx-Gallery `_