Note
Go to the end to download the full example code.
Example of watershed in slamΒΆ
# Authors:
# Lucile Hashimoto lucile-hashimoto
# Guillaume Auzias <guillaume.auzias@univ-amu.fr>
# License: MIT
# sphinx_gallery_thumbnail_number = 2
- 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 
importation of slam modules
import slam.io as sio
import slam.watershed as swat
import slam.sulcal_graph as ssg
loading an examplar mesh and corresponding texture
path_to_mesh = "../examples/data/example_mesh.gii"
path_to_mask = None
path_to_output = ""
mesh = sio.load_mesh(path_to_mesh)
side = "left"
compute curvature, dpf and voronoi
_, dpf, voronoi = swat.compute_mesh_features(mesh, save=False, outdir=path_to_output, check_if_exist=True)
normalize watershed thresholds
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)
        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]
define the exclusion mask (cingular pole)
if path_to_mask is not None:
    mask = sio.load_texture(path_to_mask).darray[0]
else:
    mask = None
extract sulcal pits and associated basins
basins, ridges, adjacency = swat.watershed(mesh, voronoi, dpf, thresh_dist, thresh_ridge, thresh_area, mask)
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
generate the textures from watershed outputs
tex_labels, tex_pits, tex_ridges = swat.get_textures_from_dict(mesh, basins, ridges, save=True, outdir=path_to_output)
generate the sulcal graph
g = ssg.get_sulcal_graph(adjacency, basins, ridges, save=True, outdir=path_to_output)
{'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
generate the textures from graph
tex_labels, tex_pits, tex_ridges = ssg.get_textures_from_graph(g, mesh, save=True, outdir=path_to_output)
Total running time of the script: (0 minutes 0.273 seconds)