Zeffiro User Interface for Electromagnetic Brain Imaging: a GPU Accelerated FEM Tool for Forward and Inverse Computations in Matlab

  • Q. He
  • A. RezaeiEmail author
  • S. Pursiainen
Open Access
Software Original Article


This article introduces the Zeffiro interface (ZI) version 2.2 for brain imaging. ZI aims to provide a simple, accessible and multimodal open source platform for finite element method (FEM) based and graphics processing unit (GPU) accelerated forward and inverse computations in the Matlab environment. It allows one to (1) generate a given multi-compartment head model, (2) to evaluate a lead field matrix as well as (3) to invert and analyze a given set of measurements. GPU acceleration is applied in each of the processing stages (1)–(3). In its current configuration, ZI includes forward solvers for electro-/magnetoencephalography (EEG) and linearized electrical impedance tomography (EIT) as well as a set of inverse solvers based on the hierarchical Bayesian model (HBM). We report the results of EEG and EIT inversion tests performed with real and synthetic data, respectively, and demonstrate numerically how the inversion parameters affect the EEG inversion outcome in HBM. The GPU acceleration was found to be essential in the generation of the FE mesh and the LF matrix in order to achieve a reasonable computing time. The code package can be extended in the future based on the directions given in this article.


Matlab Interface Electro-/Magnetoencephalography (EEG/MEG) Electrical Impedance Tomography (EIT) Finite Element Method (FEM) Hierarchical Bayesian Model (HBM) 


This article introduces the Zeffiro1 interface (ZI) version 2.2 for electromagnetic brain imaging and investigations. ZI aims to provide an accessible and multi-modal open-source platform for finite element method (FEM) (Braess 2001) based forward and inverse computations in the Matlab (TheMathWorks Inc.) environment. The FEM is widely applied for modeling electromagnetic fields in a bounded domain, such as the brain and the head (de Munck et al. 2012; Monk 2003). It allows one to discretize realistic three-dimensional tissue parameter distributions in an accurate way, including advanced features such as complex internal boundary layers and anisotropic tissues such as the fibrous white matter of the brain (Rullmann et al. 2009). The FEM can be applied to model an electromagnetic source within the brain (Pursiainen et al. 2016b; Miinalainen et al. 2019) and, thereby, to construct a lead field (LF) matrix to localize brain activity in electro-/magnetoencephalography (EEG/MEG) (Hämäläinen et al. 1993; Niedermeyer and da Silva 2004).

The same quasi-static set of Maxwell’s equations that predicts the electric potential field of a neural source can be applied also to model the effect of current injections, where either direct or alternating currents applied through electrodes act as the source of the electromagnetic field. Such an approach is used, for example, in the electrical impedance tomography (EIT) (Cheney et al. 1999) in which the goal is to map the conductivity distribution or its perturbations within a given domain. EIT constitutes a non-linear inverse problem which can be linearized with respect to a given background conductivity distribution to obtain a LF matrix, i.e., a linearized forward model. The FEM is a powerful tool in EIT (Vauhkonen 1997), since it does not set any major restrictions for the conductivity distribution. In contrast, the boundary element method (BEM) (He et al. 1987), which is the predominating method in EEG/MEG, sets the conductivity to be a compartment-wise constant parameter, limiting its practical usage in EIT.

Until recently, the FEM has been considered as computationally heavy for discretizing the complex geometry of the brain. To tackle this issue, ZI uses graphics processing unit (GPU) acceleration. It includes forward solvers for EEG/MEG and linearized EIT as well as a set of inverse solvers based on the hierarchical Bayesian model (HBM) which was introduced for EEG/MEG in Calvetti et al. (2009). The ZI platform and function library has been designed to be easily expandable and to allow implementing virtually any FEM based forward model which can be formulated as a product between a LF matrix and a candidate solution vector.

In this paper, we briefly review the mathematics behind ZI, describe the principal operations and usage, and introduce some central points for the developer perspective. We report the results obtained in EEG and EIT inversion tests performed with real and syntetic data, respectively, and demonstrate numerically how the inversion parameters affect the EEG inversion outcome in HBM.


The electric potential field u in the head model Ω is assumed to satisfy the elliptic partial differential equation (PDE) of the form ∇⋅ (σu) = ∇⋅Jp, where σ is the conductivity distribution of the head and Jp is the primary current density of the neural activity. This equation follows from the current preservation condition ∇⋅Jt = 0 for the total current density Jt = Jpσu, that is, the sum of Jp and the volume current density − σu. The electromagnetic field within Ω can be evoked either by Jp acting as the source, which is the case in EEG/MEG, or by an external source, e.g., a current pattern injected through contact electrodes in EIT. The dependence between the measurements y and the unknown of the inverse problem x in question, e.g., a source localization problem, is here assumed be of the following linear form
$$ \mathbf{L} \mathbf{x} = \mathbf{y} + \mathbf{n}, $$
where L is the LF matrix and n is the noise vector. The LF matrices for EEG and linearized EIT inverse problem can be formed as shown in Appendix A.1.

Primary Current Model

ZI utilizes the H(div) source model (Pursiainen et al. 2016b) in which both linear and quadratic basis functions constitute the primary current density Jp. In Miinalainen et al. (2019); Pursiainen et al. (2016b), this model was shown to surpass the accuracy of the classical direct source modeling approaches based on the partial integration and St. Venant’s principle and to be especially advantageous for thin cortices as well as for inverting data.

