diff --git a/examples/example_basics.py b/examples/example_basics.py index 2d89a68..538bc11 100755 --- a/examples/example_basics.py +++ b/examples/example_basics.py @@ -161,5 +161,3 @@ mesh.bounding_cylinder.volume, mesh.bounding_sphere.volume, ) - - diff --git a/examples/example_curvature.py b/examples/example_curvature.py index 1e99588..e1edf9c 100644 --- a/examples/example_curvature.py +++ b/examples/example_curvature.py @@ -146,9 +146,11 @@ ) angular_error_1 = 180 * angular_error_1 / np.pi + ############################################################################# -# VISUALIZATION USING EXTERNAL TOOLS +# VISUALIZATION USING INTERNAL TOOLS ############################################################################# + import slam.plot as splt vertices = mesh.vertices @@ -161,10 +163,12 @@ [0, np.cos(theta), -np.sin(theta)], [0, np.sin(theta), np.cos(theta)]]) vertices_translate = np.dot(rot_x, vertices_translate.T).T -rot_z = np.array([[np.cos(theta), -np.sin(theta),0], - [np.sin(theta), np.cos(theta),0], - [0, 0, 1],]) +rot_z = np.array([[np.cos(theta), -np.sin(theta), 0], + [np.sin(theta), np.cos(theta), 0], + [0, 0, 1], ]) vertices_translate = np.dot(rot_z, vertices_translate.T).T + +# Plot Mean Curvature display_settings = {} display_settings['colorbar_label'] = 'Mean Curvature' mesh_data = {} @@ -174,70 +178,76 @@ intensity_data = {} intensity_data['values'] = mean_curv intensity_data["mode"] = "vertex" -Fig = splt.mes3d_projection( +Fig = splt.mesh_projection( mesh_data=mesh_data, intensity_data=intensity_data, display_settings=display_settings) -#Fig.show() +# Fig.show() Fig.write_image("example_curvature_1.png") +# Plot Gaussian Curvature mesh_data['title'] = 'example_mesh.gii Gaussian Curvature' intensity_data['values'] = gaussian_curv display_settings['colorbar_label'] = 'Gaussian Curvature' -Fig = splt.mes3d_projection( +Fig = splt.mesh_projection( mesh_data=mesh_data, intensity_data=intensity_data, display_settings=display_settings) -#Fig.show() +# Fig.show() Fig.write_image("example_curvature_2.png") +# Plot Shape Index mesh_data['title'] = 'example_mesh.gii Shape Index' intensity_data['values'] = shapeIndex display_settings['colorbar_label'] = 'Shape Index' -Fig = splt.mes3d_projection( +Fig = splt.mesh_projection( mesh_data=mesh_data, intensity_data=intensity_data, display_settings=display_settings) -#Fig.show() +# Fig.show() Fig.write_image("example_curvature_3.png") +# Plot Curvedness mesh_data['title'] = 'example_mesh.gii Curvedness' intensity_data['values'] = curvedness display_settings['colorbar_label'] = 'Curvedness' -Fig = splt.mes3d_projection( +Fig = splt.mesh_projection( mesh_data=mesh_data, intensity_data=intensity_data, display_settings=display_settings) -#Fig.show() +# Fig.show() Fig.write_image("example_curvature_4.png") +# Plot Quadric K Mean Absolute Change mesh_data['vertices'] = quadric.vertices mesh_data['faces'] = quadric.faces mesh_data['title'] = 'Quadric K Mean Absolute Change' intensity_data['values'] = k_mean_absolute_change display_settings['colorbar_label'] = 'K Mean Absolute Change' -Fig = splt.mes3d_projection( +Fig = splt.mesh_projection( mesh_data=mesh_data, intensity_data=intensity_data, display_settings=display_settings) -#Fig.show() +# Fig.show() Fig.write_image("example_curvature_5.png") +# Plot Quadric Angular Error 0 mesh_data['title'] = 'Quadric Angular Error 0' intensity_data['values'] = angular_error_0 display_settings['colorbar_label'] = 'Angular Error 0' -Fig = splt.mes3d_projection( +Fig = splt.mesh_projection( mesh_data=mesh_data, intensity_data=intensity_data, display_settings=display_settings) Fig.write_image("example_curvature_6.png") -mesh_data['title'] = ('Quadric Angular Error 1') +# Plot Quadric Angular Error 1 +mesh_data['title'] = 'Quadric Angular Error 1' intensity_data['values'] = angular_error_1 display_settings['colorbar_label'] = 'Angular Error 1' -Fig = splt.mes3d_projection( +Fig = splt.mesh_projection( mesh_data=mesh_data, intensity_data=intensity_data, display_settings=display_settings) -#Fig.show() +# Fig.show() Fig.write_image("example_curvature_7.png") diff --git a/examples/example_differential_geometry.py b/examples/example_differential_geometry.py index e09e60b..58308d1 100644 --- a/examples/example_differential_geometry.py +++ b/examples/example_differential_geometry.py @@ -21,7 +21,7 @@ # importation of slam modules import slam.io as sio import slam.differential_geometry as sdg - +import numpy as np ############################################################################### # loading an examplar mesh and corresponding texture mesh_file = "../examples/data/example_mesh.gii" @@ -52,37 +52,56 @@ print(norm_grad) ############################################################################# -# VISUALIZATION USING EXTERNAL TOOLS +# VISUALIZATION USING INTERNAL TOOLS ############################################################################# -# # import visbrain # visu using visbrain -# visb_sc = splt.visbrain_plot( -# mesh=mesh, -# tex=tex.darray[0], -# caption="mesh with curvature", cblabel="curvature" -# ) -# visb_sc.preview() -# ############################################################################### -# # show the smoothed mesh -# visb_sc = splt.visbrain_plot( -# mesh=s_mesh, -# caption="smoothed mesh" -# ) -# visb_sc.preview() -# ############################################################################### -# # show the norm of the gradient of the curvature -# visb_sc = splt.visbrain_plot( -# mesh=mesh, -# tex=norm_grad, -# caption="norm of the gradient of curvature", -# cblabel="gradient magnitude", -# ) -# visb_sc.preview() -# ############################################################################### -# # show the depth potential function -# visb_sc = splt.visbrain_plot( -# mesh=mesh, -# tex=dpf[0], -# caption="depth potential function", -# cblabel="dpf" -# ) -# visb_sc.preview() + +import slam.plot as splt + +vertices = mesh.vertices +# center the vertices +vertices = vertices - np.mean(vertices, axis=0) +vertices_translate = np.copy(vertices) +# rotate the vertices +theta = np.pi / 2 +rot_x = np.array([[1, 0, 0], + [0, np.cos(theta), -np.sin(theta)], + [0, np.sin(theta), np.cos(theta)]]) +vertices_translate = np.dot(rot_x, vertices_translate.T).T +rot_z = np.array([[np.cos(theta), -np.sin(theta), 0], + [np.sin(theta), np.cos(theta), 0], + [0, 0, 1], ]) +vertices_translate = np.dot(rot_z, vertices_translate.T).T + +# Plot Original Mesh +display_settings = {} +display_settings['colorbar_label'] = 'Curvature' +mesh_data = {} +mesh_data['vertices'] = vertices_translate +mesh_data['faces'] = mesh.faces +mesh_data['title'] = 'example_mesh.gii Mean Curvature' +intensity_data = {} +intensity_data['values'] = tex.darray[0] +intensity_data["mode"] = "vertex" +Fig = splt.mesh_projection( + mesh_data=mesh_data, + intensity_data=intensity_data, + display_settings=display_settings) +# Fig.show() +Fig.write_image("example_differential_geometry_1.png") + +# Show the Norm of the Gradient of the Curvature +display_settings = {} +display_settings['colorbar_label'] = 'Gradient Magnitude' +mesh_data = {} +mesh_data['vertices'] = vertices_translate +mesh_data['faces'] = mesh.faces +mesh_data['title'] = 'example_mesh.gii Norm of the Gradient of Curvature' +intensity_data = {} +intensity_data['values'] = norm_grad +intensity_data["mode"] = "vertex" +Fig = splt.mesh_projection( + mesh_data=mesh_data, + intensity_data=intensity_data, + display_settings=display_settings) +# Fig.show() +Fig.write_image("example_differential_geometry_2.png") diff --git a/examples/example_distortion.py b/examples/example_distortion.py index 02077f4..ff9a5c6 100644 --- a/examples/example_distortion.py +++ b/examples/example_distortion.py @@ -52,13 +52,61 @@ edge_diff = sdst.edge_length_difference(mesh, mesh_s) edge_diff + ############################################################################# -# VISUALIZATION USING EXTERNAL TOOLS +# VISUALIZATION USING INTERNAL TOOLS ############################################################################# + +import slam.plot as splt + # # Visualization of the original mesh -# visb_sc = splt.visbrain_plot(mesh=mesh, caption="original mesh") -# visb_sc.preview() +vertices = mesh.vertices +# center the vertices +vertices = vertices - np.mean(vertices, axis=0) +vertices_translate = np.copy(vertices) +# rotate the vertices +theta = np.pi / 2 +rot_x = np.array([[1, 0, 0], + [0, np.cos(theta), -np.sin(theta)], + [0, np.sin(theta), np.cos(theta)]]) +vertices_translate = np.dot(rot_x, vertices_translate.T).T +rot_z = np.array([[np.cos(theta), -np.sin(theta), 0], + [np.sin(theta), np.cos(theta), 0], + [0, 0, 1],]) +vertices_translate = np.dot(rot_z, vertices_translate.T).T +display_settings = {} +mesh_data = {} +mesh_data['vertices'] = vertices_translate +mesh_data['faces'] = mesh.faces +mesh_data['title'] = 'example_mesh.gii Original Mesh' +intensity_data = None +Fig = splt.mesh_projection( + mesh_data=mesh_data, + intensity_data=intensity_data, + display_settings=display_settings) +# Fig.show() +Fig.write_image("example_distortion_1.png") + # ############################################################################ # # Visualization of the smoothed mesh -# visb_sc = splt.visbrain_plot(mesh=mesh_s, caption="smoothed mesh") -# visb_sc.preview() + +vertices = mesh_s.vertices +# center the vertices +vertices = vertices - np.mean(vertices, axis=0) +vertices_translate = np.copy(vertices) +# rotate the vertices +vertices_translate = np.dot(rot_x, vertices_translate.T).T +vertices_translate = np.dot(rot_z, vertices_translate.T).T + +display_settings = {} +mesh_data = {} +mesh_data['vertices'] = vertices_translate +mesh_data['faces'] = mesh_s.faces +mesh_data['title'] = 'example_mesh.gii Smoothed Mesh' +intensity_data = None +Fig = splt.mesh_projection( + mesh_data=mesh_data, + intensity_data=intensity_data, + display_settings=display_settings) +# Fig.show() +Fig.write_image("example_distortion_2.png") diff --git a/examples/example_dpf_Boucher.py b/examples/example_dpf_Boucher.py index 141bd26..d2555a3 100644 --- a/examples/example_dpf_Boucher.py +++ b/examples/example_dpf_Boucher.py @@ -20,7 +20,6 @@ ############################################################################### # Import of modules -import slam.curvature as sc import slam.sulcal_depth as sdepth import trimesh import numpy as np @@ -80,17 +79,17 @@ def boucher_surface(params, ax, ay, nstep): ################################## # Compute dpf for various alpha + alphas = [0.001, 0.01, 0.1, 1, 10, 100] -dpfs = sdepth.depth_potential_function( - mesh, alphas=alphas) +various_dpfs = sdepth.depth_potential_function(mesh, alphas=alphas) amplitude_center = [] amplitude_peak = [] index_peak_pos = np.argmax(mesh.vertices[:, 2]) index_peak_neg = np.argmin(mesh.vertices[:, 2]) -for i in range(len(dpfs)): - amplitude_center.append(dpfs[i][index_peak_neg]) - amplitude_peak.append(dpfs[i][index_peak_pos]) +for i in range(len(various_dpfs)): + amplitude_center.append(various_dpfs[i][index_peak_neg]) + amplitude_peak.append(various_dpfs[i][index_peak_pos]) #################################### # Fix alpha and vary M = params[0] @@ -104,47 +103,53 @@ def boucher_surface(params, ax, ay, nstep): all_amplitudes.append(dpfs[0][len(mesh.vertices) // 2]) ############################################################################# -# VISUALIZATION USING EXTERNAL TOOLS +# VISUALIZATION USING INTERNAL TOOLS ############################################################################# -# import visbrain # visu using visbrain -# import slam.plot as splt -# import matplotlib.pyplot as plt -########################################################################## -# # Visualization of the mesh -# visb_sc = splt.visbrain_plot( -# mesh=mesh, -# caption="Boucher mesh", -# bgcolor=[ -# 0.3, -# 0.5, -# 0.7]) -# visb_sc -# visb_sc.preview() -############################################################################### -# plt.figure() -# plt.semilogx(alphas, amplitude_center) -# plt.semilogx(alphas, amplitude_peak) -# plt.semilogx(alphas, len(alphas) * -# [params[0] * (1 + 2 * np.exp(-3 / 2))], "--") -# plt.xlabel("alpha") -# plt.ylabel("amplitude") -# plt.legend(["DPF at center", "DPF (secondary peaks)", "True amplitude"]) -# plt.show() -# -###################################### -# # Display dpfs on the surfaces -# -# visb_sc = splt.visbrain_plot( -# mesh=mesh, tex=dpfs[0], caption="Boucher mesh", bgcolor="white" -# ) -# visb_sc = splt.visbrain_plot( -# mesh=mesh, tex=dpfs[5], caption="Boucher mesh", visb_sc=visb_sc -# ) -# visb_sc.preview() -# -############################################################################## -# plt.figure() -# plt.plot(all_M, all_amplitudes, "+-") -# plt.xlabel("M") -# plt.ylabel("Amplitude of DPF") -# plt.show() + +import slam.plot as splt + +vertices = mesh.vertices +# center the vertices +vertices = vertices - np.mean(vertices, axis=0) +vertices_translate = np.copy(vertices) +# rotate the vertices +theta = np.pi / 2 +rot_x = np.array([[1, 0, 0], + [0, np.cos(theta), -np.sin(theta)], + [0, np.sin(theta), np.cos(theta)]]) +vertices_translate = np.dot(rot_x, vertices_translate.T).T +rot_z = np.array([[np.cos(theta), -np.sin(theta), 0], + [np.sin(theta), np.cos(theta), 0], + [0, 0, 1],]) +vertices_translate = np.dot(rot_z, vertices_translate.T).T + +display_settings = {} +mesh_data = {} +mesh_data['vertices'] = vertices_translate +mesh_data['faces'] = mesh.faces +mesh_data['title'] = 'Boucher mesh alpha 0.001' +intensity_data = {} +intensity_data['values'] = various_dpfs[0] +intensity_data["mode"] = "vertex" +Fig = splt.mesh_projection( + mesh_data=mesh_data, + intensity_data=intensity_data, + display_settings=display_settings) +# Fig.show() +Fig.write_image("example_dpf_Boucher_1.png") + + +display_settings = {} +mesh_data = {} +mesh_data['vertices'] = vertices_translate +mesh_data['faces'] = mesh.faces +mesh_data['title'] = 'Boucher mesh alpha 100' +intensity_data = {} +intensity_data['values'] = various_dpfs[5] +intensity_data["mode"] = "vertex" +Fig = splt.mesh_projection( + mesh_data=mesh_data, + intensity_data=intensity_data, + display_settings=display_settings) +# Fig.show() +Fig.write_image("example_dpf_Boucher_2.png") diff --git a/examples/example_generate_parametric_surfaces.py b/examples/example_generate_parametric_surfaces.py index 0f12d7e..bf0a7f3 100644 --- a/examples/example_generate_parametric_surfaces.py +++ b/examples/example_generate_parametric_surfaces.py @@ -74,21 +74,102 @@ ) ############################################################################# -# VISUALIZATION USING EXTERNAL TOOLS +# VISUALIZATION USING INTERNAL TOOLS ############################################################################# -# # import visbrain # visu using visbrain -# # show the quadric with its mean curvature -# visb_sc = splt.visbrain_plot( -# mesh=quadric, -# tex=quadric_mean_curv, -# caption="quadric", -# cblabel="mean curvature" -# ) -# # show the ellipsoid -# visb_sc = splt.visbrain_plot(mesh=ellips, caption="ellipsoid") + +import slam.plot as splt + +vertices = quadric.vertices +# center the vertices +vertices = vertices - np.mean(vertices, axis=0) +vertices_translate = np.copy(vertices) +# rotate the vertices +theta = np.pi / 2 +rot_x = np.array([[1, 0, 0], + [0, np.cos(theta), -np.sin(theta)], + [0, np.sin(theta), np.cos(theta)]]) +vertices_translate = np.dot(rot_x, vertices_translate.T).T +rot_z = np.array([[np.cos(theta), -np.sin(theta), 0], + [np.sin(theta), np.cos(theta), 0], + [0, 0, 1], ]) +vertices_translate = np.dot(rot_z, vertices_translate.T).T + +# Plot Mean Curvature +display_settings = {} +display_settings['colorbar_label'] = 'Curvature' +mesh_data = {} +mesh_data['vertices'] = vertices_translate +mesh_data['faces'] = quadric.faces +mesh_data['title'] = 'Mean Curvature' +intensity_data = {} +intensity_data['values'] = quadric_mean_curv +intensity_data["mode"] = "vertex" +Fig = splt.mesh_projection( + mesh_data=mesh_data, + intensity_data=intensity_data, + display_settings=display_settings) +# Fig.show() +Fig.write_image("example_generate_parametric_surfaces_1.png") +# show the ellipsoid +vertices = ellips.vertices +vertices = vertices - np.mean(vertices, axis=0) +vertices_translate = np.copy(vertices) +vertices_translate = np.dot(rot_x, vertices_translate.T).T +vertices_translate = np.dot(rot_z, vertices_translate.T).T +display_settings = {} +intensity_data = None +mesh_data = {} +mesh_data['vertices'] = vertices_translate +mesh_data['faces'] = ellips.faces +mesh_data['title'] = 'Ellips Mesh' +Fig = splt.mesh_projection( + mesh_data=mesh_data, + intensity_data=intensity_data, + display_settings=display_settings) +# Fig.show() +Fig.write_image("example_generate_parametric_surfaces_2.png") + +# show the sphere with regular sampling +vertices = sphere_regular.vertices +vertices = vertices - np.mean(vertices, axis=0) +vertices_translate = np.copy(vertices) +vertices_translate = np.dot(rot_x, vertices_translate.T).T +vertices_translate = np.dot(rot_z, vertices_translate.T).T +display_settings = {} +intensity_data = None +display_settings['colorbar_label'] = 'Curvature' +mesh_data = {} +mesh_data['vertices'] = vertices_translate +mesh_data['faces'] = sphere_regular.faces +mesh_data['title'] = 'Sphere Regular Mesh' +Fig = splt.mesh_projection( + mesh_data=mesh_data, + intensity_data=intensity_data, + display_settings=display_settings) +# Fig.show() +Fig.write_image("example_generate_parametric_surfaces_3.png") + + # # show the sphere with regular sampling -# visb_sc = splt.visbrain_plot(mesh=sphere_regular, caption="sphere_regular") -# # show the sphere with random sampling +vertices = sphere_random.vertices +vertices = vertices - np.mean(vertices, axis=0) +vertices_translate = np.copy(vertices) +vertices_translate = np.dot(rot_x, vertices_translate.T).T +vertices_translate = np.dot(rot_z, vertices_translate.T).T +display_settings = {} +intensity_data = None +mesh_data = {} +mesh_data['vertices'] = vertices_translate +mesh_data['faces'] = sphere_random.faces +mesh_data['title'] = 'Sphere Random Mesh' +Fig = splt.mesh_projection( + mesh_data=mesh_data, + intensity_data=intensity_data, + display_settings=display_settings) +# Fig.show() +Fig.write_image("example_generate_parametric_surfaces_4.png") + + # visb_sc = splt.visbrain_plot( # mesh=sphere_random, caption="sphere_random", visb_sc=visb_sc # ) diff --git a/examples/example_geodesic.py b/examples/example_geodesic.py index ca13459..7d624e0 100644 --- a/examples/example_geodesic.py +++ b/examples/example_geodesic.py @@ -59,25 +59,50 @@ print(path) ############################################################################# -# VISUALIZATION USING EXTERNAL TOOLS +# VISUALIZATION USING INTERNAL TOOLS ############################################################################# -# # Visualization with visbrain -# # show the geodesic distance -# visb_sc = splt.visbrain_plot( -# mesh=mesh, -# tex=geo_distance, -# caption="geodesic distance", -# cblabel="distance" -# ) -# visb_sc.preview() -# # show the geodesic distance locally -# visb_sc2 = splt.visbrain_plot( -# mesh=mesh, -# tex=area_geodist[0].toarray().squeeze(), -# caption="local geodesic distance", -# cblabel="distance", -# ) -# visb_sc2.preview() + +import slam.plot as splt + +mesh.apply_transform(mesh.principal_inertia_transform) +theta = np.pi / 2 +rot_x = np.array([[1, 0, 0], + [0, np.cos(theta), -np.sin(theta)], + [0, np.sin(theta), np.cos(theta)]]) +vertices_translate = np.dot(rot_x, mesh.vertices.T).T + +display_settings = {} +display_settings['colorbar_label'] = 'Distance' +mesh_data = {} +mesh_data['vertices'] = vertices_translate +mesh_data['faces'] = mesh.faces +mesh_data['title'] = 'Geodesic Distance' +intensity_data = {} +intensity_data['values'] = geo_distance +intensity_data["mode"] = "vertex" +Fig = splt.mesh_projection( + mesh_data=mesh_data, + intensity_data=intensity_data, + display_settings=display_settings) +# Fig.show() +Fig.write_image("example_geodesic_1.png") + + +display_settings = {} +display_settings['colorbar_label'] = 'Distance' +mesh_data = {} +mesh_data['vertices'] = vertices_translate +mesh_data['faces'] = mesh.faces +mesh_data['title'] = 'Local Geodesic Distance' +intensity_data = {} +intensity_data['values'] = area_geodist[0].toarray().squeeze() +intensity_data["mode"] = "vertex" +Fig = splt.mesh_projection( + mesh_data=mesh_data, + intensity_data=intensity_data, + display_settings=display_settings) +Fig.show() +# Fig.write_image("example_geodesic_2.png") ############################################################################### # # Visualization using pyglet @@ -89,11 +114,11 @@ # # path_visual = trimesh.load_path(mesh.vertices[path]) # path_visual -# -# ############################################################################### -# # Visualizable two points + +############################################################################### +# Visualizable two points # points_visual = trimesh.points.PointCloud(mesh.vertices[[start, end]]) -# + # ############################################################################### # # Create a scene with the mesh, path, and points # diff --git a/examples/example_hinge_gyri.py b/examples/example_hinge_gyri.py index 08ec90d..acee3a2 100644 --- a/examples/example_hinge_gyri.py +++ b/examples/example_hinge_gyri.py @@ -21,6 +21,7 @@ # importation of slam modules import slam.curvature as scurv import slam.generate_parametric_surfaces as sgps +import numpy as np ############################################################################### # Creating an examplar 3-4-...n hinge mesh @@ -29,13 +30,30 @@ mean_curvature = 1 / 2 * mesh_curvatures[0].sum(axis=0) ############################################################################# -# VISUALIZATION USING EXTERNAL TOOLS +# VISUALIZATION USING INTERNAL TOOLS # ############################################################################# -# # Visualization with visbrain -# visb_sc = splt.visbrain_plot( -# mesh=hinge_mesh, -# tex=mean_curvature, -# caption="hinge", -# cblabel="mean curvature" -# ) -# visb_sc.preview() + +import slam.plot as splt + +hinge_mesh.apply_transform(hinge_mesh.principal_inertia_transform) +theta = np.pi / 2 +rot_x = np.array([[1, 0, 0], + [0, np.cos(theta), -np.sin(theta)], + [0, np.sin(theta), np.cos(theta)]]) +vertices_translate = np.dot(rot_x, hinge_mesh.vertices.T).T + +display_settings = {} +display_settings['colorbar_label'] = 'Mean Curvature' +mesh_data = {} +mesh_data['vertices'] = vertices_translate +mesh_data['faces'] = hinge_mesh.faces +mesh_data['title'] = 'Hinge' +intensity_data = {} +intensity_data['values'] = mean_curvature +intensity_data["mode"] = "vertex" +Fig = splt.mesh_projection( + mesh_data=mesh_data, + intensity_data=intensity_data, + display_settings=display_settings) +# Fig.show() +Fig.write_image("example_hinge_gyri_1.png") diff --git a/examples/example_registration.py b/examples/example_registration.py index 851fb20..7613ea6 100644 --- a/examples/example_registration.py +++ b/examples/example_registration.py @@ -11,17 +11,11 @@ # 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 trimesh - +import numpy as np ############################################################################### # loading an two unregistered meshes mesh_1 = sio.load_mesh("../examples/data/example_mesh.gii") @@ -36,29 +30,59 @@ print(transf_mat) print(cost) +############################################################################# +# VISUALIZATION USING INTERNAL TOOLS +############################################################################# + +# # plot them to check the misalignment +joint_mesh = mesh_1 + mesh_2 +joint_tex = np.ones((joint_mesh.vertices.shape[0],)) +joint_tex[: mesh_1.vertices.shape[0]] = 10 + +import slam.plot as splt + +joint_mesh.apply_transform(joint_mesh.principal_inertia_transform) +theta = np.pi / 2 +rot_x = np.array([[1, 0, 0], + [0, np.cos(theta), -np.sin(theta)], + [0, np.sin(theta), np.cos(theta)]]) +vertices_translate = np.dot(rot_x, joint_mesh.vertices.T).T + +display_settings = {} +mesh_data = {} +mesh_data['vertices'] = vertices_translate +mesh_data['faces'] = joint_mesh.faces +mesh_data['title'] = 'Before Registration' +intensity_data = {} +intensity_data['values'] = joint_tex +intensity_data["mode"] = "vertex" +Fig = splt.mesh_projection( + mesh_data=mesh_data, + intensity_data=intensity_data, + display_settings=display_settings) +# Fig.show() +Fig.write_image("example_registration_1.png") + ############################################################################### # apply the estimated rigid transformation to the mesh mesh_1.apply_transform(transf_mat) +joint_mesh = mesh_1 + mesh_2 +joint_tex = np.ones((joint_mesh.vertices.shape[0],)) +joint_tex[: mesh_1.vertices.shape[0]] = 10 +joint_mesh.apply_transform(joint_mesh.principal_inertia_transform) +vertices_translate = np.dot(rot_x, joint_mesh.vertices.T).T -############################################################################# -# VISUALIZATION USING EXTERNAL TOOLS -############################################################################# -# # Visualization with visbrain -# import slam.plot as splt -# import numpy as np -# ############################################################################### -# # plot them to check the misalignment -# joint_mesh = mesh_1 + mesh_2 -# joint_tex = np.ones((joint_mesh.vertices.shape[0],)) -# joint_tex[: mesh_1.vertices.shape[0]] = 10 -# visb_sc = splt.visbrain_plot( -# mesh=joint_mesh, tex=joint_tex, caption="before registration" -# ) -# visb_sc.preview() -# ############################################################################### -# # plot the two meshes to check they are now aligned -# joint_mesh = mesh_1 + mesh_2 -# visb_sc = splt.visbrain_plot( -# mesh=joint_mesh, tex=joint_tex, caption="after registration" -# ) -# visb_sc.preview() +display_settings = {} +mesh_data = {} +mesh_data['vertices'] = vertices_translate +mesh_data['faces'] = joint_mesh.faces +mesh_data['title'] = 'After Registration' +intensity_data = {} +intensity_data['values'] = joint_tex +intensity_data["mode"] = "vertex" +Fig = splt.mesh_projection( + mesh_data=mesh_data, + intensity_data=intensity_data, + display_settings=display_settings) +# Fig.show() +Fig.write_image("example_registration_2.png") diff --git a/examples/example_remeshing.py b/examples/example_remeshing.py index 92fab96..8f1e6cc 100644 --- a/examples/example_remeshing.py +++ b/examples/example_remeshing.py @@ -23,7 +23,7 @@ # Importation of slam modules import slam.io as sio import slam.remeshing as srem - +import numpy as np ############################################################################### # Source object files source_mesh_file = "../examples/data/example_mesh.gii" @@ -47,29 +47,82 @@ ) ############################################################################# -# VISUALIZATION USING EXTERNAL TOOLS +# VISUALIZATION USING INTERNAL TOOLS ############################################################################# + +import slam.plot as splt + +source_mesh.apply_transform(source_mesh.principal_inertia_transform) +theta = np.pi / 2 +rot_x = np.array([[1, 0, 0], + [0, np.cos(theta), -np.sin(theta)], + [0, np.sin(theta), np.cos(theta)]]) +vertices_translate = np.dot(rot_x, source_mesh.vertices.T).T + +# Plot Mean Curvature +display_settings = {} +mesh_data = {} +mesh_data['vertices'] = vertices_translate +mesh_data['faces'] = source_mesh.faces +mesh_data['title'] = 'Source' +intensity_data = {} +intensity_data['values'] = source_tex.darray[0], +intensity_data["mode"] = "vertex" +Fig = splt.mesh_projection( + mesh_data=mesh_data, + intensity_data=intensity_data, + display_settings=display_settings) +# Fig.show() +Fig.write_image("example_distorsion_1.png") + + # # Visualization with visbrain # import slam.plot as splt # ############################################################################### -# visb_sc = splt.visbrain_plot( -# mesh=source_mesh, -# tex=source_tex.darray[0], -# caption="source with curvature", -# cblabel="curvature", -# ) -# visb_sc = splt.visbrain_plot( -# mesh=source_spherical_mesh, -# tex=source_tex.darray[0], -# caption="spherical source mesh", -# cblabel="curvature", -# visb_sc=visb_sc, -# ) -# visb_sc = splt.visbrain_plot( -# mesh=target_mesh, -# tex=interpolated_tex_values, -# caption="target mesh with curvature " "from source mesh", -# cblabel="curvature", -# visb_sc=visb_sc, -# ) -# visb_sc.preview() + +source_spherical_mesh.apply_transform( + source_spherical_mesh.principal_inertia_transform) +theta = np.pi / 2 +rot_x = np.array([[1, 0, 0], + [0, np.cos(theta), -np.sin(theta)], + [0, np.sin(theta), np.cos(theta)]]) +vertices_translate = np.dot(rot_x, source_spherical_mesh.vertices.T).T + +# Plot Mean Curvature +display_settings = {} +mesh_data = {} +mesh_data['vertices'] = vertices_translate +mesh_data['faces'] = source_spherical_mesh.faces +mesh_data['title'] = 'Spherical Source' +intensity_data = {} +intensity_data['values'] = source_tex.darray[0], +intensity_data["mode"] = "vertex" +Fig = splt.mesh_projection( + mesh_data=mesh_data, + intensity_data=intensity_data, + display_settings=display_settings) +# Fig.show() +Fig.write_image("example_remeshing_1.png") + +target_mesh.apply_transform(target_mesh.principal_inertia_transform) +theta = np.pi / 2 +rot_x = np.array([[1, 0, 0], + [0, np.cos(theta), -np.sin(theta)], + [0, np.sin(theta), np.cos(theta)]]) +vertices_translate = np.dot(rot_x, target_mesh.vertices.T).T + +# Plot Mean Curvature +display_settings = {} +mesh_data = {} +mesh_data['vertices'] = vertices_translate +mesh_data['faces'] = target_mesh.faces +mesh_data['title'] = 'target mesh from source mesh' +intensity_data = {} +intensity_data['values'] = interpolated_tex_values, +intensity_data["mode"] = "vertex" +Fig = splt.mesh_projection( + mesh_data=mesh_data, + intensity_data=intensity_data, + display_settings=display_settings) +# Fig.show() +Fig.write_image("example_remeshing_2.png") diff --git a/examples/example_spangy.py b/examples/example_spangy.py index a9df385..85c46fc 100644 --- a/examples/example_spangy.py +++ b/examples/example_spangy.py @@ -83,7 +83,7 @@ eigVects) -# WHOLE BRAIN MEAN-CURVATURE<=0 & MEAN-CURVATURE>0 SPECTRI +# WHOLE BRAIN MEAN-CURVATURE<=0 & MEAN-CURVATURE>0 SPECTRE # -------------------------------------------------------- # Define negative mean curvature subsignal mean_curv_sulci = np.zeros((mean_curv.shape)) @@ -98,22 +98,36 @@ = spgy.spectrum(mean_curv_gyri, lap_b, eigVects, eigVal) ############################################################################# -# VISUALIZATION USING EXTERNAL TOOLS +# VISUALIZATION USING INTERNAL TOOLS ############################################################################# -# import slam.plot as splt -# import matplotlib.pyplot as plt -# from matplotlib.colors import ListedColormap -# import pyvista as pv -# -# ############################################################################### -# # Plot of mean curvature on the mesh -# visb_sc = splt.visbrain_plot( -# mesh=mesh, -# tex=mean_curv, -# caption='Mean Curvature', -# cmap='jet') -# visb_sc.preview() -# + + +import slam.plot as splt + +mesh.apply_transform(mesh.principal_inertia_transform) +theta = np.pi / 2 +rot_x = np.array([[1, 0, 0], + [0, np.cos(theta), -np.sin(theta)], + [0, np.sin(theta), np.cos(theta)]]) +vertices_translate = np.dot(rot_x, mesh.vertices.T).T + +display_settings = {} +mesh_data = {} +mesh_data['vertices'] = vertices_translate +mesh_data['faces'] = mesh.faces +mesh_data['title'] = 'Mean Curvature' +intensity_data = {} +intensity_data['values'] = mean_curv +intensity_data["mode"] = "vertex" +Fig = splt.mesh_projection( + mesh_data=mesh_data, + intensity_data=intensity_data, + display_settings=display_settings) +# Fig.show() +Fig.write_image("example_spangy_1.png") + + + # # Plot coefficients and bands for all mean curvature signal # fig, (ax1, ax2) = plt.subplots(1, 2) # ax1.scatter(np.sqrt(eigVal/2*np.pi), @@ -132,11 +146,22 @@ # ax2.set_ylabel('Power Spectrum') # plt.show() # -# # Plot of spectral dominant bands on the mesh -# visb_sc = splt.visbrain_plot(mesh=mesh, tex=loc_dom_band, -# caption='Local Dominant Band', cmap='jet') -# visb_sc.preview() -# + +display_settings = {} +mesh_data = {} +mesh_data['vertices'] = vertices_translate +mesh_data['faces'] = mesh.faces +mesh_data['title'] = ('Local Dominant Band') +intensity_data = {} +intensity_data['values'] = loc_dom_band +intensity_data["mode"] = "vertex" +Fig = splt.mesh_projection( + mesh_data=mesh_data, + intensity_data=intensity_data, + display_settings=display_settings) +# Fig.show() +Fig.write_image("example_spangy_2.png") + # # Plot mean curvature coefficients & compacted power spectrum characterizing # # either Sulci either Gyri folding pattern # # --------------------------------------------------------------------------- diff --git a/examples/example_topology.py b/examples/example_topology.py index 1f3052c..acca1fe 100644 --- a/examples/example_topology.py +++ b/examples/example_topology.py @@ -92,17 +92,52 @@ print(mesh.is_watertight) print(mesh_closed.is_watertight) + +print('close mesh') +broken_vertices_mesh_closed = stop.broken_vertices(mesh_closed) +print(np.count_nonzero(broken_vertices_mesh_closed)) +print('open mesh') +broken_vertices_open_mesh = stop.broken_vertices(open_mesh) +print(np.count_nonzero(broken_vertices_open_mesh)) + ############################################################################# -# VISUALIZATION USING EXTERNAL TOOLS +# VISUALIZATION USING INTERNAL TOOLS ############################################################################# -# import slam.plot as splt -# from vispy.scene import Line -# from visbrain.objects import VispyObj, SourceObj -# + +import slam.plot as splt + +vertices = open_mesh.vertices +# center the vertices +vertices = vertices - np.mean(vertices, axis=0) +vertices_translate = np.copy(vertices) +# rotate the vertices +theta = np.pi / 2 +rot_x = np.array([[1, 0, 0], + [0, np.cos(theta), -np.sin(theta)], + [0, np.sin(theta), np.cos(theta)]]) +vertices_translate = np.dot(rot_x, vertices_translate.T).T +rot_z = np.array([[np.cos(theta), -np.sin(theta), 0], + [np.sin(theta), np.cos(theta), 0], + [0, 0, 1], ]) +vertices_translate = np.dot(rot_z, vertices_translate.T).T + +# Plot Mean Curvature +display_settings = {} +mesh_data = {} +mesh_data['vertices'] = vertices_translate +mesh_data['faces'] = open_mesh.faces +mesh_data['title'] = 'Open Mesh' +intensity_data = None +Fig = splt.mesh_projection( + mesh_data=mesh_data, + intensity_data=intensity_data, + display_settings=display_settings) +# Fig.show() +Fig.write_image("example_topology_1.png") + + # ############################################################################### # # show the result -# # WARNING : BrainObj should be added first before -# visb_sc = splt.visbrain_plot(mesh=open_mesh, caption="open mesh") # # create points with vispy # for bound in open_mesh_boundary: # points = open_mesh.vertices[bound] @@ -121,6 +156,35 @@ # # ############################################################################### # # show the result +vertices = eroded_mesh.vertices +# center the vertices +vertices = vertices - np.mean(vertices, axis=0) +vertices_translate = np.copy(vertices) +# rotate the vertices +theta = np.pi / 2 +rot_x = np.array([[1, 0, 0], + [0, np.cos(theta), -np.sin(theta)], + [0, np.sin(theta), np.cos(theta)]]) +vertices_translate = np.dot(rot_x, vertices_translate.T).T +rot_z = np.array([[np.cos(theta), -np.sin(theta), 0], + [np.sin(theta), np.cos(theta), 0], + [0, 0, 1], ]) +vertices_translate = np.dot(rot_z, vertices_translate.T).T + +# Plot Mean Curvature +display_settings = {} +mesh_data = {} +mesh_data['vertices'] = vertices_translate +mesh_data['faces'] = eroded_mesh.faces +mesh_data['title'] = 'Eroded Mesh' +intensity_data = None +Fig = splt.mesh_projection( + mesh_data=mesh_data, + intensity_data=intensity_data, + display_settings=display_settings) +# Fig.show() +Fig.write_image("example_topology_2.png") + # visb_sc2 = splt.visbrain_plot(mesh=eroded_mesh, caption="eroded mesh") # # show again the boundary of original mesh which have been removed with # # corresponding faces by the erosion @@ -140,9 +204,37 @@ # visb_sc2.preview() # # ############################################################################### -# # show the results -# visb_sc3 = splt.visbrain_plot( -# mesh=mesh, tex=tex_parcel.darray[0], caption="texture boundary" +# show the result +vertices = mesh.vertices +# center the vertices +vertices = vertices - np.mean(vertices, axis=0) +vertices_translate = np.copy(vertices) +# rotate the vertices +theta = np.pi / 2 +rot_x = np.array([[1, 0, 0], + [0, np.cos(theta), -np.sin(theta)], + [0, np.sin(theta), np.cos(theta)]]) +vertices_translate = np.dot(rot_x, vertices_translate.T).T +rot_z = np.array([[np.cos(theta), -np.sin(theta), 0], + [np.sin(theta), np.cos(theta), 0], + [0, 0, 1], ]) +vertices_translate = np.dot(rot_z, vertices_translate.T).T + +# Plot Mean Curvature +display_settings = {} +mesh_data = {} +mesh_data['vertices'] = vertices_translate +mesh_data['faces'] = mesh.faces +mesh_data['title'] = 'Texture Boundary' +intensity_data = {} +intensity_data['values'] = tex_parcel.darray[0] +intensity_data["mode"] = "vertex" +Fig = splt.mesh_projection( + mesh_data=mesh_data, + intensity_data=intensity_data, + display_settings=display_settings) +# Fig.show() +Fig.write_image("example_topology_3.png") # ) # cols = ["red", "green", "yellow", "blue"] # ind = 0 @@ -166,20 +258,46 @@ # # ############################################################################### # # show the mesh with the cuted subparts in different colors -# scene_list = list() -# cuted_mesh = sub_meshes[-1] -# joint_mesh = sub_meshes[0] -# joint_tex = np.zeros((sub_meshes[0].vertices.shape[0],)) -# last_ind = sub_meshes[0].vertices.shape[0] -# for ind, sub_mesh in enumerate(sub_meshes[1:]): -# sub_tex = np.ones((sub_mesh.vertices.shape[0],)) * (ind + 1) -# joint_mesh += sub_mesh -# joint_tex = np.hstack((joint_tex, sub_tex)) -# visb_sc3 = splt.visbrain_plot( -# mesh=joint_mesh, -# tex=joint_tex, -# caption="mesh parts shown in different colors" -# ) +scene_list = list() +cuted_mesh = sub_meshes[-1] +joint_mesh = sub_meshes[0] +joint_tex = np.zeros((sub_meshes[0].vertices.shape[0],)) +last_ind = sub_meshes[0].vertices.shape[0] +for ind, sub_mesh in enumerate(sub_meshes[1:]): + sub_tex = np.ones((sub_mesh.vertices.shape[0],)) * (ind + 1) + joint_mesh += sub_mesh + joint_tex = np.hstack((joint_tex, sub_tex)) + +vertices = joint_mesh.vertices +# center the vertices +vertices = vertices - np.mean(vertices, axis=0) +vertices_translate = np.copy(vertices) +# rotate the vertices +theta = np.pi / 2 +rot_x = np.array([[1, 0, 0], + [0, np.cos(theta), -np.sin(theta)], + [0, np.sin(theta), np.cos(theta)]]) +vertices_translate = np.dot(rot_x, vertices_translate.T).T +rot_z = np.array([[np.cos(theta), -np.sin(theta), 0], + [np.sin(theta), np.cos(theta), 0], + [0, 0, 1], ]) +vertices_translate = np.dot(rot_z, vertices_translate.T).T + +display_settings = {} +mesh_data = {} +mesh_data['vertices'] = vertices_translate +mesh_data['faces'] = joint_mesh.faces +mesh_data['title'] = 'mesh parts shown in different colors' +intensity_data = {} +intensity_data['values'] = joint_tex +intensity_data["mode"] = "vertex" +Fig = splt.mesh_projection( + mesh_data=mesh_data, + intensity_data=intensity_data, + display_settings=display_settings) +# Fig.show() +Fig.write_image("example_topology_4.png") + # ind = 0 # boundaries = stop.mesh_boundary(cuted_mesh) # for bound in boundaries: @@ -200,8 +318,36 @@ # ind = 0 # visb_sc3.preview() # ############################################################################### -# # show the largest submesh with the boundaries of cutted parts -# visb_sc4 = splt.visbrain_plot(mesh=cuted_mesh, caption="open mesh") +# show the largest submesh with the boundaries of cutted parts +vertices = cuted_mesh.vertices +# center the vertices +vertices = vertices - np.mean(vertices, axis=0) +vertices_translate = np.copy(vertices) +# rotate the vertices +theta = np.pi / 2 +rot_x = np.array([[1, 0, 0], + [0, np.cos(theta), -np.sin(theta)], + [0, np.sin(theta), np.cos(theta)]]) +vertices_translate = np.dot(rot_x, vertices_translate.T).T +rot_z = np.array([[np.cos(theta), -np.sin(theta), 0], + [np.sin(theta), np.cos(theta), 0], + [0, 0, 1], ]) +vertices_translate = np.dot(rot_z, vertices_translate.T).T + +display_settings = {} +mesh_data = {} +mesh_data['vertices'] = vertices_translate +mesh_data['faces'] = cuted_mesh.faces +mesh_data['title'] = 'Open Mesh' +intensity_data = None +Fig = splt.mesh_projection( + mesh_data=mesh_data, + intensity_data=intensity_data, + display_settings=display_settings) +# Fig.show() +Fig.write_image("example_topology_5.png") + + # # create points with vispy # for bound in boundaries: # points = cuted_mesh.vertices[bound] @@ -219,12 +365,82 @@ # visb_sc4.preview() # ############################################################################### # # show the closed mesh -# visb_sc5 = splt.visbrain_plot(mesh=mesh_closed, caption="closed mesh") -# visb_sc5.preview() -print('close mesh') -broken_vertices = stop.broken_vertices(mesh_closed) -print(np.count_nonzero(broken_vertices)) -print('open mesh') -broken_vertices = stop.broken_vertices(open_mesh) -print(np.count_nonzero(broken_vertices)) +# show the largest submesh with the boundaries of cutted parts +vertices = mesh_closed.vertices +# center the vertices +vertices = vertices - np.mean(vertices, axis=0) +vertices_translate = np.copy(vertices) +# rotate the vertices +theta = np.pi / 2 +rot_x = np.array([[1, 0, 0], + [0, np.cos(theta), -np.sin(theta)], + [0, np.sin(theta), np.cos(theta)]]) +vertices_translate = np.dot(rot_x, vertices_translate.T).T +rot_z = np.array([[np.cos(theta), -np.sin(theta), 0], + [np.sin(theta), np.cos(theta), 0], + [0, 0, 1], ]) +vertices_translate = np.dot(rot_z, vertices_translate.T).T + +display_settings = {} +mesh_data = {} +mesh_data['vertices'] = vertices_translate +mesh_data['faces'] = mesh_closed.faces +mesh_data['title'] = 'Closed Mesh' +intensity_data = None +Fig = splt.mesh_projection( + mesh_data=mesh_data, + intensity_data=intensity_data, + display_settings=display_settings) +# Fig.show() +Fig.write_image("example_topology_6.png") + +# Plot the broken vertices + +vertices = mesh_closed.vertices +# center the vertices +vertices = vertices - np.mean(vertices, axis=0) +vertices_translate = np.copy(vertices) +# rotate the vertices +vertices_translate = np.dot(rot_x, vertices_translate.T).T +vertices_translate = np.dot(rot_z, vertices_translate.T).T + +# Plot Mean Curvature +display_settings = {} +display_settings['colorbar_label'] = 'Broken Vertices' +mesh_data = {} +mesh_data['vertices'] = vertices_translate +mesh_data['faces'] = mesh_closed.faces +mesh_data['title'] = 'Mesh Close' +intensity_data = {} +intensity_data['values'] = broken_vertices_mesh_closed +intensity_data["mode"] = "vertex" +Fig = splt.mesh_projection( + mesh_data=mesh_data, + intensity_data=intensity_data, + display_settings=display_settings) +# Fig.show() +Fig.write_image("example_topology_7.png") + +vertices = open_mesh.vertices +# center the vertices +vertices = vertices - np.mean(vertices, axis=0) +vertices_translate = np.copy(vertices) +# rotate the vertices +vertices_translate = np.dot(rot_x, vertices_translate.T).T +vertices_translate = np.dot(rot_z, vertices_translate.T).T +display_settings = {} +display_settings['colorbar_label'] = 'Broken Vertices' +mesh_data = {} +mesh_data['vertices'] = vertices_translate +mesh_data['faces'] = open_mesh.faces +mesh_data['title'] = 'Mesh Close' +intensity_data = {} +intensity_data['values'] = broken_vertices_open_mesh +intensity_data["mode"] = "vertex" +Fig = splt.mesh_projection( + mesh_data=mesh_data, + intensity_data=intensity_data, + display_settings=display_settings) +# Fig.show() +Fig.write_image("example_topology_8.png") diff --git a/examples/example_transfo_mesh.py b/examples/example_transfo_mesh.py new file mode 100644 index 0000000..d2cecff --- /dev/null +++ b/examples/example_transfo_mesh.py @@ -0,0 +1,65 @@ +import slam.io as sio +import numpy as np + +mesh_file = "../examples/data/example_mesh.gii" + +mesh = sio.load_mesh(mesh_file) + +vertices = mesh.vertices + +theta = np.pi / 2 +rot_x = np.array([[1, 0, 0], + [0, np.cos(theta), -np.sin(theta)], + [0, np.sin(theta), np.cos(theta)]]) + + + +############################################################################# +# VISUALIZATION USING INTERNAL TOOLS +############################################################################# +import slam.plot as splt + +# Plot Original Mesh +display_settings = {} +mesh_data = {} +mesh_data['vertices'] = vertices +mesh_data['faces'] = mesh.faces +mesh_data['title'] = 'example_mesh.gii Without Transformation' + +intensity_data = None +Fig = splt.mesh_projection( + mesh_data=mesh_data, + intensity_data=intensity_data, + display_settings=display_settings) +# Fig.show() +Fig.write_image("example_transfo_mesh_1.png") + +mesh.apply_transform(mesh.principal_inertia_transform) + +display_settings = {} +mesh_data = {} +mesh_data['vertices'] = mesh.vertices +mesh_data['faces'] = mesh.faces +mesh_data['title'] = 'example_mesh.gii PCA Transformation' +intensity_data = None +Fig = splt.mesh_projection( + mesh_data=mesh_data, + intensity_data=intensity_data, + display_settings=display_settings) +# Fig.show() +Fig.write_image("example_transfo_mesh_2.png") + +vertices_translate = np.dot(rot_x, mesh.vertices.T).T + +display_settings = {} +mesh_data = {} +mesh_data['vertices'] = vertices_translate +mesh_data['faces'] = mesh.faces +mesh_data['title'] = 'example_mesh.gii With PCA and rotation Transformation' +intensity_data = None +Fig = splt.mesh_projection( + mesh_data=mesh_data, + intensity_data=intensity_data, + display_settings=display_settings) +# Fig.show() +Fig.write_image("example_transfo_mesh_3.png") diff --git a/examples/example_vertex_voronoi.py b/examples/example_vertex_voronoi.py index 47377b5..27823d8 100644 --- a/examples/example_vertex_voronoi.py +++ b/examples/example_vertex_voronoi.py @@ -36,9 +36,11 @@ print(vert_vor.shape) print(np.sum(vert_vor) - mesh.area) + ############################################################################# -# VISUALIZATION USING EXTERNAL TOOLS +# VISUALIZATION USING INTERNAL TOOLS ############################################################################# + import slam.plot as splt ############################################################################### # Visualization @@ -62,8 +64,9 @@ intensity_data = {} intensity_data['values'] = vert_vor intensity_data["mode"] = "vertex" -visb_sc = splt.mes3d_projection( +Fig = splt.mesh_projection( mesh_data=mesh_data, intensity_data=intensity_data, display_settings=display_settings) -visb_sc.show() +# Fig.show() +Fig.write_image("example_vertex_voronoi_1.png") diff --git a/examples/example_watershed.py b/examples/example_watershed.py index 392adb4..a206df2 100644 --- a/examples/example_watershed.py +++ b/examples/example_watershed.py @@ -30,11 +30,11 @@ path_to_mesh = "../examples/data/example_mesh.gii" path_to_mask = None path_to_output = "" -#path_to_mesh = "/mnt/data/work/BV_database/BV_db_test/subjects/auzias/t1mri/default_acquisition/default_analysis/segmentation/mesh/auzias_Lwhite.gii" -#path_to_output = "/mnt/data/work/BV_database/BV_db_test/subjects/auzias/t1mri/default_acquisition/default_analysis/segmentation/mesh/" +# path_to_mesh = "/mnt/data/work/BV_database/BV_db_test/subjects/auzias/t1mri/default_acquisition/default_analysis/segmentation/mesh/auzias_Lwhite.gii" +# path_to_output = "/mnt/data/work/BV_database/BV_db_test/subjects/auzias/t1mri/default_acquisition/default_analysis/segmentation/mesh/" -#path_to_mesh = "/mnt/data/work/python_sandBox/brain_slam/debug_watershed/example_mesh.gii" -#path_to_output = "/mnt/data/work/python_sandBox/brain_slam/debug_watershed/" +# path_to_mesh = "/mnt/data/work/python_sandBox/brain_slam/debug_watershed/example_mesh.gii" +# path_to_output = "/mnt/data/work/python_sandBox/brain_slam/debug_watershed/" mesh = sio.load_mesh(path_to_mesh) side = "left" @@ -46,7 +46,7 @@ # normalize watershed thresholds thresh_dist, thresh_ridge, thresh_area = swat.normalize_thresholds(voronoi, thresh_dist=20.0, thresh_ridge=1.5, thresh_area=50.0, side=side) -thresh_dist, thresh_ridge, thresh_area = 0,0,0 +thresh_dist, thresh_ridge, thresh_area = 0, 0, 0 ############################################################################### # define the exclusion mask (cingular pole) if path_to_mask is not None: @@ -56,16 +56,20 @@ ############################################################################### # extract sulcal pits and associated basins -basins, ridges, adjacency = swat.watershed(mesh, voronoi, dpf, thresh_dist, thresh_ridge, thresh_area, mask) +basins, ridges, adjacency = swat.watershed( + mesh, voronoi, dpf, thresh_dist, thresh_ridge, thresh_area, mask) ############################################################################### # 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) +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) +g = ssg.get_sulcal_graph( + adjacency, basins, ridges, save=True, outdir=path_to_output) ############################################################################### # generate the textures from graph -tex_labels, tex_pits, tex_ridges = ssg.get_textures_from_graph(g, mesh, save=True, outdir=path_to_output) \ No newline at end of file +tex_labels, tex_pits, tex_ridges = (ssg.get_textures_from_graph + (g, mesh, save=True, outdir=path_to_output))