.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/plot_segment_baboon_ants_based.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_plot_segment_baboon_ants_based.py: .. _plot_segment_baboon_ants_based: =============================================================================== Plot the results of a segmentation of a baboon dataset with ANTS-based pipeline =============================================================================== .. GENERATED FROM PYTHON SOURCE LINES 8-23 .. code-block:: default # Authors: David Meunier # License: BSD (3-clause) # sphinx_gallery_thumbnail_number = 2 import os import os.path as op import json import pprint from macapype.utils.utils_tests import load_test_data import matplotlib.pyplot as plt # noqa .. GENERATED FROM PYTHON SOURCE LINES 24-26 Testing plot in local ############################################################################## .. GENERATED FROM PYTHON SOURCE LINES 26-39 .. code-block:: default data_path = load_test_data("data_test_baboon_processed") wf_path = os.path.join(data_path, "example_segment_baboon_ants_based_Odor") graph = os.path.join(wf_path, "graph.png") img = plt.imread(graph) plt.figure(figsize=(36, 72)) plt.imshow(img) plt.axis('off') plt.show() .. image-sg:: /auto_examples/images/sphx_glr_plot_segment_baboon_ants_based_001.png :alt: plot segment baboon ants based :srcset: /auto_examples/images/sphx_glr_plot_segment_baboon_ants_based_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out Out: .. code-block:: none data_dirpath /home/meunier.d/data_macapype already exists /home/meunier.d/data_macapype/data_test_baboon_processed Already exists, skipping download .. GENERATED FROM PYTHON SOURCE LINES 40-42 Data preparation ############################################################################## .. GENERATED FROM PYTHON SOURCE LINES 44-46 results of cropping =========================== .. GENERATED FROM PYTHON SOURCE LINES 46-70 .. code-block:: default cropped_T1_file = op.join(wf_path, "short_data_preparation_pipe", "prep_T1", "crop", "sub-Odor_ses-T1_T1w_roi.nii.gz") assert op.exists(cropped_T1_file), "Error with {}".format(cropped_T1_file) # displaying results cropped_T1 = os.path.join(wf_path, "cropped_T1.png") cmd = "fsleyes render --outfile {} --size 1800 600 {}".format(cropped_T1, cropped_T1_file) os.system(cmd) cropped_T2_file = op.join(wf_path, "short_data_preparation_pipe", "prep_T2", "crop", "sub-Odor_ses-T1_T2w_roi.nii.gz") assert op.exists(cropped_T2_file), "Error with {}".format(cropped_T2_file) # displaying results cropped_T2 = os.path.join(wf_path, "cropped_T2.png") cmd = "fsleyes render --outfile {} --size 1800 600 {}".format(cropped_T2, cropped_T2_file) os.system(cmd) .. rst-class:: sphx-glr-script-out Out: .. code-block:: none 0 .. GENERATED FROM PYTHON SOURCE LINES 71-73 results of norm_intensity =========================== .. GENERATED FROM PYTHON SOURCE LINES 73-97 .. code-block:: default norm_intensity_T1_file = op.join(wf_path, "short_data_preparation_pipe", "prep_T1", "norm_intensity", "sub-Odor_ses-T1_T1w_roi_corrected.nii.gz") assert op.exists(norm_intensity_T1_file), "Error with {}".format(norm_intensity_T1_file) # displaying results norm_intensity_T1 = os.path.join(wf_path, "norm_intensity_T1.png") cmd = "fsleyes render --outfile {} --size 1800 600 {}".format(norm_intensity_T1, norm_intensity_T1_file) os.system(cmd) norm_intensity_T2_file = op.join(wf_path, "short_data_preparation_pipe", "prep_T2", "norm_intensity", "sub-Odor_ses-T1_T2w_roi_corrected.nii.gz") assert op.exists(norm_intensity_T2_file), "Error with {}".format(norm_intensity_T2_file) # displaying results norm_intensity_T2 = os.path.join(wf_path, "norm_intensity_T2.png") cmd = "fsleyes render --outfile {} --size 1800 600 {}".format(norm_intensity_T2, norm_intensity_T2_file) os.system(cmd) .. rst-class:: sphx-glr-script-out Out: .. code-block:: none 0 .. GENERATED FROM PYTHON SOURCE LINES 98-100 results of denoising =========================== .. GENERATED FROM PYTHON SOURCE LINES 100-126 .. code-block:: default denoise_T1_file = op.join( wf_path, "short_data_preparation_pipe", "prep_T1", "denoise", "sub-Odor_ses-T1_T1w_roi_corrected_noise_corrected.nii.gz") assert op.exists(denoise_T1_file), "Error with {}".format(denoise_T1_file) # displaying results denoise_T1 = os.path.join(wf_path, "denoise_T1.png") cmd = "fsleyes render --outfile {} --size 1800 600 {}".format(denoise_T1, denoise_T1_file) os.system(cmd) denoise_T2_file = op.join( wf_path, "short_data_preparation_pipe", "prep_T2", "denoise", "sub-Odor_ses-T1_T2w_roi_corrected_noise_corrected.nii.gz") assert op.exists(denoise_T2_file), "Error with {}".format(denoise_T2_file) # displaying results denoise_T2 = os.path.join(wf_path, "denoise_T2.png") cmd = "fsleyes render --outfile {} --size 1800 600 {}".format(denoise_T2, denoise_T2_file) os.system(cmd) .. rst-class:: sphx-glr-script-out Out: .. code-block:: none 0 .. GENERATED FROM PYTHON SOURCE LINES 127-152 .. code-block:: default fig, axs = plt.subplots(3, 1, figsize=(36, 24)) axs[0].imshow(plt.imread(cropped_T1)) axs[0].axis('off') axs[1].imshow(plt.imread(norm_intensity_T1)) axs[1].axis('off') axs[2].imshow(plt.imread(denoise_T1)) axs[2].axis('off') plt.show() fig, axs = plt.subplots(3, 1, figsize=(36, 24)) axs[0].imshow(plt.imread(cropped_T2)) axs[0].axis('off') axs[1].imshow(plt.imread(norm_intensity_T2)) axs[1].axis('off') axs[2].imshow(plt.imread(denoise_T2)) axs[2].axis('off') plt.show() .. rst-class:: sphx-glr-horizontal * .. image-sg:: /auto_examples/images/sphx_glr_plot_segment_baboon_ants_based_002.png :alt: plot segment baboon ants based :srcset: /auto_examples/images/sphx_glr_plot_segment_baboon_ants_based_002.png :class: sphx-glr-multi-img * .. image-sg:: /auto_examples/images/sphx_glr_plot_segment_baboon_ants_based_003.png :alt: plot segment baboon ants based :srcset: /auto_examples/images/sphx_glr_plot_segment_baboon_ants_based_003.png :class: sphx-glr-multi-img .. GENERATED FROM PYTHON SOURCE LINES 153-155 First part of the pipeline: brain extraction ############################################################################## .. GENERATED FROM PYTHON SOURCE LINES 157-159 Correct bias results ========================== .. GENERATED FROM PYTHON SOURCE LINES 159-182 .. code-block:: default debiased_T1_file = op.join( wf_path, "brain_extraction_pipe", "correct_bias_pipe", "restore_T1", "sub-Odor_ses-T1_T1w_roi_corrected_noise_corrected_maths.nii.gz") assert op.exists(norm_intensity_T2_file) debiased_T1 = os.path.join(wf_path,"debiased_T1.png") cmd = "fsleyes render --outfile {} --size 1800 600 {}".format(debiased_T1, debiased_T1_file) os.system(cmd) import matplotlib.pyplot as plt # noqa fig, axs = plt.subplots(2, 1, figsize=(36, 24)) axs[0].imshow(plt.imread(denoise_T1)) axs[0].axis('off') axs[1].imshow(plt.imread(debiased_T1)) axs[1].axis('off') plt.show() .. image-sg:: /auto_examples/images/sphx_glr_plot_segment_baboon_ants_based_004.png :alt: plot segment baboon ants based :srcset: /auto_examples/images/sphx_glr_plot_segment_baboon_ants_based_004.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 183-185 Brain extraction results ========================== .. GENERATED FROM PYTHON SOURCE LINES 185-206 .. code-block:: default # At the end 1st part pipeline mask_file = os.path.join( wf_path, "brain_extraction_pipe", "extract_pipe", "smooth_mask", "sub-Odor_ses-T1_T1w_roi_corrected_noise_corrected_maths_brain_bin_bin.nii.gz") assert op.exists(mask_file) mask = os.path.join(wf_path,"mask.png") #cmd = "fsleyes render --outfile {} --size 800 600 {} -ot mask -o -a 50 {}".format(mask, mask_file, T1_file) cmd = "fsleyes render --outfile {} --size 800 600 {} {} -a 50".format(mask, cropped_T1_file, mask_file) os.system(cmd) import matplotlib.pyplot as plt # noqa img = plt.imread(mask) plt.figure(figsize=(36, 12)) plt.imshow(img) plt.axis('off') plt.show() .. image-sg:: /auto_examples/images/sphx_glr_plot_segment_baboon_ants_based_005.png :alt: plot segment baboon ants based :srcset: /auto_examples/images/sphx_glr_plot_segment_baboon_ants_based_005.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 207-209 Second part of the pipeline: segmentation ############################################################################# .. GENERATED FROM PYTHON SOURCE LINES 209-212 .. code-block:: default seg_pipe = op.join(wf_path, "brain_segment_from_mask_pipe") .. GENERATED FROM PYTHON SOURCE LINES 213-215 debias T1xT2 and debias N4 ============================= .. GENERATED FROM PYTHON SOURCE LINES 215-246 .. code-block:: default debiased_mask_T1_file = os.path.join(seg_pipe, "masked_correct_bias_pipe", "restore_mask_T1", "sub-Odor_ses-T1_T1w_roi_corrected_noise_corrected_maths_masked.nii.gz") debiased_mask_T1 = os.path.join(wf_path,"debiased_mask_T1.png") cmd = "fsleyes render --outfile {} --size 1800 600 {} -cm Render3".format(debiased_mask_T1, debiased_mask_T1_file) os.system(cmd) N4_debias_T1_file = os.path.join(seg_pipe, "register_NMT_pipe", "norm_intensity", "sub-Odor_ses-T1_T1w_roi_corrected_noise_corrected_maths_masked_corrected.nii.gz") N4_debias_T1 = os.path.join(wf_path,"N4_debias_T1.png") cmd = "fsleyes render --outfile {} --size 1800 600 {} -cm Render3".format(N4_debias_T1, N4_debias_T1_file) os.system(cmd) import matplotlib.pyplot as plt # noqa fig, axs = plt.subplots(3, 1, figsize=(36, 24)) axs[0].imshow(plt.imread(norm_intensity_T1)) axs[0].axis('off') axs[1].imshow(plt.imread(debiased_mask_T1)) axs[1].axis('off') axs[2].imshow(plt.imread(N4_debias_T1)) axs[2].axis('off') plt.show() .. image-sg:: /auto_examples/images/sphx_glr_plot_segment_baboon_ants_based_006.png :alt: plot segment baboon ants based :srcset: /auto_examples/images/sphx_glr_plot_segment_baboon_ants_based_006.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 247-249 register template to subject ============================== .. GENERATED FROM PYTHON SOURCE LINES 249-272 .. code-block:: default deoblique_T1_file = os.path.join( seg_pipe, "register_NMT_pipe", "deoblique", "sub-Odor_ses-T1_T1w_roi_corrected_noise_corrected_maths_masked_corrected.nii.gz") reg_template_mask_to_T1_file = os.path.join( seg_pipe, "register_NMT_pipe", "align_NMT", "Haiko89_Asymmetric.nii.gz") reg_template_mask_to_T1 = os.path.join(wf_path,"reg_template_mask_to_T1.png") cmd = "fsleyes render --outfile {} --size 1800 600 {} {} -a 50".format( reg_template_mask_to_T1, deoblique_T1_file, reg_template_mask_to_T1_file) os.system(cmd) import matplotlib.pyplot as plt # noqa img = plt.imread(reg_template_mask_to_T1) plt.figure(figsize=(36, 12)) plt.imshow(img) plt.axis('off') plt.show() .. image-sg:: /auto_examples/images/sphx_glr_plot_segment_baboon_ants_based_007.png :alt: plot segment baboon ants based :srcset: /auto_examples/images/sphx_glr_plot_segment_baboon_ants_based_007.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 273-275 segmentation results by tissue ================================ .. GENERATED FROM PYTHON SOURCE LINES 275-290 .. code-block:: default csf_file = os.path.join(seg_pipe, "segment_atropos_pipe", "threshold_csf", "segment_SegmentationPosteriors01_thresh.nii.gz") gm_file = os.path.join(seg_pipe, "segment_atropos_pipe", "threshold_gm", "segment_SegmentationPosteriors02_thresh.nii.gz") wm_file = os.path.join(seg_pipe, "segment_atropos_pipe", "threshold_wm", "segment_SegmentationPosteriors03_thresh.nii.gz") segmentation_sep = os.path.join(wf_path,"segmentation_sep.png") cmd = "fsleyes render --outfile {} --size 1800 600 {} {} -cm red -a 30 {} -cm blue -a 30 {} -cm green -a 30".format(segmentation_sep, debiased_mask_T1_file, gm_file, wm_file, csf_file) os.system(cmd) import matplotlib.pyplot as plt # noqa img = plt.imread(segmentation_sep) plt.figure(figsize=(36, 12)) plt.imshow(img) plt.axis('off') plt.show() .. image-sg:: /auto_examples/images/sphx_glr_plot_segment_baboon_ants_based_008.png :alt: plot segment baboon ants based :srcset: /auto_examples/images/sphx_glr_plot_segment_baboon_ants_based_008.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-timing **Total running time of the script:** ( 1 minutes 55.992 seconds) .. _sphx_glr_download_auto_examples_plot_segment_baboon_ants_based.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: plot_segment_baboon_ants_based.py ` .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_segment_baboon_ants_based.ipynb ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_