A Cartesian set of source orientations can be obtained from a mesh-based set using the Position Based Optimization (PBO) method (Bauer et al. 2015) with an adaptive (Miinalainen and Pursiainen 2017) 10-source stencil in which 4 face and 6 edge functions are applied for each element containing a source (Pursiainen et al. 2016b). Alternatively, the Whitney model (Bauer et al. 2015), i.e., the 4-source stencil (4 face functions), can be used. Moreover, a set of Whitney functions can be applied without interpolation. That is, the LF matrix can be formed directly using the mesh-based set of basis functions as suggested in Miinalainen and Pursiainen (2017). In each active tissue compartment, the sources can either be normally constrained or unconstrained with respect to the surface of the compartment (Creutzfeldt et al. 1962; Hari et al. 2018). The source positions are randomly (uniformly) distributed in each case.

Conductivity Distribution

The current FE meshing strategy employed in ZI treats the conductivity as an isotropic piecewise (element-wise) constant distribution, i.e., a single scalar value is associated with each element in the FE mesh. However, when evaluating an LF matrix, ZI allows the conductivity distribution σ to be anisotropic, i.e., tensor-valued: the -th row of the form (σ11,σ22,σ33,σ12,σ13,σ23) within a multi-row array is associated with the symmetric conductivity tensor σij, i = 1,2,3, j = 1,2,3 (σij = σji) in the -th element.


The inverse tools of ZI are based on the HBM (Calvetti et al. 2009; O’Hagan and Forster 2004) which enables finding a reconstrution for the unknown x as either the posterior maximizer, i.e., maximum a posteriori (MAP) or the conditional mean (CM) of the posterior probability density. In HBM, the posterior probability for x is defined via choosing the standard deviation of a Gaussian likelihood density, the hypermodel, i.e., the gamma (G) or inverse gamma (IG) hyperprior determining the actual prior, and the shape and scale parameter β and 𝜃0 for the hyperprior. For a given measurement vector y, the Bayes formula (O’Hagan and Forster 2004) for the posterior is of the form
$$ p (\mathbf{x} \mid \mathbf{y}) = \frac{p(\mathbf{x}) p(\mathbf{y} \mid \mathbf{x})} {p(\mathbf{y})} \propto {p(\mathbf{x}) p(\mathbf{y} \mid \mathbf{x})}, $$
where p(x) is the prior density and p(yx) the likelihood function (Schmidt et al. 1999). Here, the noise term n, which together with the forward model (1) implies the likelihood p(yx), is assumed to be a Gaussian zero-mean random vector with independent entries.

In HBM, the prior can be expressed in the following hierarchical form p(x,h) ∝ p(𝜃)p(x𝜃), where 𝜃 is the primary hyperparameter of the model. The conditional part p(x𝜃) of the prior is a zero-mean Gaussian density, whose diagonal covariance matrix is predicted by the hyperprior p(𝜃). The hyperprior is assumed to have a long-tailed density, implying that x is likely to be a sparse vector corresponding to a well-localized (focal) volumetric distribution. In ZI, it is either G or IG density (Calvetti et al. 2009), which are controlled by the shape and scale parameter β and 𝜃0. The G and IG hyperprior can be coupled into a single model in a straightforward way, since the reciprocal 𝜃− 1 of a G-distributed random variable 𝜃 with respect to β and 𝜃0 is IG-distributed w.r.t. β and \(\theta _{0}^{-1}\).

A description of the IAS algorithm applied in ZI can be found in Appendix B. ZI’s CM estimation technique is based on the Gibbs sampler algorithm (Spitzer 1971; Murphy 2012) according to (Calvetti et al. 2009).

Hardware Requirements

ZI is principally designed to be used with a workstation or a high-end desktop computer with tens of gigabytes of RAM, a multi-core CPU and one or more GPUs. When generating the FE mesh and the LF matrix ZI is likely to allocate several gigabytes of RAM. A one-millimeter FE mesh resolution might lead to 64 GB of motherboard RAM and 2–4 GB of GPU RAM allocation during the forward computations. The resulting FE mesh will consist of 3-4 M nodes and 20-30 M elements, and the eventual project size, when stored on a hard disk, will be 0.5–1 GB.

GPU Function

ZI utilizes a GPU to accelerate the FE mesh generation process, forward and inverse computations, source interpolation and decompositions, as well as to speed up 3D visualizations. This is vital in order to achieve a convenient, around one hour computing time for a one-millimeter FE mesh resolution which has been shown to be essential in order to obtain physiologically accurate inverse estimates (Rullmann et al. 2009). A GPU is a parallel processing unit which has somewhat limited RAM compared to the motherboard. It can handle computation intensive operations very effectively, while memory intensive operations should be avoided. The operations related to forward and inverse computations can be accelerated due to the fast processing of matrix-vector products in a GPU. The other GPU operations are mainly based on the acceleration of find and sort routines, evaluating those as blocks rather than individual entries.

Forward Simulation

In the Matlab environment, the most essential speed-up gain is related to the sparse FE matrix-vector products which need to be evaluated iteratively in the forward simulation phase. The GPU-parallelization of the forward simulation is especially important, because Matlab currently handles the sparse matrix products in a single processor thread. To evaluate the lead field matrix as described in Appendix A, ZI uses the preconditioned conjugate gradient (PCG) (Golub and van Loan 1989) method with a lumped diagonal preconditioner (LDP) in which each diagonal entry is obtained as the row sum of the absolute entry values. LDP is an advantageous preconditioner regarding the limited GPU memory. While LDP is not optimal with respect to minimizing the iteration steps needed for convergence, it enables establishing a fast forward solver due to the high parallel processing performance provided by a GPU.

IAS Iteration

In the IAS iteration (Appendix B), the most time consuming step is the third one, Eq. 7, in which the size of the matrix to be inverted is determined by the length of the data vector. If a high number of time steps will need to be processed, the fastest processing is obtained by evaluating the matrix-vector product of Eq. 7 in a GPU.

Interface Structure and Function

