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