forked from brain-networks/event_detection
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathatlas_mod.py
More file actions
executable file
·34 lines (29 loc) · 1.12 KB
/
atlas_mod.py
File metadata and controls
executable file
·34 lines (29 loc) · 1.12 KB
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
import nibabel as nib
import numpy as np
import os
import subprocess
def transform(atlas_orig, data_tlrc, temp_dir):
if np.any(nib.load(atlas_orig).affine != nib.load(data_tlrc).affine):
atlas_mat = nib.load(atlas_orig).get_fdata()
tmp_image = nib.Nifti1Image(
atlas_mat, nib.load(data_tlrc).affine, nib.load(data_tlrc).header
)
TMP_name = "atlas.nii.gz"
nib.save(tmp_image, os.path.join(temp_dir, TMP_name))
subprocess.run(
f"3drefit -space TLRC -view tlrc {os.path.join(temp_dir, TMP_name)}",
shell=True,
)
else:
os.system(f"cp {atlas_orig} {os.path.join(temp_dir, TMP_name)}")
return os.path.join(temp_dir, TMP_name)
def inverse_transform(data_tlrc, atlas_orig):
subprocess.run(
f"3drefit -space ORIG -view orig {data_tlrc}",
shell=True,
)
tmp_data = nib.Nifti1Image(nib.load(data_tlrc).get_fdata(),
nib.load(atlas_orig).affine,
nib.load(atlas_orig).header
)
nib.save(tmp_data, data_tlrc)