When started, ZI creates a single data structure (struct) zef in Matlab’s base workspace. All the parameters and variables, such as the lead field matrix, measurement data and reconstruction, can be accessed via the zef structure. The basic workflow consists of three phases illustrated in Fig. 1. In this section, we briefly review the workflow and introduce the most important fields of zef for each phase.
Fig. 1

The basic three-phase workflow in ZI. In phase 1, the head model is first defined using the segmentation tool, after which, in phase 2, the three-dimensional FE mesh and the LF matrix are generated with the mesh tool. Finally, in phase 3, the inverse tools can be applied to reconstruct and analyze parameter distributions, e.g., the primary current density of the brain activity. The parcellation tool can be applied in each of the phases 1–3 to assist decomposing the brain into a finite set of ROIs

Segmentation Tool

In the first phase, a surface segmentation describing different tissue structures and properties within Ω is defined using the segmentation tool (Fig. 2). A triangular surface mesh for each tissue type is imported in ZI as an ASCII file. In the current version, a single head model can contain up to 27 different tissue compartments. Moreover, several surface meshes (sub-meshes) can be merged together into a single compartment, e.g., the left and right hemisphere of the cerebral cortex. A multi-compartment segmentation can be defined in a single initialization (.INI) file which allows importing a complete head segmentation at once. The nodes and points of each surface mesh can be stored either in two separate .DAT files or in a single .ASC file exported from the FreeSurfer2 Software Suite (Fischl 2012).

The default set of compartments includes white matter, grey matter, cerebrospinal fluid (CSF), skull, and scalp, whose default conductivity values are 0.14, 0.33, 0.0064, and 0.43 S/m, respectively, according to Dannhauer et al. (2011); Vorwerk et al. (2014). Each compartment can be defined as active or inactive. The set of active compartments contains the DOFs of x. In EEG/MEG, the activity can be either constrained or unconstrained. In the former case, it is restricted into the direction of the surface normal, and in the latter case, it can have any orientation.

Mesh Tool

Fig. 2

A screenshot of ZI with figure, mesh, parcellation, and option tool opened

Fig. 3

Top row: Surface and volume visualizations of the head model in ZI. Bottom row: FreeSurfer-based cortical parcellation with 36 Desikan-Killiany labels

In the second phase of the workflow, a uniform tetrahedral mesh is generated based on the surface segmentation. The meshing parameters can be defined in the mesh tool. The meshing process proceeds from the innermost (detail) compartment to the outermost one. It allows the tissue boundaries to intersect each other which is necessary with a real segmentation obtained from magnetic resonance imaging (MRI) data. Each compartment can be given a priority which is referred to if a tetrahedron has nodes in two or more compartments. The priority parameter allows fine-tuning the width of the thin tissue layers, e.g., the skull: the lower the value the higher the priority. The FE mesh can be also smoothed using the Bi-Laplacian smoothing flow (Ohtake et al. 2001; Pursiainen 2012). After generating the mesh, the LF matrix can be computed for a selected imaging modality and a given number of the degrees of freedom (DOFs). Finally, an interpolation process connecting the DOFs and the FE mesh nodes needs to be performed, to enable inversion of measurement data.

Together with the figure tool, the mesh tool allows one to visualize both the surface segmentation and the volumetric FE mesh, or any surface or volumetric distribution (reconstruction) defined on those. The visibility of a compartment can be selected in the Segmentation tool. The options tool includes additional options which control, e.g., the colormap, scale, vector component, and the index of the sub-mesh for the visualized distribution, e.g., that of the left or right hemisphere (see Section “Segmentation Tool”). An example of a multi-layer surface segmentation and the resulting volumetric mesh created with ZI are shown in Fig. 3. For further code development, the most important fields of zef are the following:
  1. 1.

    zef.nodes and zef.tetra store the nodes and tetrahedra of the FE mesh, respectively;

  2. 2.

    zef.L is the lead field matrix;

  3. 3.

    zef.source_positions stores the source positions corresponding to the columns of zef.L in the respective order. This array contains the DOF positions also if they do not represent neural sources, which is the case in EIT.

  4. 4.

    zef.source_directions contains the source orientations. If Cartesian orientations are used, this field is empty, and the source orientation for the columns of zef.L is given by the following regular pattern: position 1, xyz; position 2, xyz; position 3, xyz, etc.;

  5. 5.

    zef.source_interpolation_ind stores the indices that connect the finite element mesh with the DOFs;

  6. 6.

    zef.h_axes1 stores the axes handle of the figure tool.


Inverse Tools

In the third phase, the measurement data are imported and, after that, a reconstruction for x can be obtained using one of the inverse tools. A MAP estimate can be obtained via the IAS method using one of the following tools:
  1. 1.

    IAS MAP estimation which finds a MAP estimate for the whole domain;

  2. 2.

    IAS MAP estimation ROI which focuses on a ROI;

  3. 3.

    IAS MAP multiresolution which explores multiple different resolutions.

A CM estimate can be obtained for a ROI using the Hierarchical Bayesian sampler tool. For external inverse procedure development, the most important fields are the following:
  1. 1.

    zef.measurements is the set of measurements to be inverted; this field can be a matrix or a cell array with the number of rows and columns equal to that of zef.L and the time steps in the dataset, respectively;

  2. 2.

    zef.reconstruction is the reconstruction of x corresponding to the set of source positions and orientations.


Parcellation Tool

