.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/volume_surface_rendering/plot_volumetric_mask_as_surface.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code .. rst-class:: sphx-glr-example-title .. _sphx_glr_auto_examples_volume_surface_rendering_plot_volumetric_mask_as_surface.py: ================ Rendering volumetric masks as surfaces ================ This is a quick demo showing how to plot a surface mesh generated from a volumetric mask. Here, we use the template MNI152 T1-weighted brain to create an arbitrary mask. First, let's load the basic required libraries .. GENERATED FROM PYTHON SOURCE LINES 13-17 .. code-block:: default import matplotlib.pyplot as plt from cerebro import cerebro_brain_utils as cbu from cerebro import cerebro_brain_viewer as cbv .. GENERATED FROM PYTHON SOURCE LINES 18-20 Plotting a surface from volumetric masks ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ .. GENERATED FROM PYTHON SOURCE LINES 20-45 .. code-block:: default # Define a viewer cerebro_viewer = cbv.Cerebro_brain_viewer(offscreen=True, background_color=(1,1,1,1)) # Load an example volumetric file nii_file = cbu.get_data_file(f"templates/MNI152/MNI152_T1_2mm_brain.nii.gz") # Create a 3D surface of the mask volumetric_mask = cerebro_viewer.visualize_mask_surface( nii_file, # The volumetric file 6000, # An arbitrary threshold to mask the data color=(0.9, 0.4, 0.5, 1), # Let's make the brain look pink! gradient_direction="ascent", # This defines the surface normal directions smoothing=400 # Iteratively smooth the surface to look better ) fig, ax = plt.subplots(figsize=(8,7)) plt.subplots_adjust(wspace=0, hspace=0) ax.axis('off') cerebro_viewer.offscreen_draw_to_matplotlib_axes(ax) # Clear this viewer cerebro_viewer.viewer.window.destroy() plt.show() .. image-sg:: /auto_examples/volume_surface_rendering/images/sphx_glr_plot_volumetric_mask_as_surface_001.png :alt: plot volumetric mask as surface :srcset: /auto_examples/volume_surface_rendering/images/sphx_glr_plot_volumetric_mask_as_surface_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-timing **Total running time of the script:** ( 0 minutes 10.731 seconds) .. _sphx_glr_download_auto_examples_volume_surface_rendering_plot_volumetric_mask_as_surface.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_volumetric_mask_as_surface.py ` .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_volumetric_mask_as_surface.ipynb ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_