Home > vbmeg > functions > brain > vb_import_fsannot_file.m

vb_import_fsannot_file

PURPOSE ^

Import FreeSurfer annotation file.

SYNOPSIS ^

function vb_import_fsannot_file(brain_file,atlas_id,antl_file,antr_file, prefix)

DESCRIPTION ^

 Import FreeSurfer annotation file. 

 [syntax]
 vb_import_fsannot_file(brain_file,area_file,antl_file,antr_file)

 [input]
 brain_file: <<string>> Cortical surface model file (.brain.mat).
 atlas_id  : <<string>> Cortical area file (.area.mat)
 antl_file : <<string>> FS annotation file for lh.
 antr_file : <<string>> FS annotation file for rh.
 prefix    : <<int>>    optional
                        (deafult) = 0 : none is added to the area/act name.
                                  = 1 : lh_/rh_ is added to the area/act name.
                                  
 [output]
 Cortical areas are stored into the cortical area file. These areas are
 associated with labels defined with FS. 

 [example]
 >> brain_file = '3D.brain.mat';
 >> atlas_id   = 'Destrieux';
 >> antl_file  = 'lh.aparc.a2009s.annot';
 >> antr_file  = 'rh.aparc.a2009s.annot';
 >> vb_import_fsannot_file(brain_file,atlas_id,antl_file,antr_file)

 [history]
 2011-06-17 taku-y
 2012-02-20 taku-y
  [debug] Due to using information in fsannot file without modification,
          color value could be out of range from 0.0 to 1.0. taken
          directly from fsannot file. This bug has been fixed. 
 2019-10-07 rhayashi
          atlas_id is added to make both area file and act file.
 2021-3-01 rhayashi
          prefix argument is added.

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function vb_import_fsannot_file(brain_file,atlas_id,antl_file,antr_file, prefix)
0002 % Import FreeSurfer annotation file.
0003 %
0004 % [syntax]
0005 % vb_import_fsannot_file(brain_file,area_file,antl_file,antr_file)
0006 %
0007 % [input]
0008 % brain_file: <<string>> Cortical surface model file (.brain.mat).
0009 % atlas_id  : <<string>> Cortical area file (.area.mat)
0010 % antl_file : <<string>> FS annotation file for lh.
0011 % antr_file : <<string>> FS annotation file for rh.
0012 % prefix    : <<int>>    optional
0013 %                        (deafult) = 0 : none is added to the area/act name.
0014 %                                  = 1 : lh_/rh_ is added to the area/act name.
0015 %
0016 % [output]
0017 % Cortical areas are stored into the cortical area file. These areas are
0018 % associated with labels defined with FS.
0019 %
0020 % [example]
0021 % >> brain_file = '3D.brain.mat';
0022 % >> atlas_id   = 'Destrieux';
0023 % >> antl_file  = 'lh.aparc.a2009s.annot';
0024 % >> antr_file  = 'rh.aparc.a2009s.annot';
0025 % >> vb_import_fsannot_file(brain_file,atlas_id,antl_file,antr_file)
0026 %
0027 % [history]
0028 % 2011-06-17 taku-y
0029 % 2012-02-20 taku-y
0030 %  [debug] Due to using information in fsannot file without modification,
0031 %          color value could be out of range from 0.0 to 1.0. taken
0032 %          directly from fsannot file. This bug has been fixed.
0033 % 2019-10-07 rhayashi
0034 %          atlas_id is added to make both area file and act file.
0035 % 2021-3-01 rhayashi
0036 %          prefix argument is added.
0037 
0038 
0039 %%%%%%%%%%%%%%%%%%%
0040 % filename prepare
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 % start importing
0067 
0068 % load .brain.mat
0069 [Nvertex, tmp2, BV_index, Vinfo] = vb_load_cortex_info(brain_file, 'subj');
0070 Ncortex = length([Vinfo.cortexL; Vinfo.cortexR]);
0071 
0072 % load annotation file for lh
0073 [v,l,c] = read_annotation(antl_file);
0074 
0075 % make label data that of VBMEG brain model for lh
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 % make area for lh
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   % here it is assumed that the maximal color value is 255.
0099   % 2012-02-20 taku-y
0100   Area.clr = (Area.clr)./255;
0101   
0102   vb_add_area(save_areafile,Area);
0103 end
0104 
0105 % load annotation file for rh
0106 [v,l,c] = read_annotation(antr_file);
0107 
0108 % make label data that of VBMEG brain model for lh
0109 [tmp,ix1,ix2] = intersect(BV_index.Right,v+Ileft0+1);
0110 l = l(ix2);
0111 l(ix1) = l;
0112 
0113 %
0114 % make area for rh
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   % here it is assumed that the maximal color value is 255.
0128   % 2012-02-20 taku-y
0129   Area.clr = (Area.clr)./255;
0130 
0131   vb_add_area(save_areafile,Area);
0132 end
0133 
0134 %
0135 % make act file(.act.mat)
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); % set area number to xxP
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;

Generated on Mon 22-May-2023 06:53:56 by m2html © 2005