The parcellation tool (Fig. 2) allows importing a parcellation created with the FreeSurfer Software Suite. A single parcellation consists of a file containing a colortable (.MAT) and another one including the points/labels (.ASC). After importing, an interpolation process will need to be performed to connect the points with the DOFs. The parcellation can be used as a priori information in the reconstruction or visualization stage. After obtaining a reconstruction, one can evaluate a time series of the activity for each region present in the parcellation. The time series can represent, e.g., the maximal or median activity within a region. The purpose of the time series is to enable the analysis of different statistical properties and connectivity of the activity over a time interval. In the current version, e.g., the amplitude, standard deviation, correlation, covariance, and dynamic time warping (DTW) (Sakoe and Chiba 1978) measure can be evaluated. The most important fields w.r.t. the parcellation tool are the following:
  1. 1.

    zef.parcellation_colortable and zef.parcellation_points store the colortable and points of the parcellation;

  2. 2.

    zef.parcellation_interp_ind contains the indices connecting the parccellated brain regions and the DOFs;

  3. 3.

    zef.parcellation_time_series stores the time series obtained for the brain regions after reconstructing the brain activity.


Plugin Utility

ZI can be extended via the plugin utility. The list of plugins is defined in the zeffiro_plugins.ini file which is located in ZI’s root folder. A menu item will be created for each listed plugin. The Hierarchical Bayesian sampler tool (Spitzer 1971; Murphy 2012) is included in the code package as an example plugin (HBSampler).

Numerical Experiments

In the numerical experiments, we demonstrate the practical performance of ZI and the IAS MAP estimation technique via numerical experiments in which EEG and EIT inversion is tested with real and synthetic data, respectively. We also analyze the effect of hyperprior and scale parameter on the source localization in EEG using simulated measurements.

EEG Inversion Test

Fig. 4

A butterfly plot of EEG inversion test (Section “EEG Inversion Test”) data which were obtained by averaging 58 epileptiform discharges between -5 and 5 s. The vertical axis shows the measured voltage in microvolts, and the horizontal axis the measurement time in seconds. The reconstruction was found for the zero time point 0 s which is indicated by the vertical dashed line

To enable comparability of the results to an existing solver, in this case that of the Brainstorm3 software (Tadel et al. 2011), EEG source localization accuracy was examined by inverting Brainstorm’s EEG and epilepsy tutorial dataset4 which was used with the consent of Prof. A. Schulze-Bonhage, Epilepsy Centre, University Hospital Freiburg, Germany. The dataset was obtained for a patient who had suffered from focal epilepsy with focal sensory, dyscognitive and secondarily generalized seizures since the age of eight years. It consists of 58 epileptiform discharges (spikes) which were recorded at 256 Hz frequency and detected using Brainstorm by the epileptologists in Freiburg. An invasive EEG study concentrating on the same subject can be found in Dümpelmann et al. (2012).

Following the tutorial, the measurement data to be inverted, depicted in Fig. 4, were obtained for 29 electrodes applying an epoching time interval between -5 and 5 s w.r.t. the time point of the inverted data. All the non-EEG channels have been removed from the measured data. The brain activity was reconstructed via two steps of the IAS MAP estimation algorithm with low-cut and high-cut frequency of 0.5 Hz and 80 Hz, assuming that the likelihood standard deviation is 3 % of the maximum entry in the data, and selecting the shape and scale parameters as β = 1.5 and 𝜃0 = 1E-12. The head model linked to the dataset consists of the surface meshes of the scalp, skull, CSF, grey matter, and white matter. ZI’s default conductivity values were used. The LF matrix was generated for 100000 sources using 1 mm mesh resolution. The reconstructions were obtained with ZI’s IAS MAP estimation inverse tool.

EIT Inversion Test

EIT inversion was examined numerically using the population head model5 which includes a scalp, skull, CSF, ventricle, grey matter, and white matter compartment (Lee et al. 2016). The default conductivity values were applied, associating the condutivity of the ventricles with that of the CSF. A total of 72 ring electrodes with an assumed 1 kOhm impedance and an outer and inner diameter of 10 and 7.5 mm, respectively, were modeled through the complete electrode model (CEM) described in Appendix A.

The head model was discretized using 1 mm mesh resolution. The FE mesh is shown in Fig. 6. A LF matrix was evaluated for a total number of 5000 DOFs using the approach presented in Appendix A and the original piecewise constant conductivity as the background distribution, i.e., the point of the linearization. The DOFs were distributed in the CSF, white matter and grey matter compartment.

The synthetic data were generated by perturbing the conductivity inside the brain within a spherical 30 mm diameter sub-domain representing an intracerebral hemorrhage (Broderick et al. 1993). Following, e.g., Li et al. (2017); Tang et al. (2010), the magnitude of the perturbation was set to be + 0.73 S/m and the signal-to-noise ratio was assumed to be 60 dB. The measurement errors consisted of additive Gaussian zero-mean white noise.

The likelihood standard deviation was set to be 12 % conciding approximately with the level following from the noise model. The IG hyperprior was employed selecting the shape and scale parameters as β = 1.5 and 𝜃0 = 0.001. To reconstruct the deep-lying anomaly, the total set of DOFs was decomposed into randomized 300 subsets which were formed w.r.t. an equal number of randomly (uniformly) distributed center points via the nearest point interpolation technique. The MAP estimate was found by performing two steps of IAS iteration for altogether 100 such randomized decompositions. A serial approach was adopted: the estimate obtained for one decomposition was set as the initial guess for the next one. The final reconstruction was produced as the mean of the resulting 100 MAP estimates.

The motivation to use averaging was to reduce the effect of decomposition-related artifacts which we assumed to be identically distributed for each separate decomposition and, thus, converge towards an expectation of an asymptotical Gaussian distribution based on the law of random numbers and the central limit theorem (O’Hagan and Forster 2004). The averaged reconstruction was obtained using the IAS MAP multiresolution inverse tool which allows averaging the reconstruction over one or more resolution levels and multiple randomized decompositions. The resolution is determined by the number of subsets within a single decomposition which is here 300 in each.

