Make smooth cortex from brain model by morphological smoothing [V,F,xx,brain_parm] = vb_job_smooth_cortex(proj_root,brain_parm) --- Input file name proj_root brain_parm.brain_file = [ base_brain_file_name '.brain.mat'] brain_parm.area_file = [ base_area_file_name '.area.mat' ] brain_parm.act_file = [ base_act_file_name '.act.mat' ] brain_parm.analyze_file --- Optional Input brain_parm.Nvertex = 3000 (Default) : Number of vertex brain_parm.R_fill = 4 : radius to fill inside of sulcus brain_parm.R_smooth = [ 6 6 -6 -6] : radius for morphological smoothing brain_parm.vstep = 2 : Subsampling step for mask image [mm] Para.Nloop = 200: iteration number for expanding sphere to brain surface Para.Nlast = 0: iteration number for additional smoothing ---- Output file name brain_parm.brain_file = [ base_brain_file_name '_smooth.brain.mat'] brain_parm.area_file = [ base_area_file_name '_smooth.area.mat' ] brain_parm.act_file = [ base_act_file_name '_smooth.act.mat' ] ---- Output (also saved in the brain_file) V : Cortical vertex point cordinate (SPM_Right_m) F : Patch index structure xx : Normal vector to cortical surface ---- Saved variable in the brain_file xxA : area for vertex 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 Original_info.parent_ix : Original vertex index corresponding to new vertex Original_info.brain_file : Original brainfile; Vinfo : Vertex dimension structure M. Sato 2006-7-21 M. Sato 2007-3-16 Copyright (C) 2011, ATR All Rights Reserved. License : New BSD License(see VBMEG_LICENSE.txt)
0001 function [V,F,xx,brain_parm] = vb_job_smooth_cortex(proj_root,brain_parm) 0002 % Make smooth cortex from brain model by morphological smoothing 0003 % [V,F,xx,brain_parm] = vb_job_smooth_cortex(proj_root,brain_parm) 0004 % --- Input file name 0005 % proj_root 0006 % brain_parm.brain_file = [ base_brain_file_name '.brain.mat'] 0007 % brain_parm.area_file = [ base_area_file_name '.area.mat' ] 0008 % brain_parm.act_file = [ base_act_file_name '.act.mat' ] 0009 % brain_parm.analyze_file 0010 % --- Optional Input 0011 % brain_parm.Nvertex = 3000 (Default) : Number of vertex 0012 % brain_parm.R_fill = 4 : radius to fill inside of sulcus 0013 % brain_parm.R_smooth = [ 6 6 -6 -6] : radius for morphological smoothing 0014 % brain_parm.vstep = 2 : Subsampling step for mask image [mm] 0015 % Para.Nloop = 200: iteration number for expanding sphere to brain surface 0016 % Para.Nlast = 0: iteration number for additional smoothing 0017 % 0018 % ---- Output file name 0019 % brain_parm.brain_file = [ base_brain_file_name '_smooth.brain.mat'] 0020 % brain_parm.area_file = [ base_area_file_name '_smooth.area.mat' ] 0021 % brain_parm.act_file = [ base_act_file_name '_smooth.act.mat' ] 0022 % ---- Output (also saved in the brain_file) 0023 % V : Cortical vertex point cordinate (SPM_Right_m) 0024 % F : Patch index structure 0025 % xx : Normal vector to cortical surface 0026 % ---- Saved variable in the brain_file 0027 % xxA : area for vertex 0028 % 0029 % xxF{i} : Next-neighbor index for the vertex-i 0030 % xxD{i} : Distance between next-neighbor and the vertex-i 0031 % xxT{n} : vertex index for n-th triangle 0032 % nextIX{i} : Neighbor index list for the vertex-i 0033 % nextDD{i} : Distance from the vertex-i 0034 % Original_info.parent_ix : Original vertex index corresponding to new vertex 0035 % Original_info.brain_file : Original brainfile; 0036 % 0037 % Vinfo : Vertex dimension structure 0038 % 0039 % M. Sato 2006-7-21 0040 % M. Sato 2007-3-16 0041 % 0042 % Copyright (C) 2011, ATR All Rights Reserved. 0043 % License : New BSD License(see VBMEG_LICENSE.txt) 0044 0045 DEBUG_MODE=0; 0046 0047 proj_root = vb_rm_trailing_slash(proj_root); 0048 0049 brain_file = brain_parm.brain_file; 0050 area_file = brain_parm.area_file ; 0051 act_file = brain_parm.act_file ; 0052 0053 add_name = '_smooth'; 0054 0055 brain_parm.brain_file = vb_change_file_basename(brain_file,add_name); 0056 brain_parm.area_file = vb_change_file_basename(area_file,add_name); 0057 brain_parm.act_file = vb_change_file_basename(act_file,add_name); 0058 0059 % Original input brain_file 0060 original_brainfile = [proj_root filesep brain_file]; 0061 0062 % Output file path 0063 brain_file = [proj_root filesep brain_parm.brain_file]; 0064 area_file = [proj_root filesep brain_parm.area_file ]; 0065 act_file = [proj_root filesep brain_parm.act_file ]; 0066 0067 [V,F] = vb_load_cortex(original_brainfile); 0068 0069 % ID for MRI image data 0070 [udir, fname] = fileparts(brain_parm.analyze_file); 0071 MRI_ID = fname; 0072 0073 % Subsampling step for mask image [mm] 0074 if ~isfield(brain_parm,'vstep'), brain_parm.vstep = 2; end; 0075 0076 % 0077 %----- ΊΒΙΈΚΡ΄Ή: Spm_right [m] -> Analyze_right [mm] 0078 % 0079 disp(['--- Change coordinate to Analyze_right [mm] ']); 0080 0081 [Vdim, Vsize] = analyze_hdr_read(brain_parm.analyze_file); 0082 Vox = vb_spm_right_to_analyze_right_mm(V, Vdim, Vsize); 0083 0084 % Calculate mask image size 0085 brain_parm.Dim = vb_mask_image_size(Vdim,Vsize, brain_parm.vstep); 0086 0087 % 0088 % --- Make smoothed cortex coordinate from original cortex 0089 % 0090 0091 [Vox,F,xx,original_indx,Vinfo] = vb_smooth_cortex(Vox, F, brain_parm); 0092 0093 % 0094 % --- Back to original coordinate 0095 % Vox = V*1000 - Vorgin; 0096 % V = (Vox + Vorgin) * 0.001; 0097 disp(['--- Back to Spm_right [m] coordinate ']); 0098 0099 V = vb_analyze_right_mm_to_spm_right(Vox,Vdim,Vsize); 0100 Vinfo.Coord = 'SPM_Right_m'; 0101 0102 if DEBUG_MODE==2, return; end; 0103 0104 % 0105 % --- Search next-point index and distance 0106 % 0107 tic; 0108 fprintf('--- Search next-point index and distance '); 0109 0110 [xxD, xxF, xxT] = vb_next_distance( [F.F3L ; F.F3R] , V ); % unit : m 0111 0112 fprintf('%f[sec]\n',toc); 0113 0114 % 0115 % --- Calculate area assigned to the vertex 0116 % 0117 tic 0118 0119 [xxA] = vb_calc_patch_area(V, F.F3, xxT); 0120 0121 fprintf('%f[sec]\n',toc); 0122 0123 original_info.parent_ix = original_indx; 0124 original_info.brain_file = original_brainfile; 0125 0126 fprintf(['--- Save brain model \n']); 0127 fprintf(' filename = %s\n', brain_file ); 0128 0129 vb_save([brain_file], 'F','V','xx','xxF','xxD','xxA',... 0130 'Vinfo','MRI_ID','original_info'); 0131 0132 % total number of vertex 0133 Ndipole = Vinfo.Ndipole; 0134 Vindx = 1:Ndipole; 0135 0136 % Make activity map file 0137 act_new.key = 'Uniform'; 0138 act_new.xxP = ones(Ndipole,1); 0139 act_new.comment = 'artificial data'; 0140 0141 vb_add_act([act_file], act_new, MRI_ID, OFF); 0142 0143 % Make Area file 0144 AreaNew.key = 'Cortex'; 0145 AreaNew.Iextract = [1:Ndipole]'; 0146 0147 vb_add_area([area_file], AreaNew, MRI_ID, OFF); 0148 0149 % Check brain model by 3D & MRI image 0150 vb_check_brain_model(proj_root,brain_parm); 0151 0152 if DEBUG_MODE==1, 0153 figure; 0154 hist(xxA*1e6, 0:0.25:10); 0155 xlim([0 10]) 0156 title('Histgram of patch area') 0157 xlabel('Area') 0158 return; 0159 end; 0160 % 0161 % Search neighbor points along cortex sheet 0162 % 0163 0164 if isfield(brain_parm,'R_max'), 0165 Rmax = brain_parm.R_max; 0166 else 0167 Rmax = 18e-3; 0168 end 0169 if isfield(brain_parm,'R_max'), 0170 Display = brain_parm.display; 0171 else 0172 Display = 200; 0173 end 0174 0175 [nextIX , nextDD] = vb_find_neighbor_all(Rmax, xxF, xxD, Vindx, Display); 0176 0177 vb_save([brain_file],'nextIX','nextDD'); 0178 0179 proj_file_save(brain_parm); 0180 0181 return 0182 0183 function proj_file_save(brain_parm) 0184 % project_file save 0185 proj_file = get_project_filename; 0186 0187 if isempty(proj_file) 0188 return; 0189 end 0190 0191 project_file_mgr('load', proj_file); 0192 project_file_mgr('add', 'brain_parm', brain_parm); 0193 0194 return