.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/example_watershed.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_example_watershed.py: .. _example_watershed: =================================== Example of watershed in slam =================================== .. GENERATED FROM PYTHON SOURCE LINES 8-16 .. code-block:: Python # Authors: # Lucile Hashimoto lucile-hashimoto # Guillaume Auzias # License: MIT # sphinx_gallery_thumbnail_number = 2 .. GENERATED FROM PYTHON SOURCE LINES 17-21 NOTE: there is no visualization tool in slam, but we provide at the end of this script exemplare code to do the visualization with an external solution ############################################################################## .. GENERATED FROM PYTHON SOURCE LINES 23-24 importation of slam modules .. GENERATED FROM PYTHON SOURCE LINES 24-28 .. code-block:: Python import slam.io as sio import slam.watershed as swat import slam.sulcal_graph as ssg .. GENERATED FROM PYTHON SOURCE LINES 29-30 loading an examplar mesh and corresponding texture .. GENERATED FROM PYTHON SOURCE LINES 30-37 .. code-block:: Python path_to_mesh = "../examples/data/example_mesh.gii" path_to_mask = None path_to_output = "" mesh = sio.load_mesh(path_to_mesh) side = "left" .. GENERATED FROM PYTHON SOURCE LINES 38-39 compute curvature, dpf and voronoi .. GENERATED FROM PYTHON SOURCE LINES 39-41 .. code-block:: Python _, dpf, voronoi = swat.compute_mesh_features(mesh, save=False, outdir=path_to_output, check_if_exist=True) .. GENERATED FROM PYTHON SOURCE LINES 42-43 normalize watershed thresholds .. GENERATED FROM PYTHON SOURCE LINES 43-46 .. code-block:: Python thresh_dist, thresh_ridge, thresh_area = swat.normalize_thresholds(voronoi, thresh_dist=20.0, thresh_ridge=1.5, thresh_area=50.0, side=side) .. rst-class:: sphx-glr-script-out .. code-block:: none Computing the surface area .. GENERATED FROM PYTHON SOURCE LINES 47-48 define the exclusion mask (cingular pole) .. GENERATED FROM PYTHON SOURCE LINES 48-53 .. code-block:: Python if path_to_mask is not None: mask = sio.load_texture(path_to_mask).darray[0] else: mask = None .. GENERATED FROM PYTHON SOURCE LINES 54-55 extract sulcal pits and associated basins .. GENERATED FROM PYTHON SOURCE LINES 55-57 .. code-block:: Python basins, ridges, adjacency = swat.watershed(mesh, voronoi, dpf, thresh_dist, thresh_ridge, thresh_area, mask) .. rst-class:: sphx-glr-script-out .. code-block:: none Computing watershed by flooding... Distance between 2 pits: 5.3 mm - Ridge height: 1.5 mm Number of basins found: 27 nb of basins to remove: 0 .. GENERATED FROM PYTHON SOURCE LINES 58-59 generate the textures from watershed outputs .. GENERATED FROM PYTHON SOURCE LINES 59-61 .. code-block:: Python tex_labels, tex_pits, tex_ridges = swat.get_textures_from_dict(mesh, basins, ridges, save=True, outdir=path_to_output) .. GENERATED FROM PYTHON SOURCE LINES 62-63 generate the sulcal graph .. GENERATED FROM PYTHON SOURCE LINES 63-65 .. code-block:: Python g = ssg.get_sulcal_graph(adjacency, basins, ridges, save=True, outdir=path_to_output) .. rst-class:: sphx-glr-script-out .. code-block:: none Graph saved in graph.gpickle .. GENERATED FROM PYTHON SOURCE LINES 66-67 generate the textures from graph .. GENERATED FROM PYTHON SOURCE LINES 67-67 .. code-block:: Python tex_labels, tex_pits, tex_ridges = ssg.get_textures_from_graph(g, mesh, save=True, outdir=path_to_output) .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 2.761 seconds) .. _sphx_glr_download_auto_examples_example_watershed.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: example_watershed.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: example_watershed.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: example_watershed.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_