-
Notifications
You must be signed in to change notification settings - Fork 0
/
interpolation.py
61 lines (47 loc) · 1.59 KB
/
interpolation.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# Imports :
import numpy as np
import numpy.matlib
import slam.io as sio
import pyvista as pv
import os
import slam.utils as ut
import numpy.matlib
import slam.generate_parametric_surfaces as sgps
import slam.plot as splt
import slam.curvature as scurv
import slam.topology as stop
import slam.differential_geometry as sdg
import matplotlib.pyplot as plt
from matplotlib.cm import get_cmap
# Load data :
mesh_file1 = './KKI2009_113/MR1/lh.sphere.reg.gii'
sphFV1 = sio.load_mesh(mesh_file1)
mesh_file2 = './KKI2009_113/MR2/lh.sphere.reg.gii'
sphFV2 = sio.load_mesh(mesh_file2)
coord1 = sphFV1.vertices
coord2 = sphFV2.vertices
mesh_file3 = './KKI2009_113/MR2/lh.white.gii'
FV2 = sio.load_mesh(mesh_file3)
# Load Texture
mesh_file = './KKI2009_113/MR1/lh.white.bassin1.gii'
texture1 = sio.load_texture(mesh_file)
# Texture to array
texture1 = texture1.darray[0]
# Visualisation mesh1
visb_sc = splt.visbrain_plot(mesh=sphFV1, tex=texture1,caption='Surface 1 - ROI')
visb_sc.preview()
# Initialisation of var for texture
texture2 = np.zeros(len(coord2))
print("Calculating texture by interpolation")
# Algo Interpolation
for i in range(len(coord2)):
if i%1000 ==0:
print("{:.2f}".format(i/total*100), " percent finished")
ind = np.argmin(np.linalg.norm(coord1 - sphFV2.vertices[i,:],axis=1))
texture2[i] = texture1[ind]
# Saving texture in npy format
with open('texture2.npy', 'wb') as f:
np.save(f,texture2)
# Visualisation mesh2
visb_sc = splt.visbrain_plot(mesh=sphFV2, tex=texture2,caption='Surface 2 - ROI')
visb_sc.preview()