Hypermodel and Parameter Selection

The HBM approach requires selecting the hypermodel together with an appropriate value for the shape and scale parameter β and 𝜃. To investigate the effect of the parameter selection on the IAS MAP estimation process, we compared the localization of a simultaneously active pair of synthetic deep and superficial 10 nAm source in the case of EEG. The reconstruction was found as the center of mass of the primary current distribution within two 30 mm ROIs centered at the actual source locations. The accuracy was measured by evaluating the position (mm) and orientation (degree) difference with respect to the exact sources. As the computation domain we used a six-compartment (white matter, grey matter, CSF, compact skull, spongious skull, scalp) head model corresponding to a 49-year old male subject with ZI’s default conductivity values. For the spongious part of the skull 0.028 S/m was selected (Vorwerk et al. 2014). The EEG LF matrix was formed for a cap of 72 electrodes. The effects of choosing the hyperprior h and scale parameter 𝜃0 were examined for the following four pars: (i) h = G,𝜃0 = 1E − 5, (ii) h = IG,𝜃0 = 1E − 5, (iii) h = G,𝜃0 = 1E − 9, and (iv) h = IG,𝜃0 = 1E − 9, respectively. The shape parameter β was set to be β = 1.5 in each case. Gaussian white noise with 2 % relative standard deviation was added in the data. Each reconstruction was evaluated for 50 different realizations of the noise vector. The inverse tool applied in the experiment was ZI’s IAS MAP estimation ROI.
Fig. 5

A surface and volume visualization of reconstructed brain activity (amplitude) obtained in the EEG inversion test (Section “EEG Inversion Test”). The left and right images correspond to G and IG hyperprior, respectively. Top row: An axial projection of the reconstructions interpolated on the surface of the grey matter compartment. Bottom row: The volumetric reconstructions cut by a coronal plane at the location of the maximal activity. The reconstructions have been normalized to one

Fig. 6

Left: An illustration of the synthetic hemorrhage (grey sphere) which was applied to generate the data of the EIT inversion tests. The diameter of the sphere was 30 mm and its conductivity was set to be 0.73 S/m higher compared to its surroundings. The unperturbed background conductivity distribution was assumed to be constant in each tissue compartment including white matter (white), grey matter (grey), CSF (green and blue), skull (khaki), and scalp (brown). The CEM electrodes (Appendix A.1) are shown as surface patches (black rings): Center: An averaged reconstruction of the synthetic hemorrhage found using the IAS MAP multiresolution inverse tool. The final distribution was produced as an average of altogether 100 different MAP estimates corresponding to different randomized decompositions of 300 DOFs as explained in Section “EIT Inversion Test”. Right: A reconstruction (an unaveraged MAP estimate) found for a single decomposition of 300 DOFs. The reconsructions have been normalized to one

Fig. 7

Top row: Examples of the center of mass (red pin) found for the deep and superficial source (1 and 2, respectively) in the cases (i)–(iv) with synthetic EEG data and the noise level of 2 %. The exact position of each source is also depicted (cyan pin). Bottom row: Box-plots showing the distributions (i)–(iv) of the position (millimeter) and angle error (degree) found for sources 1 and 2 and 50 different realizations of the noise vector


ZI’s forward simulation performance was evaluated w.r.t. the computing time for the head model described in Section “Hypermodel and Parameter Selection”. The mesh generation, LF matrix evaluation and interpolation processes took 21, 39 and 3.5 minutes, respectively, using NVIDIA6 Quadro P6000 GPU. GPU acceleration was also found to be necessary to obtain a reasonable computing time as it sped up these routines by more than a factor of ten.

EEG Inversion Test

The results of the EEG inversion test can be found in Fig. 5 which displays the reconstructed brain activity for the surface of the cortex and a volume cut corresponding to the location of the maximal activity. The reconstruction obtained with the IG hyperprior was observed to be more focal than the one corresponding to G. The surface visualizations obtained for the G and IG hyperprior confirm similar active area as illustrated in Brainstorm’s EEG and epilepsy tutorial, especially, compared to the outcome of the Brainstorm’s maximum of entropy on the mean (MEM) framework solution. The volume cuts show the depth of the reconstructed activity.

EIT Inversion Test

In the EIT inversion test, the averaged reconstruction found for the synthetic hemorrhage matched well with its exact location, which is shown in Fig. 6. A visual comparison between the averaged and unaveraged and reconstruction (Fig. 6) suggests that the averaging process was beneficial w.r.t. the localization accuracy. The resolution (level of detail) of the averaged reconstruction seems to be refined compared to that of the unaveraged one. Moreover, using a comparatively low number of DOFs (here 300) in each randomized decomposition was found to be necessary for detecting the hemorrhage.

Hypermodel and Parameter Selection

Figure 7 illustrates the source localization results obtained in the hypermodel and parameter selection test. G was observed to perform comparably well for the superficial ROI and IG for the deep one. This is reflected by the cases (i) and (iv) in which the utmost position accuracy was obtained in these ROIs, respectively. Moreover, for G, the larger scale parameter value seemed preferable to the smaller one, while, for IG, the situation was the opposite. Regardless of the hyperprior, selecting a smaller scale parameter seemed beneficial for localizing the deep source until a certain level, where noise effects started to affect the reconstruction.


This article introduced Zeffiro interface (ZI) version 2.2, a GPU accelerated Matlab tool for multi-modal FEM-based modeling of electromagnetic fields in brain imaging and investigations (Braess 2001; de Munck et al. 1988; Monk 2003). It was shown that, when aided by a state-of-the-art GPU, ZI allows one to invert a given set of EEG data for a physiologically accurate (Rullmann et al. 2009) one-millimeter volumetric multi-compartment head model within a reasonable one hour’s time. GPU acceleration is needed, specifically, in the forward simulation phase, that is, in the generation of the FE mesh and the LF matrix as well as in the interpolation process connecting the DOFs of the unknown with the nodes of the FE mesh. Since Matlab does not currently parallelize the sparse matrix operations in a CPU, the performance difference between CPU and GPU computations, both applicable in ZI, is particularly pronounced.

