Home > vbmeg > functions > job > subdirectory > vb_job_brain_subj.m

vb_job_brain_subj

PURPOSE ^

Make whole brain data (cortex sheet) by reducing BV/FS surface data.

SYNOPSIS ^

function [V,F,xx,BV_index,Vinfo] = vb_job_brain_subj(proj_root,brain_parm, mode)

DESCRIPTION ^

 Make whole brain data (cortex sheet) by reducing BV/FS surface data.
 (VBMEG public function)

 [syntax]
 vb_job_brain_subj(proj_root,brain_parm);

 [input]
 proj_root : <<string>> VBMEG project root directory. 
 brain_parm: <<struct>> Parameters for creating cortical surface model
 --- fields of brain_parm
 analyze_file: <<string>> MRI filename (.nii/.hdr)
 brain_parm.FS_left_file         = [fs_dir '/bem/lh.smoothwm.asc'];
 brain_parm.FS_right_file        = [fs_dir '/bem/rh.smoothwm.asc'];
 brain_parm.FS_left_infl_file    = [fs_dir '/bem/lh.inflated.asc'];
 brain_parm.FS_right_infl_file   = [fs_dir '/bem/rh.inflated.asc'];
 brain_parm.FS_left_curv_file    = [fs_dir '/bem/lh.curv.asc'];
 brain_parm.FS_right_curv_file   = [fs_dir '/bem/rh.curv.asc'];
 brain_parm.FS_left_label_file  = [fs_dir '/label/lh.cortex.label'];
 brain_parm.FS_right_label_file = [fs_dir '/label/rh.cortex.label'];
 
 brain_parm.FS_left_sphere_file  = [fs_dir,  'lh.sphere.reg.asc'];
 brain_parm.FS_right_sphere_file = [fs_dir,  'rh.sphere.reg.asc'];
 brain_parm.FS_sphere_key        = 'sphere.reg';

  brain_file  : <<string>> Cortical surface model file (.brain.mat).
  act_file    : <<string>> Cortical activity map file (.act.mat).
  area_file   : <<string>> Cortical area file (.area.mat).
  Nvertex     : <<int>>    Total number of vertices for cortical surface model
                           Priority: Nvertex > reduce_ratio
  Rmax        : <<float>>  Maximum radius for neighbor search 
  N_step      : <<int>>    Division number of z axis in matching between
                           cortical surface model and MRI points
  display     : <<int>>    Display progress for this steps
  
  (parameters for BrainVoyager cortical surface model) <<string>>
  BV_left_file      : GM/WM boundary file (.srf) for left hemisphere 
  BV_right_file     : GM/WM boundary file (.srf) for right hemisphere 
  
 ---
 
 [output]
 The following files are created: 
  VBMEG cortical surface model file (.brain.mat)
  VBMEG area file (.area.mat)
  VBMEG activity map file (.act.mat)

 The following variables are stored in .brain.mat file: 
 V         : Cortical vertex point cordinate (SPM_Right_m) 
 F         : Patch index structure
 xx        : Normal vector to cortical surface 
 xxA       : area asigned for each vertex ([m^2])

 BV_index  : original vertex index in BV/FS corresponding to brain
 Vinfo     : Vertex dimension structure

 xxF{i}    : Next-neighbor index for the vertex-i
 xxD{i}    : Distance between next-neighbor and the vertex-i
 xxT{n}    : vertex index for n-th triangle
 nextIX{i} : Neighbor index list for the vertex-i
 nextDD{i} : Distance from the vertex-i
 
 The following areas are automatically created and stored in .area.mat
 file: 
 areakey = 'Cortex'         : whole brain
 areakey = 'cortex_region'  : cortex region without corpus area
 areakey = 'corpus_area'    : corpus area

 [history]
 Line 117 was modified by Kawawaki, Dai at 06/04/07
 2006/07/21 M. Sato 
  Make reduced cortex for soft normal constraint
 2007/03/05 O. Yamashita
  Add lines to compute MNI and Talairach coordinate and two area files
  derived from anatomical divisions. These lines are only valid when 
  spm_normalization_file is specified.
 2008-12-24 Taku Yoshioka
  Reduce model supression mode
  vb_disp() is used for displaying message
  Show figures for checking standard brain mask
 2010-05-28 Taku Yoshioka
  Minor change
 2011-01-28 rhayashi
  call vb_job_inflate() when brain_parm have fields for inflate model.
 2017-03-14 rhayashi
  exclude corpus area from 'Cortex'. 
 Copyright (C) 2011, ATR All Rights Reserved.
 License : New BSD License(see VBMEG_LICENSE.txt)

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

