[1] Loading EEG data and check the items including data, channel locations, and sampling rate.
[2] Calculating the leadfield matrix by solving forward problem based on selected head model and channel locations. Or obtaining a user defined leadfield matrix.
[3] If needed, passband filtering the EEG data. Default is no filtering.
[4] Specific event data can be extracted according to the input ‘eventlabel’. If the input ‘eventlabel’ is empty, all data will be used. And, specific EEG signals will be divided into small epochs. If applicable, EEG segments in bad block (label 9999, marked by WB_EEG_Mark) will be rejected automatically, and NOT used to estimate sources.
[5] EEG data of each epoch (default is 5-s epoch) is subjected to estimate sources to obtain the EEG signals in the source space using an inverse method such as ‘sLORETA’ (Dale et al., 2000; Pascual-Marqui, 2002).
[6] If needed, matching source signals to a brain template (e.g. AAL template) to obtain the averaged source signals of brain regions.
[7] Saving the results of EEG source signals and parameters as a .set file.

Fig. 12: The pipeline of EEG source imaging. (1) Loading EEG data and check the items including data, channel locations, and sampling rate. (2) Calculating the leadfield matrix by solving forward problem based on selected head model and channel locations. Or obtaining a user defined leadfield matrix. The channel locations will be matched to the head model automatically. (3) If needed, passband filtering the EEG data. Default is no filtering. (4) Specific event data can be extracted according to the input ‘eventlabel’. If the input ‘eventlabel’ is empty, all data will be used. And, specific EEG signals will be divided into small epochs. If applicable, EEG segments in bad block (label 9999, marked by wb_EEG_Mark) will be rejected automatically, and NOT used to estimate sources. (5) EEG data of each epoch (default is 5 s epoch) is subjected to estimate sources to obtain the EEG signals in the source space using an inverse method such as ‘sLORETA’. (6) If needed, matching source signals to a brain template (e.g. AAL template) to obtain the averaged source signals of brain regions. (7) Saving the results of EEG source signals and parameters as a .set file.
Parameters
epochLenth: Length of small epochs to calculate EEG source signals. Unit is second. Default is 5s. If epochLenth is negative, it means that if possible, data before event labels (eventlabel) will be used (no overlapped).
eventlabel: Event label which means specific event data. Default is empty. If it is empty, all data will be used. If eventlabel is not found, NO data will be epoched and calculated. If structure event (eventlabel) doesn’t include duration, the duration will be equal to epochLenth.
seleChanns: a string number with indices of the selected channels (e.g. ‘[1:4,7:30]’ or ‘all’). Default is ‘all’.
passband: Pass band of filtering. Default is no filtering (i.e. ‘[]’).
ForwardMethod: Forward method used to calculate the leadfield matrix.
ForwardMethod = 0: use a user defined leadfield matrix. While ForwardMethod = 0, the leadfield file must be inputed.
ForwardMethod = 1: if EEG contains correct channel locations, it will automatically calculate leadfield matrix based on 3-concentric sphere head model.
ForwardMethod = 2: if EEG contains correct channel locations, it will automatically calculate leadfield matrix based on based on real head modal (BEM modal) using FieldTrip.
proportion: overlapped percentage for each segments/sliding windows. It should be [0,1). Default is 0 (no overlapped).
SourceMethod: Inverse method used to calcualte EEG source signals. Default is ‘sloreta’.
‘sloreta’: EEG source imaging using sLORETA method (based on Dale et al. standardization) (Dale et al., 2000; Pascual-Marqui, 2002). The sLORETA is a tomographic method for electric neuronal activity, where localization inference is based on images of standardized current density. The method is denoted as standardized low resolution brain electromagnetic tomography (sLORETA). Noting that the Dale et al. standardization is used in the standardized estimation of sLORETA in the WeBrain.
alpha: regularization parameter of inverse method.
alpha >= 0: use user-defined value;
alpha = ‘mean’: use averaged alpha with tikh regularization (default);
alpha = ‘timevarying’: use time-varying alpha with tikh regularization. The time cost of ‘time-varying’ alpha is extremely high for EEG time courses. It is used for the situation of less topographies.
elecDirecFlag: It is valid while calcuating leadfield. It is optional.
elecDirecFlag = 0: XYZ coordinates is the electorde array with their Cartesian x (the left ear is defined as -x axis),y (the nasion is the +y axis), z coordinates in three columns.
elecDirecFlag = 1: XYZ coordinates is the electorde array with their Cartesian x (the nasion is the +x axis),y (the left ear is the +y axis), z coordinates in three columns. Default is 1.
matchflag: Matching the source signals to a brain template (e.g. AAL template) to obtain the averaged source signals of brain regions.
matchflag = [] (default): no matching;
matchflag = ‘aal’: matching to AAL template and obtaining averaged source signals of brain regions;
erpflag: Estimating the source signals for averaged ERP waves? It is useful for the segmented ERP epoch data (i.e. the demension of EEG.data is channels × time points × epochs).
erpflag = 0 (default): estimating the source signals of each epoch;
erpflag = 1: averaging trials and then estimating the source signals of averaged ERP waves. It is valid, while the data is epoched.
leadfieldfile: a user defined lead field file (optional). It is valid, while the ForwardMethod = 0 only. The file could be a MATLAB .mat file, containing a matrix named ‘leadfield’ (channels × sources/dipoles, e.g. 60 channels × 6144 sources/dipoles) or a MATLAB structure containing leadfield of x,y,z-orientations (e.g. leadfield.X with dimension channels × dipoles (x-orientation);leadfield.Y with dimension channels × dipoles (y-orientation); leadfield.Z with dimension channels × dipoles (z-orientation)) which is calculated by using the forward theory, based on the electrode montage, head model and equivalent source model. It can also be the output of ft_prepare_leadfield.m (e.g. lf.leadfield, dipoles contain x,y,z-orientations, 60 channels × 6144*3 dipoles) based on real head modal (BEM modal) using FieldTrip.
gridresolution:The grid resolution of dipoles (sources) inside the brain (optional). It is valid, while ForwardMethod = 1. If it is empty or <=0, the default dipoles are vertices which are little smaller than brain, and the orientations of dipoles are their normal vector directions, i.e. the normals of the brain mesh. If it >0 (unit is mm), the dipoles are distributed on regular 3D grid inside brain mesh. The orientations of dipoles are X, Y and Z orientations, i.e. there are X, Y and Z oriented dipoles. Default is empty.
srate: Sampling rate of EEG data (optional). Default is obtained from EEG data (‘[]’).
AAL: a matrix with brain region number of AAL template. It is optional, and is valid while matchflag = ‘aal’.
Output:
EEG: a structure of EEG containing results of EEG source imaging.
EEG.data: EEG sources with dimension No. of dipoles × No. of time points.
EEG.parameter.eventlabel: An eventlabel which means good quality data;
EEG.parameter.selechanns: An array with selected channels;
EEG.parameter.epochLenth: Length of small epochs, and unit is time point;
EEG.parameter.srate: Sampling rate of EEG data;
EEG.parameter.sourcemethod: Inverse method used to estimate EEG source signals;
EEG.parameter.proportion: overlapped percentage for each segments/sliding windows;
EEG.parameter.chanlocs: EEG channel locations on the scalp;
EEG.parameter.ref: original EEG reference;
EEG.parameter.leadfield: leadfield matrix;
EEG.parameter.alpha: regularization parameter;
EEG.parameter.elecDirecFlag: flag of channel directions;
EEG.parameter.chaninfo: channel information.
EEG.parameter.erpflag: flag of average ERP.
EEG.parameter.headmodel: default headmodel, and details see below;
EEG.parameter.ForwardMethod: forward method used in the tool.
EEG.parameter.passband: pass band of filtering.
EEG.parameter.gridresolution: the grid resolution of dipoles (sources) inside the brain.
EEG.parameter.elec_aligned: aligned channel locations of electrodes.
EEG.parameter.BrainRegionInd: brain region indices according to a template such as AAL.
EEG.parameter.template: the template used to obtain the averaged source signals of brain regions.
EEG.parameter.matchflag: flag of matching source signals to a brain template.
Important Issues in Source Imaging
Forward model
(1) 3-concentric sphere head model
Default head model are based on 3-concentric spheres, in which the radii of spheres are normalized by the largest sphere. i.e. [0.87, 0.92, 1], corresponding to brain, skull and scalp. Conductivities of 3 concentric spheres are normalized by the largest resistivity, and default is [1, 0.0125, 1]. A high-density canonical cortical mesh was used to define the dipoles. These meshes were obtained by warping a template mesh to the T1-weighted structural anatomy of an individual subject, as described in Mattout et al. (2007) (Mattout et al., 2007). This warping is the inverse of the transformation derived for the spatial normalization of the subject’s structural MRI image. The template mesh was generated by Fieldtrip (http://fieldtrip.fcdonders.nl/download.php), and was extracted from a structural MRI of a neurotypical male. The wrapping procedure provided a high-density mesh with 33,001 vertexes, which was uniformly distributed on the gray-white matter interface. The mesh was further down-sampled to 6,144 vertexes (SPM MNI space) to reduce the computational load. More details see: Lei, X., et al. (2012). "Incorporating fMRI Functional Networks in EEG Source Imaging: A Bayesian Model Comparison Approach." Brain Topogr (Lei et al., 2012). Finally, the leadfield matrix was calculated analytically based on spherical harmonic spectra theory (Yao, 2000; Yao et al., 2004).
headmodel details: default head model are based on 3-concentric spheres.
headmodel.r: the radii of spheres which are normalized by the largest sphere. E.g. [0.87,0.92,1].
headmodel.type: head model type. It is concentric spheres
headmodel.cond (optional): the conductivities (Brain, Skull and Scalp) which are normalized by the largest resistivity. E.g. For 3 concentric spheres, default is [1, 0.0125, 1];
headmodel.tissue (optional): tissues. E.g. [‘brain’ ‘skull’ ‘scalp’ ];
headmodel.o: center of the spheres (optional if origin).e.g. [0,0,0].
headmodel.terms: the constants for the Legendre expansion for EEG leadfields. The returning value is the constant for the third layer on the outer surface, e.g. K(3, r=R3).
headmodel.sourcemesh.bnd: the source mesh of dipoles.

Fig.13: The default 3 concentric sphere head model in the WeBrain. A: the default geometrically triangular grid in the WeBrain which is based on the standard brain (MNI space) and contains 6144 dipoles. B: 3 concentric spheres and their conductivities. Nodes and their normal vector directions are showed.
(2) Real head model based on Boundary Element Method
The details about BEM and real head model used in the WeBrain are as follows:
A standard headmodel using ‘dipoli’ method based on Boundary Element Method (BEM) were used in the WeBrain. The headmodel contains a standard BEM volume conduction model of the head that can be used for EEG forward and inverse computations. The geometry is based on the “colin27” template that is described further down. The BEM model is expressed in MNI coordinates in mm. A very similar BEM volume conduction model (based on the same template data) is described and validated by Fuchs et al. in Clin Neurophysiol. 2002 May;113(5):702-12. More details see : http://www.fieldtriptoolbox.org/template/headmodel/. More details about the real head model and BEM can also be seen in the 3.11 WB_EEG_CalcLeadfield_standardBEM.
The “colin27” anatomical MRI and its relation to the TT and MNI template atlas is described in detail on http://imaging.mrc-cbu.cam.ac.uk/imaging/MniTalairach. The original construction of the averaged MRI is detailed in [http://www.ncbi.nlm.nih.gov/pubmed/9530404| Holmes CJ, Hoge R, Collins L, Woods R, Toga AW, Evans AC. Enhancement of MR images using registration for signal averaging. J Comput Assist Tomogr. 1998 Mar-Apr;22(2):324-33.]

Fig.14: The “colin27” anatomical MRI.
headmodel: headmodel info
headmodel.bnd: mesh of scalp, skull and brain.
headmodel.cond: conductivity of tissues, order is [scalp, skull and brain].
headmodel.type: BEM method used (i.e. ‘dipoli’).
headmodel.unit:unit of head model coordinates.
Inverse Method
(1) sLORETA
The details of sLORETA can be seen in the paper: Pascual-Marqui, R. D. (2002). "Standardized low-resolution brain electromagnetic tomography (sLORETA): technical details." Methods Find Exp Clin Pharmacol 24 Suppl D: 5-12.
The sLORETA tool is also available on http://www.uzh.ch/keyinst/loreta.htm.
Brain Template
(1) AAL template
An automated anatomical parcellation of the spatially normalized single-subject high-resolution T1 volume provided by the Montreal Neurological Institute (MNI), named Automated Anatomical Labeling (AAL) template (Tzourio-Mazoyer et al., 2002), is used to get average source signals in the brain regions in the WeBrain. More details about the AAL template are available on https://www.gin.cnrs.fr/en/tools/aal/.

Fig. 15: AAL template used in the WeBrain.