forked from Remi-Gau/bidsNighres
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathnighres_create_layers.py
65 lines (49 loc) · 1.97 KB
/
nighres_create_layers.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
62
63
64
65
import os
import nighres
from nilearn import plotting
input_dir = "/home/remi/gin/V5_high-res/pilot_1/derivatives/nighres"
subj = "sub-pilot001"
sess = "ses-001"
subj_dir = os.path.join(input_dir, subj, sess, "anat")
filename = "sub-pilot001_ses-001_acq-"
n_layers = 6
up = ""
RES = ["075", "069"]
# extract left cerebrum
ROIS = ["right_cerebrum", "left_cerebrum"]
LABELS = ["RightCerebrum", "LeftCerebrum"]
for res in RES:
segmentation = os.path.join(subj_dir, res, filename + res + "_mgdm-seg.nii.gz")
boundary_dist = os.path.join(subj_dir, res, filename + res + "_mgdm-dist.nii.gz")
max_labels = os.path.join(subj_dir, res, filename + res + "_mgdm-lbls.nii.gz")
max_probas = os.path.join(subj_dir, res, filename + res + "_mgdm-mems.nii.gz")
for i, roi in enumerate(ROIS):
output_filename = filename + res + "_label-" + LABELS[i] + "_mask"
cortex = nighres.brain.extract_brain_region(
segmentation=segmentation,
levelset_boundary=boundary_dist,
maximum_membership=max_probas,
maximum_label=max_labels,
extracted_region=roi,
save_data=True,
file_name=output_filename,
output_dir=os.path.join(subj_dir, res),
)
cruise = nighres.cortex.cruise_cortex_extraction(
init_image=cortex["inside_mask"],
wm_image=cortex["inside_proba"],
gm_image=cortex["region_proba"],
csf_image=cortex["background_proba"],
normalize_probabilities=True,
save_data=True,
file_name=output_filename,
output_dir=os.path.join(subj_dir, res, "cruise"),
)
depth = nighres.laminar.volumetric_layering(
inner_levelset=cruise["gwb"],
outer_levelset=cruise["cgb"],
n_layers=n_layers,
save_data=True,
file_name=output_filename,
output_dir=os.path.join(subj_dir, res, f"nbLayers-{n_layers}"),
)