Skip to content

Commit c15d0b4

Browse files
committed
Scripts used to generate the mappings to surface.
1 parent 0860e8e commit c15d0b4

File tree

2 files changed

+50
-0
lines changed

2 files changed

+50
-0
lines changed
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import os
2+
import numpy as np
3+
4+
from brainplotlib3d import ValuesIcoorder, Surface, plot_to_file
5+
6+
7+
if __name__ == '__main__':
8+
# nv = 1175 # 588 + 587
9+
nv = 4**7 * 10 + 2
10+
v = np.arange(nv * 2, dtype=int)
11+
c1 = v // 256 **2
12+
c2 = (v // 256) % 256
13+
c3 = v % 256
14+
c = np.stack([c1, c2, c3], axis=1) / 255.
15+
v = np.array_split(c, 2, axis=0)
16+
values = ValuesIcoorder(v[0], v[1], fill_nan=0.8, space='fsaverage', icoorder=7)
17+
18+
for surf_type in ['inflated', 'pial', 'midthickness', 'white']:
19+
out_fn = f'fsaverage_{surf_type}.npy'
20+
if os.path.exists(out_fn):
21+
continue
22+
23+
zoom = 0.015
24+
if surf_type == 'inflated':
25+
zoom = 0.013
26+
27+
surf = Surface(surf_type, 'FS')
28+
surf.add_colors(values)
29+
actors = surf.get_actors(ambient=1, diffuse=0, specular=0)
30+
31+
img = plot_to_file([actors[0]], [actors[1]],
32+
surf.focal_points, out_fn=None,
33+
zoom=zoom, magnification=1, aa_frames=1)
34+
np.save(out_fn, img)
35+
exit(0)
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import cv2
2+
import numpy as np
3+
4+
5+
if __name__ == '__main__':
6+
for surf_type in ['inflated', 'pial', 'midthickness', 'white']:
7+
img = np.load(f'fsaverage_{surf_type}.npy')
8+
nv = 4**7 * 10 + 2
9+
mask = (img[:, :, 3] == 0.0)
10+
img = np.round(img[:, :, :3] * 255).astype(int)
11+
v = ((img[:, :, 0] * 256**2) + (img[:, :, 1] * 256) + img[:, :, 2])
12+
print(v.shape, mask.shape)
13+
v[mask] = -1
14+
np.save(f'fsaverage_to_{surf_type}_image.npy', v)
15+
print(v.max(), v.min(), np.unique(v).shape)

0 commit comments

Comments
 (0)