Home > vbmeg > functions > brain > vb_make_brain_data.m

vb_make_brain_data

PURPOSE ^

Make cortex data from BrainVoyager/FreeSurfer files

SYNOPSIS ^

function [V,F,xx,BV_index,Vinfo] = vb_make_brain_data(brain_parm);

DESCRIPTION ^

 Make cortex data from BrainVoyager/FreeSurfer files
   [V,F,xx,ORG_index,Vinfo] = vb_make_brain_data(brain_parm)

 ---
 BrainVoyagerまたはFreeSurfer脳データの解像度を下げて全脳データを作る

--- Input

 brain_parm        : structure with following field
  (used for BrainVoyager files)
    .BV_left_file   : Brain-Voyager left  surface file
    .BV_right_file  : Brain-Voyager right surface file

  (used for FreeSurfer files)
    .FS_left_file   : FreeSurfer left surface file
    .FS_right_file  : FreeSurfer right surface file
    .FS_xfm_file    : Talairach transformation file

    .analyze_file   : MRI analyze file
    .reduce_ratio   : ratio of reducing vertex points
         BV皮質モデルからVBMEG脳モデルを作成するときの頂点数の削減率
    .N_step         : Division number in searching match points
         頂点対応探索時のZ軸方向分割数
 
--- Output
 
 V     : Cortical vertex point cordinate (SPM_Right_m) [Nvertex, 3]
          頂点位置 ( 頂点の数, 3)
 xx    : Normal vector to cortical surface   [Nvertex, 3]
           頂点の法線方向と位置( 頂点の数, 3)
 F      : Patch index structure
           面(3角形)を構成する3つの頂点番号 ( 面の数, 3)  
  .F3R     : Right cortex
  .F3L     : Left  cortex
  .F3     : Left + Right
 BV_index  : original vertex index in BV corresponding to brain
    .Left     : Left  brain
    .Right    : Right brain
 Vinfo        : Vertex dimension structure
   .Ndipole   : # of vertex
   .NdipoleL  : # of vertex in Left cortex
   .Npatch    : # of patch
   .Coord     = 'SPM_Right_m';

 Originaly written by S.Kajihara
 Ver 1.1  modified by M. Sato  2003-4-15

 Modified by Taku Yoshioka
 2003-07-11 
 ・ファイルに保存するデータ構造を変更
 ・メッセージを少し変更
 2003-07-29
 ・座標変換時のオフセットを切替えられるように変更
 2003-10-08
 ・MRI-Voxel座標データを保存(元の仕様)


 2005-03-20 Modified by TY

 Ver 2.0  modified by M. Sato  2005-4-8
  座標系をSPM右手座標に変換する
   Analyze ファイルが必要
   (DICOM イメージファイルは不要)

 modified by M. Sato  2005-8-1
   Vinfo 追加
 modified by M. Sato  2005-8-9
   パラメタと変数名の大幅見直し変更
 2008-10-16 Taku Yoshioka
   Non-XFM file support for FreeSurfer ver. 4.0

 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:

SOURCE CODE ^

