-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathConvertFS2BIDS.m
63 lines (52 loc) · 2.68 KB
/
ConvertFS2BIDS.m
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
function BIDS = ConvertFS2BIDS(BIDS)
%
%
%
output_dir = fullfile(BIDS.pth,'derivatives',BIDS.config.env.derivatives_dir);
fs_dir = fullfile(BIDS.pth,'derivatives','freesurfer');
setenv('SUBJECTS_DIR',fullfile(BIDS.pth,'derivatives','freesurfer'));
if BIDS.config.env.nproc > 1
parpool('local',BIDS.config.env.nproc)
parfor idx = 1:numel(BIDS.subjects)
subj = BIDS.subjects(idx).name;
ses = BIDS.subjects(idx).session;
aparc_file = fullfile(fs_dir, subj, 'mri/aparc+aseg.mgz');
aparc_file_bids = fullfile(output_dir, subj, ses, ...
'anat', [subj '_' ses '_space-T1w_desc-aparcaseg_dseg.nii.gz']);
aseg_file = fullfile(fs_dir, subj, 'mri/aseg.mgz');
aseg_file_bids = fullfile(output_dir, subj, ses, ...
'anat', [subj '_' ses '_space-T1w_desc-aseg_dseg.nii.gz']);
gtm_file = fullfile(fs_dir, subj, 'mri/gtmseg.mgz');
gtm_file_bids = fullfile(output_dir, subj, ses, ...
'anat', [subj '_' ses '_space-T1w_desc-gtm_dseg.nii.gz']);
brainmask_file = fullfile(fs_dir, subj, 'mri/brainmask.mgz');
brainmask_file_bids = fullfile(output_dir, subj, ses, ...
'anat', [subj '_' ses '_space-T1w_desc-brain_mask.nii.gz']);
unix(['mri_convert ' aparc_file ' ' aparc_file_bids]);
unix(['mri_convert ' aseg_file ' ' aseg_file_bids]);
unix(['mri_convert ' gtm_file ' ' gtm_file_bids]);
unix(['mri_convert ' brainmask_file ' ' brainmask_file_bids]);
end
delete(gcp('nocreate'));
else
for idx = 1:numel(BIDS.subjects)
subj = BIDS.subjects(idx).name;
ses = BIDS.subjects(idx).session;
aparc_file = fullfile(fs_dir, subj, 'mri/aparc+aseg.mgz');
aparc_file_bids = fullfile(output_dir, subj, ses, ...
'anat', [subj '_' ses '_space-T1w_desc-aparcaseg_dseg.nii.gz']);
aseg_file = fullfile(fs_dir, subj, 'mri/aseg.mgz');
aseg_file_bids = fullfile(output_dir, subj, ses, ...
'anat', [subj '_' ses '_space-T1w_desc-aseg_dseg.nii.gz']);
gtm_file = fullfile(fs_dir, subj, 'mri/gtmseg.mgz');
gtm_file_bids = fullfile(output_dir, subj, ses, ...
'anat', [subj '_' ses '_space-T1w_desc-gtm_dseg.nii.gz']);
brainmask_file = fullfile(fs_dir, subj, 'mri/brainmask.mgz');
brainmask_file_bids = fullfile(output_dir, subj, ses, ...
'anat', [subj '_' ses '_space-T1w_desc-brain_mask.nii.gz']);
unix(['mri_convert ' aparc_file ' ' aparc_file_bids]);
unix(['mri_convert ' aseg_file ' ' aseg_file_bids]);
unix(['mri_convert ' gtm_file ' ' gtm_file_bids]);
unix(['mri_convert ' brainmask_file ' ' brainmask_file_bids]);
end
end