0001 function vb_import_fsannot_file(brain_file,atlas_id,antl_file,antr_file, prefix)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036
0037
0038
0039
0040
0041 EXT_brain = '.brain.mat';
0042 brain_id = brain_file(1:findstr(brain_file,EXT_brain)-1);
0043
0044 save_areafile = [brain_id '_' atlas_id '.area.mat'];
0045 save_atlasfile = [brain_id '_' atlas_id '.act.mat'];
0046
0047 if exist(save_atlasfile,'file')
0048 delete(save_atlasfile);
0049 end
0050 if exist(save_areafile,'file')
0051 delete(save_areafile);
0052 end
0053
0054 if ~exist('prefix', 'var')
0055 prefix = 0;
0056 end
0057 if prefix
0058 prefix_l = 'lh_';
0059 prefix_r = 'rh_';
0060 else
0061 prefix_l = '';
0062 prefix_r = '';
0063 end
0064
0065
0066
0067
0068
0069 [Nvertex, tmp2, BV_index, Vinfo] = vb_load_cortex_info(brain_file, 'subj');
0070 Ncortex = length([Vinfo.cortexL; Vinfo.cortexR]);
0071
0072
0073 [v,l,c] = read_annotation(antl_file);
0074
0075
0076 [tmp,ix1,ix2] = intersect(BV_index.Left,v+1);
0077 l = l(ix2);
0078 l(ix1) = l;
0079 Ileft0 = length(v);
0080 Ileft = length(BV_index.Left);
0081
0082
0083
0084
0085
0086
0087 for i=1:c.numEntries
0088 ix = find(l==c.table(i,5));
0089 if ~isempty(strfind(c.struct_names{i}, 'FreeSurfer_Defined_Medial_Wall')) || ...
0090 strcmpi(c.struct_names{i}, 'Unknown') || ...
0091 isempty(ix)
0092 continue;
0093 end
0094 Area.key = [prefix_l c.struct_names{i}];
0095 Area.Iextract = ix;
0096 Area.clr = c.table(i,1:3);
0097
0098
0099
0100 Area.clr = (Area.clr)./255;
0101
0102 vb_add_area(save_areafile,Area);
0103 end
0104
0105
0106 [v,l,c] = read_annotation(antr_file);
0107
0108
0109 [tmp,ix1,ix2] = intersect(BV_index.Right,v+Ileft0+1);
0110 l = l(ix2);
0111 l(ix1) = l;
0112
0113
0114
0115
0116 for i=1:c.numEntries
0117 ix = find(l==c.table(i,5))+Ileft;
0118 if ~isempty(strfind(c.struct_names{i}, 'FreeSurfer_Defined_Medial_Wal')) || ...
0119 strcmpi(c.struct_names{i}, 'Unknown') || ...
0120 isempty(ix)
0121 continue;
0122 end
0123 Area.key = [prefix_r c.struct_names{i}];
0124 Area.Iextract = ix;
0125 Area.clr = c.table(i,1:3);
0126
0127
0128
0129 Area.clr = (Area.clr)./255;
0130
0131 vb_add_area(save_areafile,Area);
0132 end
0133
0134
0135
0136
0137 keyset = vb_get_keyset_area(save_areafile);
0138 load(save_areafile,'Area');
0139
0140 act = struct;
0141 act.key = atlas_id;
0142 act.xxP = zeros(Nvertex, 1);
0143 act.label = 1:length(keyset);
0144 act.label_name = keyset;
0145 for k=1:length(act.label)
0146 act.xxP(Area{k}.Iextract) = act.label(k);
0147 end
0148 vb_add_act(save_atlasfile, act, [], false);
0149
0150 fprintf('Save the area file as "%s" \n', save_areafile);
0151 fprintf('Save the act file as "%s" \n', save_atlasfile);
0152
0153 fprintf('# of all vertex = %d\n',Nvertex);
0154 fprintf('# of cortex points = %d\n',Ncortex);
0155 fprintf('# of areas = %d\n',length(keyset));
0156
0157
0158
0159 return;