As the mutual performance of GPU- and CPU-based codes is strongly system-specific and depends on various factors in addition to the processors themselves, ZI was not directly compared to the alternative tools. These include, for instance, Duneuro7 (Nüßing et al. 2019) and SimBio8 (Fingberg et al. 2003) which are open source FEM libraries for EEG/MEG with similar functions as Zeffiro but utilizing C++ language. Brainstorm9 (Tadel et al. 2011) and Fieldtrip10 (Oostenveld et al. 2011) are alternative packages for the Matlab platform. The core forward modeling approach of Brainstorm is the BEM (He et al. 1987). Fieldtrip does not have an advanced forward and inverse modeling functions. None of these are currently capable of advanced FEM or GPU computations. The MNE-Python11 toolbox (Gramfort et al. 2013) is the leading option for Python. It allows utilizing a GPU, but is, nevertheless, limited to a BEM-based forward simulation.

The present results suggest that ZI enables robust inversion of multi-modal data. Firstly, the reconstructions obtained for Brainstrom’s EEG and epilepsy tutorial dataset show that ZI’s forward and inversion methods can be applied to detect brain activity. Secondly, based on the numerical results obtained in the EIT inversion test, it seems that ZI can also be extended for non-linear problems and inversion of scalar-valued fields. The IAS MAP estimation technique was found to be applicable for EIT via averaging MAP estimates obtained for a randomized set of low-resolution domain decompositions. This technique might be usable also for other imaging modalities, for example, to localize deep brain activity. Furthermore, the present EIT solver might be adapted for other applications involving current injections, such as transcranial electric stimulation (Herrmann et al. 2013) in which the brain activity is evoked through external stimuli.

Based on the hyperprior and scale parameter selection experiment, IG seems to be an advantageous choice for the sub-cortical areas, whereas G seems preferable for the cerebral cortex. The scale parameter applied in the former case should be generally lower than in the latter one. This baseline is in parallel with the previous findings (Calvetti et al. 2009) and might be optimized later on. We also emphasize that the parameter selection is generally a complicated issue which is not covered completely in this study. For example, the effect of the shape parameter, which partially overlaps with that of the scale parameter, is omitted here.

Compared to the BEM, the FEM has at least two major advantages when applied in EEG/MEG. Firstly, while a BEM solver slows down if the surface mesh resolution or the number of surfaces grows, the computational performance of the FEM is virtually independent of these factors. ZI’s current design takes this aspect into account, as altogether 27 tissue compartments, each one composed of sub-entities if needed, can be included in a single head model. The uniform mesh generator is well-suited for multi-compartment meshing, since unlike many widely used software, e.g., TetGen12 (Si 2015) and Netgen13 (Schöberl 1997), it allows the tissue boundaries to intersect each other without collapsing. This is essential in practice, since the segmentation routines utilizing MRI data do not always render the surfaces smoothly. Moreover, ZI performs appropriately with a high surface resolution, thereby, allowing one to directly use the detailed surfaces exported from the FreeSurfer14 Software Suite (Fischl 2012).

The second major benefit of the FEM is that the conductivity distribution can be anisotropic (Güllmar et al. 2010; Rullmann et al. 2009). ZI’s forward simulation routines are currently capable of handling anisotropicity. The current meshing routine, however, generates an isotropic conductivity distribution. Generating or importing an anisotropic distribution, e.g., from diffusion-weighted MRI data, constitutes a potential topic for the future work.

Another potential direction is to develop the inversion methodology: one might apply the HBM for sub-cortical areas (Seeber et al. 2019), with non-diagonal prior covariance structures and/or with sampling-based posterior exploration techniques, e.g., the Gibbs sampler (Spitzer 1971; Murphy 2012). From the practical viewpoint, there is also an obvious need to develop tools for various purposes including epochs, the covariance of the measurements, and connectivity, e.g., phase-locking (Lachaux et al. 1999). Clinical studies would be needed to validate ZI for different applications and measurement situations. Providing command line executable scripts for performing the main operations without the graphical user interface, e.g., in a computing cluster, is also a potential option.




