0001 function [Vx,Fnew,xx,Vindx,Vinfo] = vb_smooth_cortex(V, F, Para)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036
0037
0038
0039
0040
0041
0042
0043
0044
0045
0046
0047
0048 if ~exist('Para','var'), Para = []; end
0049
0050 if ~isfield(Para,'Dim') | isempty(Para.Dim)
0051 error('Size of mask image is not specified');
0052 else
0053 Dim = Para.Dim;
0054 end
0055
0056
0057
0058 if ~isfield(Para,'vstep'),
0059 error('Step size of mask image is not specified');
0060 else
0061 step = Para.vstep;
0062 end;
0063
0064
0065 if ~isfield(Para,'Nvertex'), Para.Nvertex = 3000; end;
0066
0067
0068
0069 if ~isfield(Para,'R_fill'), Para.R_fill = [4]; end;
0070 if ~isfield(Para,'R_smooth'), Para.R_smooth = [ 6 6 -6 -6]; end;
0071
0072
0073 if ~isfield(Para,'Nloop'), Para.Nloop = 200; end
0074 if ~isfield(Para,'Nlast'), Para.Nlast = 0; end
0075 if ~isfield(Para,'plot_mode'),Para.plot_mode = 0; end;
0076
0077
0078
0079
0080
0081
0082
0083
0084 tic
0085 fprintf('--- Make mask image from cortical surface\n')
0086 B = vb_cortex_fill(V, F, step, Para.R_fill, 'LR', Dim);
0087 vb_ptime(toc)
0088
0089
0090 B = vb_morphology_operation(B, Para.R_smooth, step);
0091
0092 if Para.plot_mode > 2,
0093
0094 Nfig = [3, 3];
0095
0096 zindx = [20:10:Dim(3)];
0097 vb_plot_slice( B, [], zindx, 1, Nfig);
0098 end
0099
0100
0101
0102
0103 tic
0104 fprintf('smoothing\n')
0105 B = smooth3(B,'gaussian',3);
0106 vb_ptime(toc);
0107
0108
0109
0110
0111 tic
0112 fprintf('--- Surface expansion\n')
0113
0114
0115 [Vx0, Fx, xx, X0] = vb_make_inner_sphere(V, Para.Nvertex);
0116
0117
0118 [Vx, Fx, xx] = vb_surf_smooth_fit(Vx0,Fx,xx, B, Para);
0119
0120 if Para.plot_mode > 1
0121 dmax = 10;
0122 vb_plot_slice_surf( B, Vx0/step, Fx, X0(1)/step, 'x',[1 1],'r-',dmax);
0123 vb_plot_slice_surf([], Vx/step, Fx, X0(1)/step, 'x',[1 1],'b-',dmax);
0124 vb_plot_slice_surf( B, Vx0/step, Fx, X0(2)/step, 'y',[1 1],'r-',dmax);
0125 vb_plot_slice_surf([], Vx/step, Fx, X0(2)/step, 'y',[1 1],'b-',dmax);
0126 vb_plot_slice_surf( B, Vx0/step, Fx, X0(3)/step, 'z',[1 1],'r-',dmax);
0127 vb_plot_slice_surf([], Vx/step, Fx, X0(3)/step, 'z',[1 1],'b-',dmax);
0128 end
0129
0130
0131
0132
0133 fprintf('--- Surface smoothing by spring model\n')
0134
0135 if Para.Nlast > 0,
0136 Para.Nloop = Para.Nlast;
0137 [Vx, Fx, xx] = vb_surf_smooth(Vx,Fx,xx,Para);
0138 end
0139
0140 vb_ptime(toc)
0141
0142 if Para.plot_mode > 0
0143 dmax = 10;
0144 vb_plot_slice_surf( B, Vx/step, Fx, X0(1)/step, 'x',[1 1],'r-',dmax);
0145 vb_plot_slice_surf( B, Vx/step, Fx, X0(2)/step, 'y',[1 1],'r-',dmax);
0146 vb_plot_slice_surf( B, Vx/step, Fx, X0(3)/step, 'z',[1 1],'r-',dmax);
0147 end
0148
0149 Ndipole = size(Vx,1);
0150 Npatch = size(Fx,1);
0151
0152 fprintf('# of patches : %d\n',Npatch);
0153 fprintf('# of vertices: %d\n',Ndipole);
0154
0155
0156
0157
0158 Zstep = 100;
0159 Rmax = 10;
0160
0161 fprintf('Find original vertex corresponding to the smoothed surface\n')
0162 [Vindx ,ddmin] = vb_find_nearest_point(V, Vx, Rmax, Zstep);
0163
0164 fprintf('Max distance between new and old vertex = %f [mm]\n',max(ddmin))
0165
0166
0167 NdipoleL = F.NdipoleL;
0168
0169 ixL = find(Vindx <= NdipoleL);
0170 ixR = find(Vindx > NdipoleL);
0171
0172
0173 Vix = [ixL ; ixR ];
0174 Vx = Vx(Vix,:);
0175 NL = length(ixL);
0176
0177 Itrans = zeros(Ndipole,1);
0178 Itrans(Vix) = 1:Ndipole;
0179
0180 Fx = Itrans(Fx);
0181
0182 Fnew.F3L = vb_patch_select([1:NL],Fx,Ndipole);
0183 Fnew.F3R = vb_patch_select([(NL+1):Ndipole],Fx,Ndipole);
0184
0185 Fnew.F3 = Fx;
0186 Fnew.NdipoleL = NL ;
0187
0188
0189 Vinfo.NdipoleL = NL ;
0190 Vinfo.Ndipole = Ndipole;
0191 Vinfo.Npatch = Npatch;
0192 Vinfo.Coord = 'Analyze_Right_mm';