-
Notifications
You must be signed in to change notification settings - Fork 0
/
fs_mris_divide_parcellation.m
64 lines (48 loc) · 2.27 KB
/
fs_mris_divide_parcellation.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
64
function fs_mris_divide_parcellation(varargin)
% split STG and MTG in lh/rh.aparc.annot and save as
% lh/rh.aparc.split_STG_MTG.annot
if isempty(varargin)
subj = input('subject ID: ','s');
elseif nargin==1
subj = varargin{1};
else
disp('only one subject at a time')
return
end
sdir = getenv('SUBJECTS_DIR');
hemi = {'lh','rh'};
outpath = which('ntools_elec');
outpath = fileparts(outpath);
for i=1:length(hemi)
fname = ['label/',hemi{i},'.aparc.split_STG_MTG.annot'];
outfile = fullfile(sdir,subj,fname);
cmd = sprintf('mris_divide_parcellation %s %s aparc.annot %s %s',...
subj,hemi{i},fullfile(outpath,'splittable_STG_MTG.txt'),outfile);
[status,msg] = unix(cmd);
if status, disp(msg); continue; end
[vertices, label, colortable] = read_annotation(outfile);
% change colortable.struct_names
colortable.struct_names = regexprep(colortable.struct_names,'superiortemporal_div1','cSTG');
colortable.struct_names = regexprep(colortable.struct_names,'superiortemporal_div2','mSTG');
colortable.struct_names = regexprep(colortable.struct_names,'superiortemporal_div3','rSTG');
colortable.struct_names = regexprep(colortable.struct_names,'middletemporal_div1','cMTG');
colortable.struct_names = regexprep(colortable.struct_names,'middletemporal_div2','mMTG');
colortable.struct_names = regexprep(colortable.struct_names,'middletemporal_div3','rMTG');
% change colortable.table
idx1 = find(strcmp(colortable.struct_names,'mSTG'));
mSTG_id = colortable.table(idx1,5);
colortable.table(idx1,1:3) = [24,200,24];
colortable.table(idx1,5) = colortable.table(idx1,1:4)*[1;2^8;2^16;2^24];
idx2 = find(strcmp(colortable.struct_names,'mMTG'));
mMTG_id = colortable.table(idx2,5);
colortable.table(idx2,1:3) = [110,160,220];
colortable.table(idx2,5) = colortable.table(idx2,1:4)*[1;2^8;2^16;2^24];
% replace ID in label
label(label==mSTG_id) = colortable.table(idx1,5);
label(label==mMTG_id) = colortable.table(idx2,5);
% replace ID in vertices
vertices(vertices==mSTG_id) = colortable.table(idx1,5);
vertices(vertices==mMTG_id) = colortable.table(idx2,5);
% save new annotation
write_annotation(outfile,vertices,label,colortable);
end