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 Cortex area index of original FreeSurfer surface BV_index.cortexL BV_index.cortexR Vinfo : Vertex dimension structure .Ndipole : # of vertex .NdipoleL : # of vertex in Left cortex .Npatch : # of patch .Coord = 'SPM_Right_m'; Cortex area index of 'V' Vinfo.cortexL = Vinfo.cortexR = 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. 2017-03-14 rhayashi Add Vinfo.(cortexL/cortexR) and BV_index.(cortexL/cortexR)
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 % Cortex area index of original FreeSurfer surface 0043 % BV_index.cortexL 0044 % BV_index.cortexR 0045 % Vinfo : Vertex dimension structure 0046 % .Ndipole : # of vertex 0047 % .NdipoleL : # of vertex in Left cortex 0048 % .Npatch : # of patch 0049 % .Coord = 'SPM_Right_m'; 0050 % Cortex area index of 'V' 0051 % Vinfo.cortexL = 0052 % Vinfo.cortexR = 0053 % 0054 % Originaly written by S.Kajihara 0055 % Ver 1.1 modified by M. Sato 2003-4-15 0056 % 0057 % Modified by Taku Yoshioka 0058 % 2003-07-11 0059 % ・ファイルに保存するデータ構造を変更 0060 % ・メッセージを少し変更 0061 % 2003-07-29 0062 % ・座標変換時のオフセットを切替えられるように変更 0063 % 2003-10-08 0064 % ・MRI-Voxel座標データを保存(元の仕様) 0065 % 0066 % 0067 % 2005-03-20 Modified by TY 0068 % 0069 % Ver 2.0 modified by M. Sato 2005-4-8 0070 % 座標系をSPM右手座標に変換する 0071 % Analyze ファイルが必要 0072 % (DICOM イメージファイルは不要) 0073 % 0074 % modified by M. Sato 2005-8-1 0075 % Vinfo 追加 0076 % modified by M. Sato 2005-8-9 0077 % パラメタと変数名の大幅見直し変更 0078 % modified by M. Sato 2006-7-21 0079 % use BV file load function 0080 % 2010-05-28 Taku Yoshioka 0081 % Minor change (verbose level support) 0082 % 2010-08-23 rhayashi 0083 % support Nvertex parameter. 0084 % 2017-03-14 rhayashi 0085 % Add Vinfo.(cortexL/cortexR) and BV_index.(cortexL/cortexR) 0086 0087 % Copyright (C) 2011, ATR All Rights Reserved. 0088 % License : New BSD License(see VBMEG_LICENSE.txt) 0089 0090 % V0L/R Brain-Voyager coordinate 0091 % n0L/R unit vector 0092 % FOL/R triangle patch 0093 global vbmeg_inst; 0094 const = vb_define_verbose; 0095 0096 vb_disp('Load original brain'); 0097 [V0L,F0L,n0L,V0R,F0R,n0R] = vb_load_orig_brain_surf(brain_parm); 0098 % V0L/R vertex coordinate (SPM_Right mm) 0099 % n0L/R unit vector 0100 % FOL/R triangle patch 0101 0102 % Extract cortex area index 0103 vb_disp('Extract cortex area index'); 0104 0105 [Vindex] = vb_extract_cortex(V0L,F0L,V0R,F0R,brain_parm,0); 0106 0107 % 0108 % --- Redeuce patchs 0109 % 0110 tic; 0111 vb_disp('Reduce cortical vertices '); 0112 0113 R = 1.0; 0114 if isfield(brain_parm, 'Nvertex') && ~isempty(brain_parm.Nvertex) &&... 0115 isnumeric(brain_parm.Nvertex) 0116 % Number of verticies after reducing 0117 N = brain_parm.Nvertex; 0118 if((size(V0L, 1) + size(V0R, 1)) < N) 0119 vb_disp(['brain_parm.Nvertex is larger than original model''s one.'... 0120 'No reduction is applied.'], const.VERBOSE_LEVEL_WARNING); 0121 else 0122 R = N; 0123 vb_disp(sprintf('Nvertex = %d is applied.', brain_parm.Nvertex)); 0124 end 0125 elseif isfield(brain_parm, 'reduce_ratio') && ... 0126 isnumeric(brain_parm.reduce_ratio) 0127 R = brain_parm.reduce_ratio; 0128 vb_disp(sprintf('reduce_ratio = %.2f is applied.', ... 0129 brain_parm.reduce_ratio)); 0130 end 0131 0132 [F3L,V3L] = vb_reducepatch( F0L, V0L, R ); % 0 < R < 1: ratio 0133 [F3R,V3R] = vb_reducepatch( F0R, V0R, R ); % R > 1 : number of verticies 0134 0135 vb_disp(sprintf('%f [sec]',toc)); 0136 0137 % 0138 % --- Find original vertex point in BV-model corresponding to reduced model 0139 % 0140 tic; 0141 vb_disp_nonl('Find original point corresponding to reduced model: '); 0142 0143 IndxL = vb_find_match_point( V0L, V3L, brain_parm.N_step ); 0144 IndxR = vb_find_match_point( V0R, V3R, brain_parm.N_step ); 0145 0146 % --- Normal vector obtained from original BV-model 0147 n3L = n0L(IndxL,:); 0148 n3R = n0R(IndxR,:); 0149 0150 0151 % Vertex number of reduced model 0152 NdipoleL = size(V3L,1); 0153 NdipoleR = size(V3R,1); 0154 Ndipole = NdipoleL + NdipoleR; 0155 0156 F3R = F3R + NdipoleL; 0157 F3 = [F3L ; F3R]; 0158 xx = [n3L ; n3R]; 0159 0160 % Normalize normal vectors 0161 nn = sqrt(sum(xx.^2 ,2)); 0162 nn = max( nn, eps); 0163 xx = xx./repmat(nn ,[1 3]); 0164 0165 vb_disp(sprintf('%f[sec]',toc)); 0166 0167 NdipoleL0 = size(V0L,1); 0168 NdipoleR0 = size(V0R,1); 0169 0170 % 0171 % --- SPM cordinate in [m] , Normal vector is outward. 0172 % 0173 tic; 0174 vb_disp_nonl('Change coordinate to [m]: '); 0175 V = [V3L ; V3R]/1000; 0176 0177 % triangle patch index for left/right brain 0178 Npatch = size(F3,1); 0179 F.F3 = F3; 0180 F.F3R = F3R; 0181 F.F3L = F3L; 0182 F.NdipoleL = NdipoleL; 0183 0184 % BrainVoyager vertex index corresponding to reduced brain 'V' 0185 BV_index.Left = IndxL; 0186 BV_index.Right = IndxR + NdipoleL0; 0187 0188 % Cortex area index of original FreeSurfer surface 0189 BV_index.cortexL = Vindex.cortexL; 0190 BV_index.cortexR = Vindex.cortexR + NdipoleL0; 0191 0192 % Dimensional info 0193 Vinfo.Ndipole = Ndipole; 0194 Vinfo.NdipoleL = NdipoleL; 0195 Vinfo.NdipoleR = NdipoleR; 0196 0197 Vinfo.Ndipole0 = NdipoleL0 + NdipoleR0; 0198 Vinfo.NdipoleL0 = NdipoleL0; 0199 Vinfo.NdipoleR0 = NdipoleR0; 0200 Vinfo.Npatch = Npatch; 0201 Vinfo.Coord = 'SPM_Right_m'; 0202 clear V3L V3R n3L n3R 0203 0204 [cortexL, cortexR] = vb_cortex_area_index(Vinfo, Vindex, IndxL, IndxR); 0205 Vinfo.cortexL = cortexL; 0206 Vinfo.cortexR = cortexR; 0207 0208 vb_disp(sprintf('%f[sec]',toc));