.. 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 = "" 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-49 .. code-block:: Python thresh_dist, thresh_ridge, thresh_area = swat.normalize_thresholds(mesh, 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 Fiedler geodesic length and surface area Computing Laplacian Computing mesh weights of type fem -edge length threshold needed for 0 values = 0.0 % -number of Nan in weights: 0 = 0.0 % -number of Negative values in weights: 936 = 6.706792777300086 % -nb Nan in Laplacian : 0 -nb Inf in Laplacian : 0 Fielder length [76.42611449] Distance threshold : [6.47816186] .. GENERATED FROM PYTHON SOURCE LINES 50-51 define the exclusion mask (cingular pole) .. GENERATED FROM PYTHON SOURCE LINES 51-56 .. code-block:: Python if path_to_mask: mask = sio.load_texture(path_to_mask).darray[0] else: mask = None .. GENERATED FROM PYTHON SOURCE LINES 57-58 extract sulcal pits and associated basins .. GENERATED FROM PYTHON SOURCE LINES 58-60 .. 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: [6.47816186] mm - Ridge height: 1.5 mm Number of basins found: 3 nb of basins to remove: 0 .. GENERATED FROM PYTHON SOURCE LINES 61-62 generate the textures from watershed outputs .. GENERATED FROM PYTHON SOURCE LINES 62-64 .. 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 65-66 generate the sulcal graph .. GENERATED FROM PYTHON SOURCE LINES 66-68 .. 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 {'ridge_index': np.int64(1456), 'ridge_depth': np.float32(-0.001474528), 'ridge_length': 105} {'ridge_index': np.int64(1582), 'ridge_depth': np.float32(0.017893096), 'ridge_length': 64} {'ridge_index': np.int64(1425), 'ridge_depth': np.float32(-0.0014448662), 'ridge_length': 105} {'ridge_index': np.int64(1852), 'ridge_depth': np.float32(-0.031923838), 'ridge_length': 39} {'ridge_index': np.int64(1624), 'ridge_depth': np.float32(0.018081363), 'ridge_length': 64} {'ridge_index': np.int64(1910), 'ridge_depth': np.float32(-0.031930108), 'ridge_length': 39} Edge 0 attributes: dict_keys(['weight']) Edge 1 attributes: dict_keys(['weight']) Edge 2 attributes: dict_keys(['weight']) Edge 0 attributes: dict_keys(['weight', 'ridge_index', 'ridge_depth', 'ridge_length']) Edge 1 attributes: dict_keys(['weight', 'ridge_index', 'ridge_depth', 'ridge_length']) Edge 2 attributes: dict_keys(['weight', 'ridge_index', 'ridge_depth', 'ridge_length']) Graph saved in graph.gpickle .. GENERATED FROM PYTHON SOURCE LINES 69-70 generate the textures from graph .. GENERATED FROM PYTHON SOURCE LINES 70-70 .. 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 0.290 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 `_