Note
Go to the end to download the full example code.
Example of morphological distortion in slam¶
# Authors:
# Guillaume Auzias <guillaume.auzias@univ-amu.fr>
# Julien Barrès <julien.barres@etu.univ-amu.fr>
# License: MIT
# sphinx_gallery_thumbnail_number = 2
Importation of slam modules
import slam.distortion as sdst
import slam.differential_geometry as sdg
import slam.io as sio
import numpy as np
Loading an example mesh and a smoothed copy of it
mesh = sio.load_mesh("../examples/data/example_mesh.gii")
mesh_s = sdg.laplacian_mesh_smoothing(mesh, nb_iter=50, dt=0.1)
Smoothing mesh
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
0
10
20
30
40
OK
Computation of the angle difference between each faces of mesh and mesh_s
angle_diff = sdst.angle_difference(mesh, mesh_s)
angle_diff
array([[-0.18881895, 0.12117287, 0.06764609],
[ 0.05797368, 0.03686888, -0.09484256],
[ 0.07230468, 0.16239874, -0.23470342],
...,
[-0.08685515, 0.03678422, 0.05007093],
[ 0.0635167 , -0.10415994, 0.04064324],
[ 0.05023476, -0.0978278 , 0.04759305]], shape=(4652, 3))
face_angle_dist = np.sum(np.abs(angle_diff), 1)
face_angle_dist
array([0.3776379 , 0.18968511, 0.46940683, ..., 0.1737103 , 0.20831988,
0.19565561], shape=(4652,))
Computation of the area difference between each faces of mesh and mesh_s
area_diff = sdst.area_difference(mesh, mesh_s)
area_diff
array([0.42263817, 0.20383547, 0.26206739, ..., 0.08069364, 0.08235209,
0.18712064], shape=(4652,))
Computation of the length difference between each edges of mesh and mesh_s
edge_diff = sdst.edge_length_difference(mesh, mesh_s)
edge_diff
TrackedArray([0.2547129 , 0.23347774, 0.18442651, ..., 0.25986046,
0.1005251 , 0.08211042], shape=(6978,))
VISUALIZATION USING INTERNAL TOOLS¶
import slam.plot as splt
display_settings = {}
mesh_data = {}
mesh_data['vertices'] = mesh.vertices
mesh_data['faces'] = mesh.faces
mesh_data['title'] = 'Original Mesh'
intensity_data = None
fig1 = splt.plot_mesh(
mesh_data=mesh_data,
intensity_data=intensity_data,
display_settings=display_settings)
fig1.show()
fig1
# ############################################################################
# # Visualization of the smoothed mesh
display_settings = {}
mesh_data = {}
mesh_data['vertices'] = mesh_s.vertices
mesh_data['faces'] = mesh_s.faces
mesh_data['title'] = 'Smoothed Mesh'
intensity_data = None
fig2 = splt.plot_mesh(
mesh_data=mesh_data,
intensity_data=intensity_data,
display_settings=display_settings)
fig2.show()
Total running time of the script: (0 minutes 5.441 seconds)