Skip to content

Commit

Permalink
Scripts used to generate the mappings to surface.
Browse files Browse the repository at this point in the history
  • Loading branch information
feilong committed Feb 8, 2022
1 parent 0860e8e commit c15d0b4
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 0 deletions.
35 changes: 35 additions & 0 deletions scripts/compute_fsaverage_mapping_part1.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import os
import numpy as np

from brainplotlib3d import ValuesIcoorder, Surface, plot_to_file


if __name__ == '__main__':
# nv = 1175 # 588 + 587
nv = 4**7 * 10 + 2
v = np.arange(nv * 2, dtype=int)
c1 = v // 256 **2
c2 = (v // 256) % 256
c3 = v % 256
c = np.stack([c1, c2, c3], axis=1) / 255.
v = np.array_split(c, 2, axis=0)
values = ValuesIcoorder(v[0], v[1], fill_nan=0.8, space='fsaverage', icoorder=7)

for surf_type in ['inflated', 'pial', 'midthickness', 'white']:
out_fn = f'fsaverage_{surf_type}.npy'
if os.path.exists(out_fn):
continue

zoom = 0.015
if surf_type == 'inflated':
zoom = 0.013

surf = Surface(surf_type, 'FS')
surf.add_colors(values)
actors = surf.get_actors(ambient=1, diffuse=0, specular=0)

img = plot_to_file([actors[0]], [actors[1]],
surf.focal_points, out_fn=None,
zoom=zoom, magnification=1, aa_frames=1)
np.save(out_fn, img)
exit(0)
15 changes: 15 additions & 0 deletions scripts/compute_fsaverage_mapping_part2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import cv2
import numpy as np


if __name__ == '__main__':
for surf_type in ['inflated', 'pial', 'midthickness', 'white']:
img = np.load(f'fsaverage_{surf_type}.npy')
nv = 4**7 * 10 + 2
mask = (img[:, :, 3] == 0.0)
img = np.round(img[:, :, :3] * 255).astype(int)
v = ((img[:, :, 0] * 256**2) + (img[:, :, 1] * 256) + img[:, :, 2])
print(v.shape, mask.shape)
v[mask] = -1
np.save(f'fsaverage_to_{surf_type}_image.npy', v)
print(v.max(), v.min(), np.unique(v).shape)

0 comments on commit c15d0b4

Please sign in to comment.