QH, AR, and SP contributed equally to this study. This study was supported by the Academy of Finland Centre of Excellence in Inverse Modelling and Imaging 2018–2025. We are grateful for DAAD’s (Deutscher Akademischer Austausch Dienst) bilateral travel funding support between Mathematics and Statistics, Tampere University and Institute for Biomagnetism and Biosignal Analysis, University of Münster (Project: Advancing Finite Element Computations for Reconstructing and Manipulating the Human Somatosensory Cortex, Academy of Finland decision number 317165).


  1. Bauer, M., Pursiainen, S., Vorwerk, J., Köstler, H., Wolters, C.H. (2015). Comparison study for Whitney (Raviart-Thomas) type source models in finite element method based EEG forward modeling. IEEE Transactions on Biomedical Engineering, 62(11), 2648–56.CrossRefPubMedGoogle Scholar
  2. Braess, D. (2001). Finite elements. Cambridge: Cambridge University Press.Google Scholar
  3. Broderick, J.P., Brott, T.G., Duldner, J.E., Tomsick, T., Huster, G. (1993). Volume of intracerebral hemorrhage. A powerful and easy-to-use predictor of 30-day mortality. Stroke, 24(7), 987–993.CrossRefPubMedGoogle Scholar
  4. Calvetti, D., & Somersalo, E. (2007). A gaussian hypermodel to recover blocky objects. Inverse Problems, 23 (2), 733.CrossRefGoogle Scholar
  5. Calvetti, D., Hakula, H., Pursiainen, S., Somersalo, E. (2009). Conditionally Gaussian hypermodels for cerebral source localization. SIAM JImaging Sci, 2(3), 879–909.CrossRefGoogle Scholar
  6. Calvetti, D., Pitolli, F., Somersalo, E., Vantaggi, B. (2018). Bayes meets Krylov: statistically inspired preconditioners for CGLS. SIAM Review, 60(2), 429–461.CrossRefGoogle Scholar
  7. Cheney, M., Isaacson, D., Newell, J.C. (1999). Electrical impedance tomography. SIAM Review, 41(1), 85–101.CrossRefGoogle Scholar
  8. Cheng, K.S., Isaacson, D., Newell, J., Gisser, D.G. (1989). Electrode models for electric current computed tomography. IEEE Transactions on Biomedical Engineering, 36(9), 918–924.CrossRefPubMedGoogle Scholar
  9. Creutzfeldt, O.D., Fromm, G.H., Kapp, H. (1962). Influence of transcortical dc currents on cortical neuronal activity. Experimental Neurology, 5(6), 436–452.CrossRefPubMedGoogle Scholar
  10. Dannhauer, M., Lanfer, B., Wolters, C.H., Knösche, T.R. (2011). Modeling of the human skull in EEG source analysis. Human Brain Mapping, 32, 1383–1399. Scholar
  11. Dümpelmann, M., Ball, T., Schulze-Bonhage, A. (2012). Sloreta allows reliable distributed source reconstruction based on subdural strip and grid recordings. Human Brain Mapping, 33(5), 1172–1188.CrossRefPubMedGoogle Scholar
  12. Fingberg, J., Berti, G., Hartmann, H., Basermann, A., Wolters, C.H., Anwander, A., McCarthy, A., Woods, S. (2003). Bio-numerical simualtions with SimBio. NEC Research and Development, 44(1), 140–145.Google Scholar
  13. Fischl, B. (2012). FreeSurfer. NeuroImage, 62(2), 774–781.CrossRefPubMedPubMedCentralGoogle Scholar
  14. Golub, G., & van Loan, C. (1989). Matrix computations. Baltimore: The John Hopkins University Press.Google Scholar
  15. Gramfort, A., Luessi, M., Larson, E., Engemann, D.A., Strohmeier, D., Brodbeck, C., Goj, R., Jas, M., Brooks, T., Parkkonen, L., et al. (2013). MEG And EEG data analysis with MNE-python. Frontiers in Neuroscience, 7, 267.CrossRefPubMedPubMedCentralGoogle Scholar
  16. Güllmar, D., Haueisen, J., Reichenbach, J. (2010). Influence of anisotropic electrical conductivity in white matter tissue on the EEG/MEG, forward and inverse solution. A high-resolution whole head simulation study. NeuroImage Scholar
  17. Hämäläinen, M., Hari, R., Ilmoniemi, R.J., Knuutila, J., Lounasmaa, O.V. (1993). Magnetoencephalography — theory, instrumentation, and applications to invasive studies of the working human brain. Reviews of Modern Physics, 65, 413–498.CrossRefGoogle Scholar
  18. Hari, R., Baillet, S., Barnes, G., Burgess, R., Forss, N., Gross, J., Hämäläinen, M., Jensen, O., Kakigi, R., Mauguière, F., et al. (2018). IFCN-endorsed practical guidelines for clinical magnetoencephalography (MEG). Clinical Neurophysiology.CrossRefPubMedPubMedCentralGoogle Scholar
  19. He, B., Musha, T., Okamoto, Y., Homma, S., Nakajima, Y., Sato, T. (1987). Electric dipole tracing in the brain by means of the boundary element method and its accuracy. IEEE Transactions on Biomedical Engineering (6), 406–414.CrossRefGoogle Scholar
  20. Herrmann, C.S., Rach, S., Neuling, T., Strüber, D. (2013). Transcranial alternating current stimulation: a review of the underlying mechanisms and modulation of cognitive processes. Frontiers in Human Neuroscience, 7, 279.CrossRefPubMedPubMedCentralGoogle Scholar
  21. Lachaux, J.P., Rodriguez, E., Martinerie, J., Varela, F.J. (1999). Measuring phase synchrony in brain signals. Human Brain Mapping, 8(4), 194–208.CrossRefPubMedGoogle Scholar
  22. Lee, E., Duffy, W., Hadimani, R., Waris, M., Siddiqui, W., Islam, F., Rajamani, M., Nathan, R., Jiles, D. (2016). Investigational effect of brain-scalp distance on the efficacy of transcranial magnetic stimulation treatment in depression. IEEE Transactions on Magnetics, 52(7), 1–4.Google Scholar
  23. Li, G., Sun, J., Ma, K., Yan, Q., Zheng, X., Qin, M., Jin, G., Ning, X., Zhuang, W., Feng, H., et al. (2017). Construction of a cerebral hemorrhage test system operated in real-time. Scientific Reports, 7, 42,842.CrossRefGoogle Scholar
  24. Miinalainen, T., & Pursiainen, S. (2017). A case study of focal Bayesian EEG inversion for whitney element source spaces: mesh-based vs.Cartesian orientations. In EMBEC & NBC 2017 (pp. 1065–1068). Berlin: Springer.Google Scholar
  25. Miinalainen, T., Rezaei, A., Us, D., Nüßing, A., Engwer, C., Wolters, C.H., Pursiainen, S. (2019). A realistic, accurate and fast source modeling approach for the EEG forward problem. NeuroImage, 184, 56–67.CrossRefPubMedGoogle Scholar
  26. Monk, P. (2003). Finite element methods for Maxwell’s equations. Oxford: Clarendon Press.CrossRefGoogle Scholar
  27. de Munck, J., van Dijk, B., Spekreijse, H. (1988). Mathematical dipoles are adequate to describe realistic generators of human brain activity 35(11), 960–966.Google Scholar
  28. de Munck, J., Wolters, C.H., Clerc, M. (2012). EEG & MEG forward modeling. In Brette, R, & Destexhe, A (Eds.) Handbook of neural activity measurement. New York: Cambridge University Press.
  29. Murphy, K.P. (2012). Machine learning: a probabilistic perspective. Adaptive Computation and Machine Learning. Cambridge: MIT Press.Google Scholar
  30. Niedermeyer, E., & da Silva, F.L. (2004). Electroencephalography: basic principles, clinical applications and related fields, 5th edn. Philadelphia: Lippincott Williams & Wilkins.Google Scholar
  31. Nüßing, A., Piastra, M.C., Schrader, S., Miinalainen, T., Brinck, H., Wolters, C.H., Engwer, C. (2019). Duneuro-a software toolbox for forward modeling in neuroscience. arXiv:190102874.
  32. O’Hagan, A., & Forster, J.J. (2004). Kendall’s advanced theory of statistics, volume 2B: Bayesian inference Vol. 2. London: Arnold.Google Scholar
  33. Ohtake, Y., Belyaev, A., Bogaevski, I. (2001). Mesh regularization and adaptive smoothing. Computer-Aided Design, 33, 789–800.CrossRefGoogle Scholar
  34. Oostenveld, R., Fries, P., Maris, E., Schoffelen, J.M. (2011). FieldTrip: open source software for advanced analysis of MEG, EEG, and invasive electrophysiological data. Comput Intell Neurosci. Scholar
  35. Pursiainen, S. (2012). Raviart–thomas-type sources adapted to applied EEG and MEG: implementation and results. Inverse Problems, 28(6), 065,013.CrossRefGoogle Scholar
  36. Pursiainen, S., Lew, S., Wolters, C.H. (2016a). Forward and inverse effects of the complete electrode model in neonatal EEG. Journal of Neurophysiology. Scholar
  37. Pursiainen, S., Vorwerk, J., Wolters, C. (2016b). Electroencephalography (EEG) forward modeling via H(div) finite element sources with focal interpolation. Physics in Medicine and Biology, 61(24), 8502–8520. Scholar
  38. Rullmann, M., Anwander, A., Dannhauer, M., Warfield, S.K., Duffy, F.H., Wolters, C.H. (2009). EEG source analysis of epileptiform activity using a 1 mm anisotropic hexahedra finite element head model. NeuroImage, 44(2), 399–410.CrossRefPubMedGoogle Scholar
  39. Sakoe, H., & Chiba, S. (1978). Dynamic programming algorithm optimization for spoken word recognition. IEEE Transactions on Acoustics, Speech, and Signal Processing ASSP-26, 43–49.Google Scholar
  40. Schmidt, D.M., George, J.S., Wood, C.C. (1999). Bayesian inference applied to the electromagnetic inverse problem. Human Brain Mapping, 7(3), 195–212.CrossRefPubMedGoogle Scholar
  41. Schöberl, J. (1997). Netgen an advancing front 2D/3D-mesh generator based on abstract rules. Computing and Visualization in Science, 1(1), 41–52.CrossRefGoogle Scholar
  42. Seeber, M., Cantonas, L.M., Hoevels, M., Sesia, T., Visser-Vandewalle, V., Michel, C.M. (2019). Subcortical electrophysiological activity is detectable with high-density EEG source imaging. Nature Communications, 10(1), 753.CrossRefPubMedPubMedCentralGoogle Scholar
  43. Si, H. (2015). Tetgen, a delaunay-based quality tetrahedral mesh generator. ACM Transactions on Mathematical Software (TOMS), 41(2), 11.CrossRefGoogle Scholar
  44. Spitzer, F. (1971). Markov random fields and Gibbs ensembles. The American Mathematical Monthly, 78(2), 142–154.CrossRefGoogle Scholar
  45. Tadel, F., Baillet, S., Mosher, J.C., Pantazis, D., Leahy, R.M. (2011). Brainstorm: a user-friendly application for MEG/EEG analysis. Computational Intelligence and Neuroscience, 2011, 8.CrossRefGoogle Scholar
  46. Tang, T., Oh, S., Sadleir, R. (2010). A robust current pattern for the detection of intraventricular hemorrhage in neonates using electrical impedance tomography. Annals of Biomedical Engineering, 38(8), 2733–2747.CrossRefPubMedPubMedCentralGoogle Scholar
  47. Vauhkonen, M. (1997). Electrical impedance tomography and prior information. Kuopio, dissertation: University of Kuopio.Google Scholar
  48. Vorwerk, J., Cho, J.H., Rampp, S., Hamer, H., Knösche, T.R., Wolters, C.H. (2014). A guideline for head volume conductor modeling in EEG and MEG. NeuroImage, 100, 590–607.CrossRefPubMedGoogle Scholar

Copyright information

© The Author(s) 2019

Open Access This article is distributed under the terms of the Creative Commons Attribution 4.0 International License (, which permits unrestricted use, distribution, and reproduction in any medium, provided you give appropriate credit to the original author(s) and the source, provide a link to the Creative Commons license, and indicate if changes were made.

Authors and Affiliations

  1. 1.Information Technology, Faculty of Information Technology and Communication SciencesTampere UniversityTampereFinland
  2. 2.Mathematics and Statistics, Faculty of Information Technology and Communication SciencesTampere UniversityTampereFinland

Personalised recommendations