0001 function [V,F,xx,BV_index,Vinfo] = vb_job_brain_subj(proj_root,brain_parm, mode)
0002 % Make whole brain data (cortex sheet) by reducing BV/FS surface data.
0003 % (VBMEG public function)
0004 %
0005 % [syntax]
0006 % vb_job_brain_subj(proj_root,brain_parm);
0007 %
0008 % [input]
0009 % proj_root : <<string>> VBMEG project root directory.
0010 % brain_parm: <<struct>> Parameters for creating cortical surface model
0011 % --- fields of brain_parm
0012 % analyze_file: <<string>> MRI filename (.nii/.hdr)
0013 % brain_parm.FS_left_file         = [fs_dir '/bem/lh.smoothwm.asc'];
0014 % brain_parm.FS_right_file        = [fs_dir '/bem/rh.smoothwm.asc'];
0015 % brain_parm.FS_left_infl_file    = [fs_dir '/bem/lh.inflated.asc'];
0016 % brain_parm.FS_right_infl_file   = [fs_dir '/bem/rh.inflated.asc'];
0017 % brain_parm.FS_left_curv_file    = [fs_dir '/bem/lh.curv.asc'];
0018 % brain_parm.FS_right_curv_file   = [fs_dir '/bem/rh.curv.asc'];
0019 % brain_parm.FS_left_label_file  = [fs_dir '/label/lh.cortex.label'];
0020 % brain_parm.FS_right_label_file = [fs_dir '/label/rh.cortex.label'];
0021 %
0022 % brain_parm.FS_left_sphere_file  = [fs_dir,  'lh.sphere.reg.asc'];
0023 % brain_parm.FS_right_sphere_file = [fs_dir,  'rh.sphere.reg.asc'];
0024 % brain_parm.FS_sphere_key        = 'sphere.reg';
0025 %
0026 %  brain_file  : <<string>> Cortical surface model file (.brain.mat).
0027 %  act_file    : <<string>> Cortical activity map file (.act.mat).
0028 %  area_file   : <<string>> Cortical area file (.area.mat).
0029 %  Nvertex     : <<int>>    Total number of vertices for cortical surface model
0030 %                           Priority: Nvertex > reduce_ratio
0031 %  Rmax        : <<float>>  Maximum radius for neighbor search
0032 %  N_step      : <<int>>    Division number of z axis in matching between
0033 %                           cortical surface model and MRI points
0034 %  display     : <<int>>    Display progress for this steps
0035 %
0036 %  (parameters for BrainVoyager cortical surface model) <<string>>
0037 %  BV_left_file      : GM/WM boundary file (.srf) for left hemisphere
0038 %  BV_right_file     : GM/WM boundary file (.srf) for right hemisphere
0039 %
0040 % ---
0041 %
0042 % [output]
0043 % The following files are created:
0044 %  VBMEG cortical surface model file (.brain.mat)
0045 %  VBMEG area file (.area.mat)
0046 %  VBMEG activity map file (.act.mat)
0047 %
0048 % The following variables are stored in .brain.mat file:
0049 % V         : Cortical vertex point cordinate (SPM_Right_m)
0050 % F         : Patch index structure
0051 % xx        : Normal vector to cortical surface
0052 % xxA       : area asigned for each vertex ([m^2])
0053 %
0054 % BV_index  : original vertex index in BV/FS corresponding to brain
0055 % Vinfo     : Vertex dimension structure
0056 %
0057 % xxF{i}    : Next-neighbor index for the vertex-i
0058 % xxD{i}    : Distance between next-neighbor and the vertex-i
0059 % xxT{n}    : vertex index for n-th triangle
0060 % nextIX{i} : Neighbor index list for the vertex-i
0061 % nextDD{i} : Distance from the vertex-i
0062 %
0063 % The following areas are automatically created and stored in .area.mat
0064 % file:
0065 % areakey = 'Cortex'         : whole brain
0066 % areakey = 'cortex_region'  : cortex region without corpus area
0067 % areakey = 'corpus_area'    : corpus area
0068 %
0069 % [history]
0070 % Line 117 was modified by Kawawaki, Dai at 06/04/07
0071 % 2006/07/21 M. Sato
0072 %  Make reduced cortex for soft normal constraint
0073 % 2007/03/05 O. Yamashita
0074 %  Add lines to compute MNI and Talairach coordinate and two area files
0075 %  derived from anatomical divisions. These lines are only valid when
0076 %  spm_normalization_file is specified.
0077 % 2008-12-24 Taku Yoshioka
0078 %  Reduce model supression mode
0079 %  vb_disp() is used for displaying message
0080 %  Show figures for checking standard brain mask
0081 % 2010-05-28 Taku Yoshioka
0082 %  Minor change
0083 % 2011-01-28 rhayashi
0084 %  call vb_job_inflate() when brain_parm have fields for inflate model.
0085 % 2017-03-14 rhayashi
0086 %  exclude corpus area from 'Cortex'.
0087 % Copyright (C) 2011, ATR All Rights Reserved.
0088 % License : New BSD License(see VBMEG_LICENSE.txt)
0089 
0090 const = vb_define_verbose;
0091 VERBOSE_LEVEL_NOTICE = const.VERBOSE_LEVEL_NOTICE;
0092 
0093 % Set BV-SPM version (mode = 0 : SBI-compatible)
0094 if ~exist('mode','var'), mode = 1; end;
0095 
0096 proj_root = vb_rm_trailing_slash(proj_root);
0097 
0098 %
0099 % Do not modify following lines
0100 %
0101 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0102 %
0103 
0104 % Output file path
0105 brain_file = [proj_root filesep brain_parm.brain_file];
0106 area_file  = [proj_root filesep brain_parm.area_file ];
0107 act_file   = [proj_root filesep brain_parm.act_file  ];
0108 
0109 % ID for MRI image data
0110 [udir, fname] = vb_get_file_parts(brain_parm.analyze_file);
0111 MRI_ID = fname;
0112 
0113 %-------------------------------------------------------
0114 % Make cortex coordinate from Brain-Voyager srf-file
0115 %-------------------------------------------------------
0116 switch    mode
0117 case    0
0118     % BV-Vox-SPM version (SBI-compatible)
0119     [V,F,xx,BV_index,Vinfo] = vb_make_brain_data(brain_parm);
0120     DEBUG_MODE = 0;
0121 case    1
0122     % BV-SPM version
0123     [V,F,xx,BV_index,Vinfo] = vb_make_brain_data2(brain_parm);
0124     DEBUG_MODE = 0;
0125 case    2
0126     % BV-Vox-SPM version (SBI-compatible)
0127     [V,F,xx,BV_index,Vinfo] = vb_make_brain_data(brain_parm);
0128     DEBUG_MODE = 2;
0129 case    3
0130     % BV-SPM version
0131     [V,F,xx,BV_index,Vinfo] = vb_make_brain_data2(brain_parm);
0132     DEBUG_MODE = 2;
0133 end
0134 
0135 if DEBUG_MODE==2, return; end;
0136 
0137 %----------------------------------------
0138 % Search next-point index and distance
0139 %----------------------------------------
0140 tic;
0141 vb_disp_nonl('Search next-point index and distance ', ...
0142         VERBOSE_LEVEL_NOTICE);
0143 
0144 [xxD, xxF, xxT] = vb_next_distance( F.F3, V ); % unit : m
0145 
0146 vb_disp(sprintf('%f[sec]',toc), VERBOSE_LEVEL_NOTICE);
0147 
0148 % total number of vertex
0149 Ndipole = Vinfo.Ndipole;
0150 Vindx   = 1:Ndipole;
0151 
0152 %---------------------------------------
0153 % Smoothing normal vectors (Double mean)
0154 %---------------------------------------
0155 tic
0156 vb_disp_nonl('Mean of patch normal ', VERBOSE_LEVEL_NOTICE);
0157 
0158 % Mean of normal vector for neighboring patch
0159 xx = vb_mean_normal_vector_1(Vindx ,F,V,xx);
0160 % Mean of normal vector for neighbor vertex
0161 xx = vb_mean_normal_vector_4(Vindx ,F,V,xx,xxF);
0162 
0163 vb_disp(sprintf('%f[sec]',toc), VERBOSE_LEVEL_NOTICE);
0164 
0165 %----------------------------------------------
0166 % Calculate area assigned to the vertex
0167 %----------------------------------------------
0168 tic; 
0169 [xxA] = vb_calc_patch_area(V, F.F3, xxT);
0170 vb_disp(sprintf('%f[sec]',toc), VERBOSE_LEVEL_NOTICE);
0171 
0172 %
0173 % Save cortical surface model
0174 %
0175 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0176 vb_disp(['Save brain model '], VERBOSE_LEVEL_NOTICE);
0177 vb_disp(sprintf('     filename = %s', brain_file), ...
0178         VERBOSE_LEVEL_NOTICE);
0179 vb_save([brain_file],...
0180      'F','V','xx','xxF','xxD','xxA','Vinfo','BV_index','MRI_ID');
0181 
0182 if DEBUG_MODE==1, return; end;
0183 
0184 %----------------------------------------------
0185 % Search neighbor points along cortex sheet
0186 %----------------------------------------------
0187 Rmax    = brain_parm.R_max; 
0188 Display = brain_parm.display;
0189 
0190 [nextIX , nextDD] = vb_find_neighbor_all(Rmax, xxF, xxD, Vindx, Display);
0191 
0192 vb_disp('Save neighbor index of cortical vertex', ...
0193         VERBOSE_LEVEL_NOTICE);
0194 vb_save([brain_file],'nextIX','nextDD');
0195 
0196 %--------------------------------------------------------------------------
0197 % Calculate MNI coordinate and Talairach coordinate and
0198 % two area files derived from two anatomical divisons (added by OY 07/03/05)
0199 %--------------------------------------------------------------------------
0200 mni_calculation = ...
0201     (isfield(brain_parm, 'spm_normalization_file') ...
0202       && ~isempty(brain_parm.spm_normalization_file)) ...
0203    ||(isfield(brain_parm, 'FS_left_sphere_file') ... 
0204       && ~isempty(brain_parm.FS_left_sphere_file) && ...
0205     isfield(brain_parm, 'FS_right_sphere_file') ...
0206       && ~isempty(brain_parm.FS_right_sphere_file));
0207 
0208 if mni_calculation
0209   atlas_dir = 'MNI_atlas_templates/';
0210   EXT_brain = '.brain.mat';
0211   brain_id       = brain_file(1:findstr(brain_file,EXT_brain)-1);
0212     
0213   %% MNI coordinate
0214   tic 
0215     % Computing MNI and Talairach coordinate
0216     vb_job_brain_add_mni_tal_coord(proj_root, brain_parm, false);
0217 
0218     %% AAL atlas
0219     tic 
0220     mniparm.brainfile  = brain_file;
0221     vb_disp_nonl(['Creating an area file consisting of AAL anatomical' ...
0222              'division: '], VERBOSE_LEVEL_NOTICE);
0223     atlas_id = 'aal';
0224     
0225     mniparm.atlas_text = [atlas_dir atlas_id '.txt'];
0226     mniparm.atlas_file = [atlas_dir atlas_id '.img'];
0227     mniparm.atlas_id   = atlas_id;
0228     mniparm.atlas_dir  = atlas_dir;
0229 
0230 
0231     mniparm.save_areafile  = [brain_id  '_'  atlas_id  '.area.mat'];
0232     mniparm.save_atlasfile = [brain_id  '_atlas.act.mat'];    % Atlas label
0233 
0234     vb_atlas2vb_aal(mniparm)
0235     
0236     vb_disp_nonl(sprintf('Done...%f[sec]\n\n',toc));   
0237 
0238     
0239     %% Brodmann atlas
0240     tic 
0241     vb_disp_nonl(['Creating an area file consisting of Brodmann ' ...
0242              'anatomical division: ']);
0243     
0244     atlas_id = 'brodmann';
0245     
0246     mniparm.atlas_text = [atlas_dir atlas_id '.txt'];
0247     mniparm.atlas_file = [atlas_dir atlas_id '.img'];
0248     mniparm.atlas_id   = atlas_id;
0249 
0250     mniparm.save_areafile  = [brain_id  '_'  atlas_id  '.area.mat'];
0251 
0252     vb_atlas2vb(mniparm)
0253 
0254     vb_disp_nonl(sprintf('Done...%f[sec]\n\n',toc), VERBOSE_LEVEL_NOTICE);
0255 else 
0256     vb_disp('MNI and Talairach coordinate are not computed.', ...
0257             VERBOSE_LEVEL_NOTICE);
0258     vb_disp(['You can obtain MNI and Talairach coordinate by ' ...
0259              'running vb_atlas2vb.m later '], VERBOSE_LEVEL_NOTICE);
0260 end
0261 
0262 %--------------------------------------
0263 % Make new area and act files
0264 %--------------------------------------
0265 act_new.key     = 'Uniform';
0266 act_new.xxP     = ones(Ndipole,1);
0267 act_new.comment = 'homogeneous fMRI constraint';
0268 
0269 vb_add_act([act_file], act_new, MRI_ID, OFF);
0270 
0271 % Make Area file
0272 Vindx  = [Vinfo.cortexL; Vinfo.cortexR];
0273 AreaNew.key      = 'Cortex';
0274 AreaNew.Iextract = Vindx; % rhayashi 2017/3/14
0275 
0276 vb_add_area([area_file], AreaNew, MRI_ID, OFF);
0277 
0278 %---------------------------------------------------
0279 % Find original vertex near the cortical vertex
0280 %---------------------------------------------------
0281 normal_stat = vb_original_normal_statics(proj_root,brain_parm, BV_index);
0282 
0283 vb_disp('Save neighbor statics in the original brain', ...
0284         VERBOSE_LEVEL_NOTICE);
0285 vb_save(brain_file,'normal_stat');
0286 
0287 %--------------------------
0288 % Make reduced cortex
0289 %--------------------------
0290 if isfield(brain_parm,'make_reduce') & brain_parm.make_reduce, 
0291   vb_job_reduced_cortex(proj_root,brain_parm);
0292 end
0293 
0294 %--------------------------
0295 % Import inflate model
0296 %--------------------------
0297 if has_inflate_model(brain_parm)
0298   vb_job_inflate(proj_root, brain_parm);
0299 end
0300 
0301 %-----------------------------------------
0302 % Check brain model by 3D & MRI image
0303 %-----------------------------------------
0304 vb_check_brain_model(proj_root,brain_parm);
0305 
0306 %--------------------------
0307 % Save project file
0308 %--------------------------
0309 proj_file = get_project_filename;
0310 if ~isempty(proj_file)
0311     project_file_mgr('load', proj_file);
0312     project_file_mgr('add', 'brain_parm', brain_parm, 'vb_job_brain');
0313 end
0314 
0315 % Plot MNI calculation result
0316 % if mni_calculation
0317 %     try
0318 %         vb_check_mni_coregistration(brain_file);
0319 %     catch
0320 %         vb_disp(['Failed to plot MNI coordinate value(Out of Memory)', ...
0321 %                  'try again: vb_check_mni_coregistration(brain_file)'], ....
0322 %                  'WARNING');
0323 %
0324 %     end
0325 % end
0326 
0327 return;
0328 
0329 function [result] = has_inflate_model(brain_parm)
0330 % Check if brain_parm contains valid fields for inflate model.
0331 % result : return bit pattern
0332 %          = 01(1 as int): BV inflate data is set.
0333 %          = 10(2 as int): FS inflate data is set.
0334 %          = 11(3 as int): Both inflate model were set
0335 result = 0;
0336 BV_BIT = 1; FS_BIT = 2;
0337 % bit all on
0338 result = bitset(result, BV_BIT, 1);
0339 result = bitset(result, FS_BIT, 1);
0340 
0341 BV_fields = {'BV_left_infl_file', 'BV_right_infl_file'};
0342 FS_fields = {'FS_left_infl_file',  'FS_right_infl_file', ...
0343              'FS_left_curv_file', 'FS_right_curv_file'};
0344 for k=1:length(BV_fields)
0345   if ~isfield(brain_parm, BV_fields{k}) || ...
0346      exist(brain_parm.(BV_fields{k}), 'file') ~= 2
0347     % bit off
0348     result = bitset(result, BV_BIT, 0);
0349     break;
0350   end
0351 end
0352 for k=1:length(FS_fields)
0353   if ~isfield(brain_parm, FS_fields{k}) || ...
0354      exist(brain_parm.(FS_fields{k}), 'file') ~= 2
0355     % bit off
0356     result = bitset(result, FS_BIT, 0);
0357     break;
0358   end
0359 end

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