.. DO NOT EDIT.
.. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY.
.. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE:
.. "auto_examples/04_demos/viz_roi_contour.py"
.. LINE NUMBERS ARE GIVEN BELOW.

.. only:: html

    .. note::
        :class: sphx-glr-download-link-note

        :ref:`Go to the end <sphx_glr_download_auto_examples_04_demos_viz_roi_contour.py>`
        to download the full example code

.. rst-class:: sphx-glr-example-title

.. _sphx_glr_auto_examples_04_demos_viz_roi_contour.py:


======================================================
Visualization of ROI Surface Rendered with Streamlines
======================================================

Here is a simple tutorial following the probabilistic CSA Tracking Example in
which we generate a dataset of streamlines from a corpus callosum ROI, and
then display them with the seed ROI rendered in 3D with 50% transparency.

.. GENERATED FROM PYTHON SOURCE LINES 10-29

.. code-block:: Python


    from dipy.data import default_sphere, read_stanford_labels
    from dipy.direction import peaks_from_model
    from dipy.reconst.shm import CsaOdfModel

    try:
        from dipy.tracking.local import (
            LocalTracking,
            ThresholdTissueClassifier as ThresholdStoppingCriterion,
        )
    except ImportError:
        from dipy.tracking.local_tracking import LocalTracking
        from dipy.tracking.stopping_criterion import ThresholdStoppingCriterion

    from dipy.tracking import utils
    from dipy.tracking.streamline import Streamlines

    import fury








.. GENERATED FROM PYTHON SOURCE LINES 30-33

First, we need to generate some streamlines. For a more complete
description of these steps, please refer to the CSA Probabilistic Tracking
Tutorial.

.. GENERATED FROM PYTHON SOURCE LINES 33-62

.. code-block:: Python


    hardi_img, gtab, labels_img = read_stanford_labels()
    data = hardi_img.get_fdata()
    labels = labels_img.get_fdata()
    affine = hardi_img.affine

    white_matter = (labels == 1) | (labels == 2)

    csa_model = CsaOdfModel(gtab, sh_order_max=6)
    csa_peaks = peaks_from_model(
        csa_model,
        data,
        default_sphere,
        relative_peak_threshold=0.8,
        min_separation_angle=45,
        mask=white_matter,
    )

    classifier = ThresholdStoppingCriterion(csa_peaks.gfa, 0.25)

    seed_mask = labels == 2
    seeds = utils.seeds_from_mask(seed_mask, density=[1, 1, 1], affine=affine)

    # Initialization of LocalTracking. The computation happens in the next step.
    streamlines = LocalTracking(csa_peaks, classifier, seeds, affine, step_size=2)

    # Compute streamlines and store as a list.
    streamlines = Streamlines(streamlines)








.. GENERATED FROM PYTHON SOURCE LINES 63-64

We will create a streamline actor from the streamlines.

.. GENERATED FROM PYTHON SOURCE LINES 64-67

.. code-block:: Python


    streamlines_actor = fury.actor.line(streamlines, fury.colormap.line_colors(streamlines))





.. rst-class:: sphx-glr-script-out

 .. code-block:: none

    /opt/homebrew/Caskroom/miniforge/base/envs/py311-fury/lib/python3.11/site-packages/sphinx_gallery/gen_rst.py:722: UserWarning: We'll no longer accept the way you call the line function in future versions of FURY.

    Here's how to call the Function line: line(lines_value, colors='value', opacity='value', linewidth='value', spline_subdiv='value', lod='value', lod_points='value', lod_points_size='value', lookup_colormap='value', depth_cue='value', fake_tube='value')

      exec(self.code, self.fake_main.__dict__)




.. GENERATED FROM PYTHON SOURCE LINES 68-72

Next, we create a surface actor from the corpus callosum seed ROI. We
provide the ROI data, the affine, the color in [R,G,B], and the opacity as
a decimal between zero and one. Here, we set the color as blue/green with
50% opacity.

.. GENERATED FROM PYTHON SOURCE LINES 72-80

.. code-block:: Python


    surface_opacity = 0.5
    surface_color = [0, 1, 1]

    seedroi_actor = fury.actor.contour_from_roi(
        seed_mask, affine, surface_color, surface_opacity
    )





.. rst-class:: sphx-glr-script-out

 .. code-block:: none

    /opt/homebrew/Caskroom/miniforge/base/envs/py311-fury/lib/python3.11/site-packages/sphinx_gallery/gen_rst.py:722: UserWarning: We'll no longer accept the way you call the contour_from_roi function in future versions of FURY.

    Here's how to call the Function contour_from_roi: contour_from_roi(data_value, affine='value', color='value', opacity='value')

      exec(self.code, self.fake_main.__dict__)




.. GENERATED FROM PYTHON SOURCE LINES 81-83

Next, we initialize a ''Scene'' object and add both actors
to the rendering.

.. GENERATED FROM PYTHON SOURCE LINES 83-88

.. code-block:: Python


    scene = fury.window.Scene()
    scene.add(streamlines_actor)
    scene.add(seedroi_actor)








.. GENERATED FROM PYTHON SOURCE LINES 89-91

If you uncomment the following line, the rendering will pop up in an
interactive window.

.. GENERATED FROM PYTHON SOURCE LINES 91-100

.. code-block:: Python


    interactive = False
    if interactive:
        fury.window.show(scene)

    # scene.zoom(1.5)
    # scene.reset_clipping_range()

    fury.window.record(scene, out_path="contour_from_roi_tutorial.png", size=(600, 600))



.. image-sg:: /auto_examples/04_demos/images/sphx_glr_viz_roi_contour_001.png
   :alt: viz roi contour
   :srcset: /auto_examples/04_demos/images/sphx_glr_viz_roi_contour_001.png
   :class: sphx-glr-single-img


.. rst-class:: sphx-glr-script-out

 .. code-block:: none

    /opt/homebrew/Caskroom/miniforge/base/envs/py311-fury/lib/python3.11/site-packages/sphinx_gallery/gen_rst.py:722: UserWarning: We'll no longer accept the way you call the record function in future versions of FURY.

    Here's how to call the Function record: record(scene='value', cam_pos='value', cam_focal='value', cam_view='value', out_path='value', path_numbering='value', n_frames='value', az_ang='value', magnification='value', size='value', reset_camera='value', screen_clip='value', stereo='value', verbose='value')

      exec(self.code, self.fake_main.__dict__)





.. rst-class:: sphx-glr-timing

   **Total running time of the script:** (36 minutes 53.694 seconds)


.. _sphx_glr_download_auto_examples_04_demos_viz_roi_contour.py:

.. only:: html

  .. container:: sphx-glr-footer sphx-glr-footer-example

    .. container:: sphx-glr-download sphx-glr-download-jupyter

      :download:`Download Jupyter notebook: viz_roi_contour.ipynb <viz_roi_contour.ipynb>`

    .. container:: sphx-glr-download sphx-glr-download-python

      :download:`Download Python source code: viz_roi_contour.py <viz_roi_contour.py>`


.. only:: html

 .. rst-class:: sphx-glr-signature

    `Gallery generated by Sphinx-Gallery <https://sphinx-gallery.github.io>`_