Make cortex data from BrainVoyager/FreeSurfer files [V,F,xx,ORG_index,Vinfo] = vb_make_brain_data2(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 .analyze_file : MRI analyze file .Nvertex : Total number of vertices of the right and left brain after reducing original(BV/FS) model. (Priority: Nvertex>reduce_ratio) .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 パラメタと変数名の大幅見直し変更 modified by M. Sato 2006-7-21 use BV file load function 2010-05-28 Taku Yoshioka Minor change (verbose level support) 2010-08-23 rhayashi support Nvertex parameter. Copyright (C) 2011, ATR All Rights Reserved. License : New BSD License(see VBMEG_LICENSE.txt)
0001 function [V,F,xx,BV_index,Vinfo] = vb_make_brain_data2(brain_parm); 0002 % Make cortex data from BrainVoyager/FreeSurfer files 0003 % [V,F,xx,ORG_index,Vinfo] = vb_make_brain_data2(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 % 0019 % .analyze_file : MRI analyze file 0020 % .Nvertex : Total number of vertices of the right and left brain 0021 % after reducing original(BV/FS) model. 0022 % (Priority: Nvertex>reduce_ratio) 0023 % .reduce_ratio : ratio of reducing vertex points 0024 % BV皮質モデルからVBMEG脳モデルを作成するときの頂点数の削減率 0025 % .N_step : Division number in searching match points 0026 % 頂点対応探索時のZ軸方向分割数 0027 % 0028 %--- Output 0029 % 0030 % V : Cortical vertex point cordinate (SPM_Right_m) [Nvertex, 3] 0031 % 頂点位置 ( 頂点の数, 3) 0032 % xx : Normal vector to cortical surface [Nvertex, 3] 0033 % 頂点の法線方向と位置( 頂点の数, 3) 0034 % F : Patch index structure 0035 % 面(3角形)を構成する3つの頂点番号 ( 面の数, 3) 0036 % .F3R : Right cortex 0037 % .F3L : Left cortex 0038 % .F3 : Left + Right 0039 % BV_index : original vertex index in BV corresponding to brain 0040 % .Left : Left brain 0041 % .Right : Right brain 0042 % Vinfo : Vertex dimension structure 0043 % .Ndipole : # of vertex 0044 % .NdipoleL : # of vertex in Left cortex 0045 % .Npatch : # of patch 0046 % .Coord = 'SPM_Right_m'; 0047 % 0048 % Originaly written by S.Kajihara 0049 % Ver 1.1 modified by M. Sato 2003-4-15 0050 % 0051 % Modified by Taku Yoshioka 0052 % 2003-07-11 0053 % ・ファイルに保存するデータ構造を変更 0054 % ・メッセージを少し変更 0055 % 2003-07-29 0056 % ・座標変換時のオフセットを切替えられるように変更 0057 % 2003-10-08 0058 % ・MRI-Voxel座標データを保存(元の仕様) 0059 % 0060 % 0061 % 2005-03-20 Modified by TY 0062 % 0063 % Ver 2.0 modified by M. Sato 2005-4-8 0064 % 座標系をSPM右手座標に変換する 0065 % Analyze ファイルが必要 0066 % (DICOM イメージファイルは不要) 0067 % 0068 % modified by M. Sato 2005-8-1 0069 % Vinfo 追加 0070 % modified by M. Sato 2005-8-9 0071 % パラメタと変数名の大幅見直し変更 0072 % modified by M. Sato 2006-7-21 0073 % use BV file load function 0074 % 2010-05-28 Taku Yoshioka 0075 % Minor change (verbose level support) 0076 % 2010-08-23 rhayashi 0077 % support Nvertex parameter. 0078 % 0079 % Copyright (C) 2011, ATR All Rights Reserved. 0080 % License : New BSD License(see VBMEG_LICENSE.txt) 0081 0082 % V0L/R Brain-Voyager coordinate 0083 % n0L/R unit vector 0084 % FOL/R triangle patch 0085 global vbmeg_inst; 0086 const = vb_define_verbose; 0087 0088 vb_disp('Load original brain'); 0089 [V0L,F0L,n0L,V0R,F0R,n0R] = vb_load_orig_brain_surf(brain_parm); 0090 0091 % 0092 % --- Redeuce patchs 0093 % 0094 tic; 0095 vb_disp('Reduce cortical vertices '); 0096 0097 R = 1.0; 0098 if isfield(brain_parm, 'Nvertex') && ~isempty(brain_parm.Nvertex) &&... 0099 isnumeric(brain_parm.Nvertex) 0100 % Number of verticies after reducing 0101 N = brain_parm.Nvertex; 0102 if((size(V0L, 1) + size(V0R, 1)) < N) 0103 vb_disp(['brain_parm.Nvertex is larger than original model''s one.'... 0104 'No reduction is applied.'], const.VERBOSE_LEVEL_WARNING); 0105 else 0106 R = N; 0107 vb_disp(sprintf('Nvertex = %d is applied.', brain_parm.Nvertex)); 0108 end 0109 elseif isfield(brain_parm, 'reduce_ratio') && ... 0110 isnumeric(brain_parm.reduce_ratio) 0111 R = brain_parm.reduce_ratio; 0112 vb_disp(sprintf('reduce_ratio = %.2f is applied.', ... 0113 brain_parm.reduce_ratio)); 0114 end 0115 0116 [F3L,V3L] = reducepatch( F0L, V0L, R ); % 0 < R < 1: ratio 0117 [F3R,V3R] = reducepatch( F0R, V0R, R ); % R > 1 : number of verticies 0118 0119 vb_disp(sprintf('%f [sec]',toc)); 0120 0121 % 0122 % --- Find original vertex point in BV-model corresponding to reduced model 0123 % 0124 tic; 0125 vb_disp_nonl('Find original point corresponding to reduced model: '); 0126 0127 IndxL = vb_find_match_point( V0L, V3L, brain_parm.N_step ); 0128 IndxR = vb_find_match_point( V0R, V3R, brain_parm.N_step ); 0129 0130 % --- Normal vector obtained from original BV-model 0131 n3L = n0L(IndxL,:); 0132 n3R = n0R(IndxR,:); 0133 0134 0135 % Vertex number of reduced model 0136 NdipoleL = size(V3L,1); 0137 NdipoleR = size(V3R,1); 0138 Ndipole = NdipoleL + NdipoleR; 0139 0140 F3R = F3R + NdipoleL; 0141 F3 = [F3L ; F3R]; 0142 xx = [n3L ; n3R]; 0143 0144 % Normalize normal vectors 0145 nn = sqrt(sum(xx.^2 ,2)); 0146 nn = max( nn, eps); 0147 xx = xx./repmat(nn ,[1 3]); 0148 0149 vb_disp(sprintf('%f[sec]',toc)); 0150 0151 NdipoleL0 = size(V0L,1); 0152 0153 % 0154 % --- SPM cordinate in [m] , Normal vector is outward. 0155 % 0156 tic; 0157 vb_disp_nonl('Change coordinate to [m]: '); 0158 V = [V3L ; V3R]/1000; 0159 0160 % triangle patch index for left/right brain 0161 Npatch = size(F3,1); 0162 F.F3 = F3; 0163 F.F3R = F3R; 0164 F.F3L = F3L; 0165 F.NdipoleL = NdipoleL; 0166 0167 % BrainVoyager vertex index corresponding to reduced brain 'V' 0168 BV_index.Left = IndxL; 0169 BV_index.Right = IndxR + NdipoleL0; 0170 0171 % Dimensional info 0172 Vinfo.Ndipole = Ndipole; 0173 Vinfo.NdipoleL = NdipoleL; 0174 Vinfo.Npatch = Npatch; 0175 Vinfo.NdipoleL0 = NdipoleL0; 0176 Vinfo.Coord = 'SPM_Right_m'; 0177 0178 clear V3L V3R n3L n3R 0179 0180 vb_disp(sprintf('%f[sec]',toc)); 0181