s = 0 for curv_type in curv_types: err= list() for sigma in Sigma: cc = 'hex_quad_k1_' + str(Ks[i][0]) + '_k2_' + str(Ks[i][1]) + '_' + str(nstep) + '_noise_' + str( int(sigma * 1000)) # os.chdir(r"/hpc/meca/users/souani.a/curvature/Compute_curvatures/Noise") # os.mkdir(cc ) # os.chdir(r"/hpc/meca/users/souani.a/curvature/Compute_curvatures/Noise/"+cc) # sio.write_mesh(mesh, cc+'.gii') list_exampels.append(cc) mesh_file = 'hex_quad_k1_' + str(Ks[i][0]) + '_k2_' + str(Ks[i][1]) + '_' + str(nstep) + '.gii' os.chdir("/hpc/meca/users/souani.a/curvature/Compute_curvatures/Curvatures/0Noise") mesh = sio.load_mesh(mesh_file) xx = sps.quadric_curv_mean(Ks[i][0], Ks[i][1])(mesh.vertices[:, 0], mesh.vertices[:, 1]) xx_m = np.zeros((nstep ** 2, 1)) texture_file = cc + '_curv_mean_' + curv_type + '.gii' # mesh.apply_transform(mesh.principal_inertia_transform) os.chdir( "/hpc/meca/users/souani.a/curvature/Compute_curvatures/Curvatures/Noise/" + cc) tex = sio.load_texture(texture_file) err.append(mean_squared_error(xx, tex.darray)) plt.plot( Sigma,err, color=couleur[s] , marker= 'o', label=str(curv_types[s])) print("Done for "+ cc[:-5]+ ' for '+ curv_type) # plt.text(Sigma[0], err[0], curv_types[s], fontsize=9) s += 1 # plt.show() os.chdir(r"/hpc/meca/users/souani.a/curvature/Compute_curvatures/Curvatures/Figures/Mean_squarred_error_function_of_noise") plt.savefig("MSE function of noise for " + cc)
print(open_mesh_boundary) scene_list = [open_mesh] for bound in open_mesh_boundary: points = open_mesh.vertices[bound] cloud_boundary = trimesh.points.PointCloud(points) cloud_colors = np.array( [trimesh.visual.random_color() for i in points]) cloud_boundary.vertices_color = cloud_colors scene_list.append(cloud_boundary) scene = trimesh.Scene(scene_list) scene.show() # here is how to get the vertices that define the boundary of # a texture on a mesh mesh = sio.load_mesh('data/example_mesh.gii') tex_parcel = sio.load_texture('data/example_texture_parcel.gii') col_map = trimesh.visual.color.interpolate(tex_parcel.darray) mesh.visual.vertex_colors = col_map boundary = stop.texture_boundary(mesh, tex_parcel.darray, 0) print(boundary) scene_list = [mesh] for bound in boundary: path_visual = trimesh.load_path(mesh.vertices[bound]) path_visual.vertices_color = trimesh.visual.random_color() scene_list.append(path_visual) # points = mesh.vertices[bound] # cloud_boundary = trimesh.points.PointCloud(points) # cloud_colors = np.array([trimesh.visual.random_color() # for i in points]) # cloud_boundary.vertices_color = cloud_colors # scene_list.append(cloud_boundary)
import slam.io as sio import slam.remeshing as srem ############################################################################### # source object files source_mesh_file = 'data/example_mesh.gii' source_texture_file = 'data/example_texture.gii' source_spherical_mesh_file = 'data/example_mesh_spherical.gii' ############################################################################### # target object files target_mesh_file = 'data/example_mesh_2.gii' target_spherical_mesh_file = 'data/example_mesh_2_spherical.gii' source_mesh = sio.load_mesh(source_mesh_file) source_tex = sio.load_texture(source_texture_file) source_spherical_mesh = sio.load_mesh(source_spherical_mesh_file) target_mesh = sio.load_mesh(target_mesh_file) target_spherical_mesh = sio.load_mesh(target_spherical_mesh_file) interpolated_tex_values = \ srem.spherical_interpolation_nearest_neigbhor(source_spherical_mesh, target_spherical_mesh, source_tex.darray[0]) ############################################################################### # plot 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,
import slam.io as sio import slam.differential_geometry as sdg import slam.plot as splt if __name__ == '__main__': # load example data mesh = sio.load_mesh('data/example_mesh.gii') tex = sio.load_texture('data/example_texture.gii') # compute various types of Laplacian of the mesh lap, lap_b = sdg.compute_mesh_laplacian(mesh, lap_type='fem') print(mesh.vertices.shape) print(lap.shape) lap, lap_b = sdg.compute_mesh_laplacian(mesh, lap_type='conformal') lap, lap_b = sdg.compute_mesh_laplacian(mesh, lap_type='meanvalue') lap, lap_b = sdg.compute_mesh_laplacian(mesh, lap_type='authalic') # smooth the mesh using Laplacian s_mesh = sdg.laplacian_mesh_smoothing(mesh, nb_iter=100, dt=0.1) # compute the gradient of texture tex triangle_grad = sdg.triangle_gradient(mesh, tex.darray[0]) print(triangle_grad) grad = sdg.gradient(mesh, tex.darray[0]) print(grad.values) norm_grad = sdg.norm_gradient(mesh, tex.darray[0]) print(norm_grad) # compute the depth potential function dpf = sdg.depth_potential_function(mesh, tex.darray[0], [0.3])
#print('nb of tex found: ' + str(len(tex_files))) #print(subjects) OASIS_diff = [] OASIS_corr_coef = [] OASIS_subjects_list = [] KKI_diff = [] KKI_corr_coef = [] KKI_subjects_list = [] for ind_s,s in enumerate(subjects): if 'MR2' in s: if 'OAS1' in s: if s[:-4] in subjects: corresp_ind = subjects.index(s[:-4]) corresp_s = subjects[corresp_ind] MR2_tex = sio.load_texture(os.path.join(output_folder, tex_files[ind_s])) MR1_tex = sio.load_texture(os.path.join(output_folder, tex_files[corresp_ind])) OASIS_diff.append(MR2_tex.darray - MR1_tex.darray) OASIS_subjects_list.append(s[:-4]) per = pearsonr(MR2_tex.darray, MR1_tex.darray) OASIS_corr_coef.append(per[0][0]) else: if s[:-4]+'_MR1' in subjects: corresp_ind = subjects.index(s[:-4]+'_MR1') corresp_s = subjects[corresp_ind] MR2_tex = sio.load_texture(os.path.join(output_folder, tex_files[ind_s])) MR1_tex = sio.load_texture(os.path.join(output_folder, tex_files[corresp_ind])) KKI_diff.append(MR2_tex.darray - MR1_tex.darray) KKI_subjects_list.append(s[:-4]) per = pearsonr(MR2_tex.darray, MR1_tex.darray) KKI_corr_coef.append(per[0][0])
import generate_quadric_surfaces as gqs if __name__ == "__main__": ccc = ["sub_mesh0", "sub_mesh1", "sub_mesh2", "sub_mesh3", "sub_mesh4"] curv_types = ["Dong", "PetitJean", "Peyre", "Rusinkiewicz", "Taubin"] mm = "lhwhite" i = 0 for cc in ccc: os.chdir(r"/hpc/meca/users/souani.a/curvature") data = list() mesh = sio.load_mesh(cc + ".gii") for curv_type in curv_types: print(curv_type) os.chdir(r"/hpc/meca/users/souani.a/data/sub_m/sub_m" + str(i)) texture_mean = sio.load_texture(cc + "_curv_mean_" + curv_type + ".gii") print(np.shape(texture_mean.darray)) data.append(texture_mean.darray) # splt.pyglet_plot(mesh, texture_mean.darray, color_map='jet') texture_gauss = sio.load_texture(cc + "_curv_gauss_" + curv_type + ".gii") # splt.pyglet_plot(mesh, texture_gauss.darray, color_map='jet') #data = np.array(data) #print(data) data = np.array(data) print(np.shape(data)) embedding = MDS(n_components=2) print(np.shape(data[:, :, 0])) data_t = embedding.fit_transform(data[:, :, 0]) print(np.shape(data_t)) # print(data_t)
tex_files = list() for subject_mesh_file in subjects_mesh_files: filename_split = subject_mesh_file.split('/') subj = filename_split[6] filename = filename_split[-1] side = filename[0] print(subj + ' ' + side) curv = os.path.join( output_folder, subj + '.' + side + 'h.white_curv_' + curv_type + '_NN_FSsphere.ico7.gii') if not os.path.exists(curv): mesh_files.append(subject_mesh_file) tex_files.append(curv) print('nb of meshes to be processed: ' + str(len(mesh_files))) #mesh_files_i = mesh_files[:2] #tex_files_i = tex_files[:2] for mesh_file, tex_file in zip(mesh_files, tex_files): print('remeshing for ' + tex_file) file_tex_in = tex_file[:-21] + '.gii' print(file_tex_in) source_tex = sio.load_texture(file_tex_in) source_spherical_mesh = sio.load_mesh(mesh_file) interpolated_tex = \ srem.spherical_interpolation_nearest_neigbhor(source_spherical_mesh, target_spherical_mesh, source_tex.darray) #splt.pyglet_plot(target_spherical_mesh, interpolated_tex, -1, 1) output_texture = stex.TextureND(darray=interpolated_tex) sio.write_texture(output_texture, tex_file)
# Authors: # Guillaume Auzias <*****@*****.**> # Julien Barrès <*****@*****.**> # License: BSD (3-clause) # sphinx_gallery_thumbnail_number = 2 ############################################################################### # Importation of slam modules import numpy as np from slam import texture from slam import io as sio ############################################################################### # tex = sio.load_texture('../examples/data/example_texture.gii') print(tex) print(tex.metadata) print(tex.shape) print(tex.dtype) print(tex.min()) print(tex.max()) ############################################################################### # darray = np.zeros((2, 3)) tex2 = texture.TextureND(darray=darray) print(tex2.metadata) print(tex2) print(tex2.shape) print(tex2.dtype)