0001 function [V,F,xx,BV_index,Vinfo] = vb_make_brain_data(brain_parm);
0002 % Make cortex data from BrainVoyager/FreeSurfer files
0003 %   [V,F,xx,ORG_index,Vinfo] = vb_make_brain_data(brain_parm)
0004 %
0005 % ---
0006 % BrainVoyagerまたはFreeSurfer脳データの解像度を下げて全脳データを作る
0007 %
0008 %--- Input
0009 %
0010 % brain_parm        : structure with following field
0011 %  (used for BrainVoyager files)
0012 %    .BV_left_file   : Brain-Voyager left  surface file
0013 %    .BV_right_file  : Brain-Voyager right surface file
0014 %
0015 %  (used for FreeSurfer files)
0016 %    .FS_left_file   : FreeSurfer left surface file
0017 %    .FS_right_file  : FreeSurfer right surface file
0018 %    .FS_xfm_file    : Talairach transformation file
0019 %
0020 %    .analyze_file   : MRI analyze file
0021 %    .reduce_ratio   : ratio of reducing vertex points
0022 %         BV皮質モデルからVBMEG脳モデルを作成するときの頂点数の削減率
0023 %    .N_step         : Division number in searching match points
0024 %         頂点対応探索時のZ軸方向分割数
0025 %
0026 %--- Output
0027 %
0028 % V     : Cortical vertex point cordinate (SPM_Right_m) [Nvertex, 3]
0029 %          頂点位置 ( 頂点の数, 3)
0030 % xx    : Normal vector to cortical surface   [Nvertex, 3]
0031 %           頂点の法線方向と位置( 頂点の数, 3)
0032 % F      : Patch index structure
0033 %           面(3角形)を構成する3つの頂点番号 ( 面の数, 3)
0034 %  .F3R     : Right cortex
0035 %  .F3L     : Left  cortex
0036 %  .F3     : Left + Right
0037 % BV_index  : original vertex index in BV corresponding to brain
0038 %    .Left     : Left  brain
0039 %    .Right    : Right brain
0040 % Vinfo        : Vertex dimension structure
0041 %   .Ndipole   : # of vertex
0042 %   .NdipoleL  : # of vertex in Left cortex
0043 %   .Npatch    : # of patch
0044 %   .Coord     = 'SPM_Right_m';
0045 %
0046 % Originaly written by S.Kajihara
0047 % Ver 1.1  modified by M. Sato  2003-4-15
0048 %
0049 % Modified by Taku Yoshioka
0050 % 2003-07-11
0051 % ・ファイルに保存するデータ構造を変更
0052 % ・メッセージを少し変更
0053 % 2003-07-29
0054 % ・座標変換時のオフセットを切替えられるように変更
0055 % 2003-10-08
0056 % ・MRI-Voxel座標データを保存(元の仕様)
0057 %
0058 %
0059 % 2005-03-20 Modified by TY
0060 %
0061 % Ver 2.0  modified by M. Sato  2005-4-8
0062 %  座標系をSPM右手座標に変換する
0063 %   Analyze ファイルが必要
0064 %   (DICOM イメージファイルは不要)
0065 %
0066 % modified by M. Sato  2005-8-1
0067 %   Vinfo 追加
0068 % modified by M. Sato  2005-8-9
0069 %   パラメタと変数名の大幅見直し変更
0070 % 2008-10-16 Taku Yoshioka
0071 %   Non-XFM file support for FreeSurfer ver. 4.0
0072 %
0073 % Copyright (C) 2011, ATR All Rights Reserved.
0074 % License : New BSD License(see VBMEG_LICENSE.txt)
0075 
0076 error('This function is a canditate to be removed, but invoked.');
0077 
0078 global vbmeg_inst;
0079 define = vbmeg_inst.const;
0080 
0081 % Define constant
0082 TRANS_COORDINATE = 0;
0083 TRANS_NORMAL     = 1;
0084 
0085 % V0L/R  Brain-Voyager coordinate
0086 % n0L/R  inward-normal unit vector
0087 % FOL/R  triangle patch
0088 tic; 
0089 if isfield(brain_parm,'BV_left_file') & ...
0090       ~isempty(brain_parm.BV_left_file),
0091   %
0092   % --- Brain-Voyager coordinate
0093   %
0094   % [Left-hand coordinate]
0095   % X:Front(0) -> Back(255)
0096   % Y:Top(0)   -> Bottom(255)
0097   % Z:Right(0) -> Left(255)
0098   fprintf('\n--- Make brain model using BrainVoyager SRF files ');
0099   filetype = 'BrainVoyager'; 
0100   
0101   Srf = vb_ScriptLoadSRF(brain_parm.BV_left_file);
0102   V0L = [Srf.VertexX, Srf.VertexY, Srf.VertexZ]; 
0103   n0L = [Srf.NormalX, Srf.NormalY, Srf.NormalZ]; 
0104   F0L = Srf.Triangles+1;
0105 
0106   Srf = vb_ScriptLoadSRF(brain_parm.BV_right_file);
0107   V0R = [Srf.VertexX, Srf.VertexY, Srf.VertexZ]; 
0108   n0R = [Srf.NormalX, Srf.NormalY, Srf.NormalZ]; 
0109   F0R = Srf.Triangles+1;
0110 elseif isfield(brain_parm,'FS_left_file') & ...
0111       ~isempty(brain_parm.FS_left_file), 
0112   fprintf('\n--- Make brain model using FreeSurfer .asc files ');
0113   filetype = 'FreeSurfer'; 
0114   
0115   [V0L,F0L] = vb_fs_load_surface(brain_parm.FS_left_file,...
0116                   brain_parm.FS_xfm_file,1.0);
0117   [V0R,F0R] = vb_fs_load_surface(brain_parm.FS_right_file,...
0118                   brain_parm.FS_xfm_file,1.0);
0119 
0120   [tmp1,tmp2,n0L] = vb_out_normal(F0L,V0L); 
0121   [tmp3,tmp4,n0R] = vb_out_normal(F0R,V0R);
0122   n0L = -1*n0L; 
0123   n0R = -1*n0R; 
0124   
0125   if size(tmp1,1)~=size(F0L,1) | size(tmp2,1)~=size(V0L,1) | ...
0126     size(tmp3,1)~=size(F0R,1) | size(tmp4,1)~=size(V0R,1), 
0127     error(['There are some isolated pathces in the FreeSurfer ' ...
0128        'cortical model.']);
0129   end
0130 end
0131 fprintf('%f[sec]\n',toc);
0132 
0133 switch filetype
0134  case 'BrainVoyager', 
0135   %
0136   % --- MRI-Voxel coordinate
0137   %
0138   % [Right-hand coordinate]
0139   % X:Front(1) -> Back(256)
0140   % Y:Top(1)   -> Bottom(256)
0141   % Z:Left(1)  -> Right(191)
0142   %
0143   tic;
0144   fprintf('--- Coordinate transformation (BV to VOX) ');
0145 
0146   [Vdim, Vsize] = analyze_hdr_read(brain_parm.analyze_file);
0147 
0148   V2L = vb_bvoyger_to_vox(V0L,Vdim,Vsize,TRANS_COORDINATE);
0149   V2R = vb_bvoyger_to_vox(V0R,Vdim,Vsize,TRANS_COORDINATE);
0150 
0151   n2L = vb_bvoyger_to_vox(n0L,Vdim,Vsize,TRANS_NORMAL);
0152   n2R = vb_bvoyger_to_vox(n0R,Vdim,Vsize,TRANS_NORMAL);
0153 
0154   fprintf('%f[sec]\n',toc);
0155  case 'FreeSurfer'
0156   V2L = V0L; 
0157   V2R = V0R; 
0158   n2L = n0L;
0159   n2R = n0R; 
0160 end
0161 
0162 %
0163 % --- Redeuce patchs
0164 %
0165 tic;
0166 fprintf('--- Reduce cortical vertices ');
0167 
0168 [F3L,V3L] = vb_reducepatch( F0L, V2L, brain_parm.reduce_ratio ); 
0169 [F3R,V3R] = vb_reducepatch( F0R, V2R, brain_parm.reduce_ratio );  
0170 
0171 fprintf('%f[sec]\n',toc);
0172 
0173 %
0174 % ---  Find original vertex point in BV-model corresponding to reduced model
0175 %
0176 tic;
0177 fprintf('--- Find original point corresponding to reduced model ');
0178 
0179 IndxL = vb_find_match_point( V2L, V3L, brain_parm.N_step );
0180 IndxR = vb_find_match_point( V2R, V3R, brain_parm.N_step );
0181 
0182 fprintf('%f[sec]\n',toc);
0183 
0184 % ---  Normal vector obtained from original BV-model
0185 n3L = n2L(IndxL,:);
0186 n3R = n2R(IndxR,:);
0187 
0188 %
0189 % --- Right-hand SPM coordinate  [mm]
0190 %
0191 % [Right-hand coordinate]
0192 % X: Left(-191/2)   -> Right(191/2)
0193 % Y: Back(-256/2)   -> Front(256/2)
0194 % Z: Bottom(-256/2) -> Top(256/2)
0195 %
0196 switch filetype, 
0197  case 'BrainVoyager', 
0198   tic; 
0199   fprintf('--- Coordinate transformation (VOX to SPM-ANALYZE) ');
0200    V3L = vb_vox_to_spm_right(V3L,Vdim,Vsize,TRANS_COORDINATE);
0201    V3R = vb_vox_to_spm_right(V3R,Vdim,Vsize,TRANS_COORDINATE);
0202 
0203    n3L = vb_vox_to_spm_right(n3L,Vdim,Vsize,TRANS_NORMAL);
0204    n3R = vb_vox_to_spm_right(n3R,Vdim,Vsize,TRANS_NORMAL);
0205    
0206    fprintf('%f[sec]\n',toc);
0207  case 'FreeSurfer', 
0208 end
0209 
0210 % Vertex number of reduced model
0211 NdipoleL = size(V3L,1);
0212 NdipoleR = size(V3R,1);
0213 Ndipole  = NdipoleL + NdipoleR;
0214 
0215 F3R = F3R + NdipoleL;
0216 F3  = [F3L ; F3R];
0217 n3  = [n3L ; n3R]; 
0218 
0219 NdipoleL0 = size(V0L,1);
0220 clear V0L V0R V2L V2R F0L F0R n0L n0R n2L n2R Srf
0221 
0222 %
0223 % --- SPM cordinate in [m] , Normal vector is outward.
0224 %
0225 tic;
0226 fprintf('--- Change coordinate to [m] ');
0227 V  = [V3L ; V3R]./1000;
0228 
0229 % Normalize normal vectors
0230 nn = sqrt(sum(n3.^2 ,2)); 
0231 ix = find(nn<eps);
0232 if ~isempty(ix), 
0233     fprintf('!! There are abnormal normal vector \n'); 
0234     nn(ix)     = 1; 
0235 end
0236 xx = -n3./repmat(nn ,[1 3]);
0237 
0238 
0239 % triangle patch index for left/right brain
0240 Npatch     = size(F3,1);
0241 F.F3       = F3;
0242 F.F3R       = F3R;
0243 F.F3L       = F3L;
0244 F.NdipoleL = NdipoleL;
0245 
0246 % BrainVoyager vertex index corresponding to reduced brain 'V'
0247 BV_index.Left  = IndxL; 
0248 BV_index.Right = IndxR+NdipoleL0;
0249 
0250 % Dimensional info
0251 Vinfo.Ndipole   = Ndipole;
0252 Vinfo.NdipoleL  = NdipoleL;
0253 Vinfo.Npatch    = Npatch;
0254 Vinfo.NdipoleL0 = NdipoleL0;
0255 Vinfo.Coord     = 'SPM_Right_m';
0256 
0257 clear V3L V3R n3L n3R
0258 
0259 fprintf('%f[sec]\n',toc);
0260

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