0001 function [sbasis, L, W, ix_area, ix_area_ex] = vb_prepare_leadfield( ...
0002 basisfile, brainfile, areafile, area_key, reduce, Rfilt, ...
0003 expand_spatial_filter, patch_norm, area_remove, spatial_smoother)
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
0049
0050
0051
0052 const = vb_define_verbose;
0053 VERBOSE_LEVEL_NOTICE = const.VERBOSE_LEVEL_NOTICE;
0054
0055
0056 if iscell(basisfile),
0057 Nfile = length(basisfile);
0058 else
0059 tmp = basisfile;
0060 Nfile = 1;
0061 basisfile = {tmp};
0062 end;
0063
0064 vb_disp(['Number of basis files (= Number of sessions): ' ...
0065 num2str(Nfile)],VERBOSE_LEVEL_NOTICE);
0066
0067
0068 [basis,L]=vb_load_basis(basisfile{1});
0069 Nj = size(basis,1);
0070 Nv = Nj/L;
0071
0072
0073 if ~isempty(areafile) & ~isempty(area_key)
0074 Area = vb_get_area(areafile, area_key);
0075 ix_area = Area.Iextract;
0076 vb_disp(['Area ID: ' area_key],VERBOSE_LEVEL_NOTICE)
0077 vb_disp(['Number of vertices: ' num2str(length(ix_area))], ...
0078 VERBOSE_LEVEL_NOTICE);
0079 else
0080 ix_area = [1:Nv]';
0081 vb_disp(['Area ID: All vertices'],VERBOSE_LEVEL_NOTICE)
0082 vb_disp(['Number of vertices: ' num2str(length(ix_area))], ...
0083 VERBOSE_LEVEL_NOTICE);
0084 end
0085
0086
0087 if exist('area_remove','var') & ~isempty(areafile) & ~isempty(area_remove)
0088 Area = vb_get_area(areafile, area_remove);
0089 ix_remove = Area.Iextract;
0090
0091 ix_area = vb_setdiff2(ix_area, ix_remove);
0092 end
0093
0094
0095 if ~isempty(reduce) & reduce ~=1,
0096 ix_area = vb_reduce_cortex(brainfile, ix_area, reduce);
0097 vb_disp(['Number of reduced vertices: ' ...
0098 num2str(length(ix_area))], VERBOSE_LEVEL_NOTICE);
0099 end
0100
0101
0102 if ~isempty(Rfilt) & Rfilt(1) > 0
0103 R = Rfilt(1);
0104
0105 if length(Rfilt) == 2,
0106 Rmax = Rfilt(2);
0107 else
0108 Rmax = 2*R;
0109 end
0110
0111 vb_disp('--- Spatial smoothing filter calculation', ...
0112 VERBOSE_LEVEL_NOTICE);
0113 vb_disp(['R = ' num2str(R,'%2.2e') ', Rmax= ' ...
0114 num2str(Rmax,'%2.2e')],VERBOSE_LEVEL_NOTICE);
0115
0116 [W,ix_area_ex] = vb_spatial_gauss_filter(...
0117 brainfile, R, Rmax, ix_area, expand_spatial_filter, [], [], spatial_smoother);
0118 else
0119 W = speye(length(ix_area), length(ix_area));
0120 ix_area_ex = ix_area;
0121 end
0122
0123 vb_disp(['Number of vertices = ' num2str(length(ix_area),'%5d')], ...
0124 VERBOSE_LEVEL_NOTICE);
0125 vb_disp(['Number of vertices in expanded area = ' ...
0126 num2str(length(ix_area_ex))],VERBOSE_LEVEL_NOTICE);
0127
0128
0129 if patch_norm==ON,
0130 if strcmpi(spatial_smoother, 'std')
0131 [tmp1,tmp2,tmp3,tmp4,xxA] = vb_load_cortex(brainfile);
0132 else
0133 [tmp1,tmp2,tmp3,tmp4,xxA] = vb_load_cortex(brainfile, 'subj');
0134 end
0135 clear tmp1 tmp2 tmp3 tmp4
0136 end
0137
0138
0139 sbasis = cell(Nfile,1);
0140
0141 for n = 1:Nfile
0142
0143 vb_disp(['Basis file for session ' num2str(n) ': ' basisfile{n}], ...
0144 VERBOSE_LEVEL_NOTICE);
0145 [basis,L]=vb_load_basis(basisfile{n});
0146 basis = basis';
0147
0148
0149 if patch_norm==ON,
0150 S = repmat(xxA(ix_area_ex)',[size(basis,1) 1]);
0151 else
0152 S = ones(size(basis(:,ix_area_ex)));
0153 end
0154
0155
0156 switch L
0157 case 1,
0158 basis = (basis(:,ix_area_ex).*S)*W;
0159 case 2,
0160 basis = [(basis(:,ix_area_ex).*S)*W (basis(:,Nv+ix_area_ex).*S)*W];
0161 case 3,
0162 basis = [(basis(:,ix_area_ex).*S)*W (basis(:,Nv+ix_area_ex).*S)*W ...
0163 (basis(:,2*Nv+ix_area_ex).*S)*W];
0164 end
0165
0166 sbasis{n} = basis;
0167 end