.. _sphx_glr_auto_examples_01_template_plot_register.py: Registration to common space ============================ Here we show how to create a template from multiple anatomical scans and register all of them to it. Initially, registration is of extracted brains. Once these are reasonably aligned, whole heads are registered, weighted by masks that, if parameters are chosen well, include some scalp. The amount of scalp is hopefully enough to help in differentiating the brain-scalp boundary without including so much head tissue that it starts to contaminate the registration with the highly variable head tissue. Retrieve the data ----------------- .. code-block:: python from sammba import data_fetchers lemur = data_fetchers.fetch_lemur_mircen_2019_t2(subjects=[0, 1, 2]) retest contains paths to images and data description .. code-block:: python print(lemur.anat) .. rst-class:: sphx-glr-script-out Out:: ['/home/salma/nilearn_data/mircen2019_t2/sub-01/sub-01_anat_sub-01_T2w.nii.gz', '/home/salma/nilearn_data/mircen2019_t2/sub-02/sub-02_anat_sub-02_T2w.nii.gz', '/home/salma/nilearn_data/mircen2019_t2/sub-03/sub-03_anat_sub-03_T2w.nii.gz'] Define the writing directory ---------------------------- .. code-block:: python import os write_dir = os.path.join(os.getcwd(), 'lemur_common') if not os.path.exists(write_dir): os.makedirs(write_dir) Create the template ------------------- .. code-block:: python from sammba.registration import anats_to_common affine_register = anats_to_common(lemur.anat, write_dir, 400, use_rats_tool=False, caching=True) We set caching to True, so that the computations are not restarted. The paths to the registered images can be accessed easilly .. code-block:: python registered_anats = affine_register.registered print(registered_anats) .. rst-class:: sphx-glr-script-out Out:: ['/home/salma/CODE/sammba-mri/examples/01_template/lemur_common/sub-01_anat_sub-01_T2w_0_Unifized_for_brain_extraction_resample_shr_affine_catenated.nii.gz', '/home/salma/CODE/sammba-mri/examples/01_template/lemur_common/sub-02_anat_sub-02_T2w_1_Unifized_for_brain_extraction_resample_shr_affine_catenated.nii.gz', '/home/salma/CODE/sammba-mri/examples/01_template/lemur_common/sub-03_anat_sub-03_T2w_2_Unifized_for_brain_extraction_resample_shr_affine_catenated.nii.gz'] Assess the template ------------------- .. code-block:: python from nilearn import image template_img = image.mean_img(registered_anats) Visalize results ---------------- We plot the edges of one individual anat on top of the average image .. code-block:: python from nilearn import plotting average_img = image.mean_img(registered_anats) display = plotting.plot_anat(average_img, dim=-1.6, title='affine register') display.add_edges(registered_anats[0]) plotting.show() .. image:: /auto_examples/01_template/images/sphx_glr_plot_register_001.png :align: center Visualize pipeline steps ------------------------- .. code-block:: python from sammba.graphs import create_pipeline_graph graph_file = os.path.join(write_dir, 'affine_registration_graph') create_pipeline_graph('anats_to_common_affine', graph_file) **Total running time of the script:** ( 51 minutes 0.667 seconds) .. container:: sphx-glr-footer .. container:: sphx-glr-download :download:`Download Python source code: plot_register.py ` .. container:: sphx-glr-download :download:`Download Jupyter notebook: plot_register.ipynb ` .. rst-class:: sphx-glr-signature `Generated by Sphinx-Gallery `_