OpenMEEG: opensource software for quasistatic bioelectromagnetics
- 15k Downloads
Interpreting and controlling bioelectromagnetic phenomena require realistic physiological models and accurate numerical solvers. A semi-realistic model often used in practise is the piecewise constant conductivity model, for which only the interfaces have to be meshed. This simplified model makes it possible to use Boundary Element Methods. Unfortunately, most Boundary Element solutions are confronted with accuracy issues when the conductivity ratio between neighboring tissues is high, as for instance the scalp/skull conductivity ratio in electro-encephalography. To overcome this difficulty, we proposed a new method called the symmetric BEM, which is implemented in the OpenMEEG software. The aim of this paper is to present OpenMEEG, both from the theoretical and the practical point of view, and to compare its performances with other competing software packages.
We have run a benchmark study in the field of electro- and magneto-encephalography, in order to compare the accuracy of OpenMEEG with other freely distributed forward solvers. We considered spherical models, for which analytical solutions exist, and we designed randomized meshes to assess the variability of the accuracy. Two measures were used to characterize the accuracy. the Relative Difference Measure and the Magnitude ratio. The comparisons were run, either with a constant number of mesh nodes, or a constant number of unknowns across methods. Computing times were also compared.
We observed more pronounced differences in accuracy in electroencephalography than in magnetoencephalography. The methods could be classified in three categories: the linear collocation methods, that run very fast but with low accuracy, the linear collocation methods with isolated skull approach for which the accuracy is improved, and OpenMEEG that clearly outperforms the others. As far as speed is concerned, OpenMEEG is on par with the other methods for a constant number of unknowns, and is hence faster for a prescribed accuracy level.
This study clearly shows that OpenMEEG represents the state of the art for forward computations. Moreover, our software development strategies have made it handy to use and to integrate with other packages. The bioelectromagnetic research community should therefore be able to benefit from OpenMEEG with a limited development effort.
KeywordsBoundary Element Method Electrical Impedance Tomography Functional Electrical Stimulation Head Model Forward Problem
Many devices used in the clinical or the cognitive science domain perform electromagnetic measurements, or stimulation, on the human body. Devices measuring electric fields include electro-encephalograms (EEG), -cardiograms (ECG), -myograms (EMG), while magneto-encephalograms (MEG) or magneto-cardiograms (MCG) measure magnetic fields. Among stimulating devices, transcranial magnetic stimulation (TMS) uses magnetic coils to stimulate brain regions, while functional electric stimulation (FES) and electrical impedance tomography (EIT) impose an electric current or potential through contact electrodes.
To interpret and control the bioelectromagnetic phenomena involved with these devices, realistic physiological modeling is required, in terms of geometry and conductivity . Accurate numerical solutions of the governing equations must be computed: obtaining the best accuracy possible for a given computational model is one of the goals of OpenMEEG, the opensource software package introduced in this article.
written here in the case where j = 0 on the boundary.
A forward problem consists of simulating V and/or B when σ, Jp, and boundary current j are known. The forward electro- magnetostatics problem is well-posed, in contrast to the far more difficult, ill-posed inverse problem of estimating σ, or Jp, from partial boundary data. Still, obtaining an accurate solution for the forward problem is far from trivial. This paper presents a software package, OpenMEEG, that makes available to the community recent research efforts to improve the accuracy of forward solvers.
Forward solutions provide the relationship between the quantities of interest and the measurements. To obtain a good description of this relationship, one must model the sources, the conductivity, and the sensors.
if the conductivity field can be described using simple geometries (with axilinear, planar, cylindrical, spherical or ellipsoidal symmetry), analytical methods can be derived, and fast algorithms have been proposed that converge to the analytical solutions for EEG [2, 3] and MEG ;
general non-homogeneous and anisotropic conductivity fields are handled by volumic methods; Finite Element Methods and Finite Difference Methods belong to this category.
This paper deals with Boundary Element Methods, whose advantage over volumic methods is to use an economic representation of the conductivity field (a few conductivity parameters - one per tissue, and a few triangular meshes to represent the interfaces). Until recently, all Boundary Element Methods used in bio-electromagnetics were based on a Green representation theorem, involving operators called single- and double-layer potentials. In OpenMEEG the approach is to consider an extended version of the Green representation theorem , involving more operators, and leading to a new BEM formulation, called the Symmetric Boundary Element Method .
The structure of the paper is as follows: the applications targeted by OpenMEEG are first presented, then some mathematical aspects of the Symmetric BEM are explained (details are presented in an appendix). Then, to motivate the use of OpenMEEG, a comparison study with four other solvers in the context of EEG forward modeling is presented. The accuracy of the solvers is tested on multiple random sphere models. The accuracy of OpenMEEG is also assessed by numerical experiments for MEG forward modeling. Finally a section provides technical details on the OpenMEEG software package while giving sample code for using OpenMEEG via Python or via the Fieldtrip Matlab toolbox. A more complete presentation of the usage of OpenMEEG via a command line interface is available in Additional file 1.
Target applications of OpenMEEG
The main purpose of OpenMEEG is to solve the forward problems arising in magneto- and electro-encephalography. OpenMEEG is therefore primarily developed in the field of brain research, but its development could directly benefit to other problems dealing with electromagnetic biosignals (see for example  in the context of electrocardiography). A geometrical model of nested meshes representing tissue interfaces must be provided to OpenMEEG, which does not perform any segmentation or meshing. OpenMEEG handles nested regions, and could in principle be extended to more general, disjoint regions . The main output of a forward problem is a leadfield, i.e., the linear application relating sources at specific locations to sensor measurements. Although the principal target of OpenMEEG is magneto- and electro-encephalography, other types of bioelectromagnetic problems have also been handled with OpenMEEG: we hereforth describe its current scope.
Electroencephalography (EEG) is concerned with the variations of electric potential on the scalp, due to sources within the brain. At frequencies of interest, the quasistatic regime is valid, resulting in the electrostatics relation (1). The air surrounding the scalp is supposed non-conductive, hence the normal current vanishes on the scalp: j = 0 in boundary condition (2). The sources within the brain are represented by dipoles: in equation (1), the sources are where p is a dipole position and the associated dipolar moment. OpenMEEG computes the electric potential and the normal current on each interface between two homogeneous tissues, due to electric sources within the brain. EEG sensors are electrodes, modeled in OpenMEEG as discrete positions on the scalp at which the potential can be measured (infinite impedance assumption). On these sensors, OpenMEEG computes the EEG leadfield, representing the linear relationship between source amplitude (for fixed position and orientation) and sensor values.
Magnetoencephalography (MEG) is concerned with magnetic fields produced by sources within the brain, which, like for EEG, are modeled as dipoles . OpenMEEG makes use of the Biot and Savart relation (3) to compute the magnetic field, and hence requires the electric potential to be computed beforehand on all the interfaces . Magnetometers or gradiometers can be modeled in OpenMEEG. Magnetometers are defined by their position and the direction of the field they measure. Gradiometers and more general sensors are handled by providing to OpenMEEG the positions, the orientations and the weights of integration points. For example with axial gradiometers present in CTF MEG systems, the forward field for a sensor is obtained by subtracting the two leadfields computed at the locations of two nearby magnetometers.
Electrical Impedance Tomography (EIT) infers characteristics of a conductive domain, by analyzing the potential resulting from the application of a current on the boundary. This method has been applied to calibrate the conductivity of EEG head models [12, 13, 14]. OpenMEEG computes the forward problem associated to EIT: given a conductive domain Ω defined by the interfaces between homogeneous regions, and their conductivity, and for a prescribed normal current j, OpenMEEG computes the potential V and the normal current σ∂ n V on each interface by solving (1) for Jp = 0, and with boundary condition (2). The electrodes are modeled with a P0 approximation over the triangles of the scalp; the injected current is assumed constant over a triangle.
Intracranial electric potentials are measured in certain clinical settings, either on the surface (ElectroCorticography) or within the brain (intracranial EEG, or stereotaxic EEG). OpenMEEG is able to compute leadfields for such intracranial electrodes, in realistic head models.
Functional Electrical Stimulation (FES) provides a way to restore movement of paralyzed body regions by activating the efferent somatic axons. For this a current is applied to a nerve sheath, using specially designed electrodes. The precise location and time course of the applied current must be optimized in order to achieve the best selectivity, and to minimize the current intensity for a desired outcome. Optimizing the stimulation parameter in a realistic nerve model requires a forward model for FES. OpenMEEG provides such a tool, by combination of the concepts of EIT and of internal potential simulation (see section on the applications targeted by OpenMEEG) [15, 16].
Cortical Mapping is an inverse problem that aims to recover the potential and the normal current occurring on the surface of the cortex (i.e., under the skull bone), given EEG measurements on electrodes . A particularly elegant solution to this problem has been proposed with the symmetric BEM , making it possible e.g. to solve further source localization problems.
OpenMEEG uses a Galerkin Boundary Element formulation, that jointly considers the electric potential and the normal current on each interface as unknowns of the problem. A P1 (piecewise linear) approximation is used for the electric potential, whereas the normal current is approximated with P0 (piecewise constant) boundary elements. The most intricate part of the implementation concerns the assembly of the system matrix, requiring singular kernel integration over triangles. Those are double integrals. The inner integrals are computed with analytical schemes , whereas the outer integrals are computed with a 7-point Gauss quadrature scheme . An adaptive integration scheme recursively subdivides the triangles until the required precision is achieved. This adaptive integration has an influence on the accuracy, as will be exposed in the benchmark results further on.
Since the electric potential can only be computed up to a constant, the system matrix is deflated to make it invertible. In practice, it consists of imposing the constraint that the integral of the potential over the external layer is 0.
The magnetic field is computed by using the Biot and Savart equation with the Galerkin piecewise linear approximation for the potential .
As stated above, given a set of dipole positions and orientations, a set of sensors and a head model defining homogeneous conductivity regions, the M/EEG forward problem produces as output the leadfield. OpenMEEG computes such lead fields with the following procedure (see the tutorial in Additional file 1 for a detailed graphical representation of this flowchart):
assemble the system matrix involving boundary integral operators on the discretized surfaces;
for a specified set of dipole positions and orientations, assemble a discretized, source-related term;
solve the linear system relating the two above matrices (providing V and on each interface)
interpolate the scalp potential (for EEG) or apply the discretized Biot and Savart relation (for MEG).
Mathematical details, as well as the practical usage of OpenMEEG can be found in the Appendix.
Methods: benchmark comparison study
In order to motivate the use of the OpenMEEG software, we have conducted a set of numerical experiments that compare the accuracy and the robustness of OpenMEEG with alternative M/EEG forward solvers. The comparison in the context of EEG forward modeling is run with the 4 alternative BEM solvers (see  for a comparison with FEM). The precision of the MEG forward solver is demonstrated using known analytical properties of the magnetic field when considering sphere models and with two other solvers.
Publicly available M/EEG forward solvers
Several software projects have the ability to solve the M/EEG forward problems. MNE, BrainStorm, EEGLAB (via the NFT Toolbox), Fieldtrip, Simbio, OpenMEEG and SPM, which shares with Fieldtrip the same M/EEG forward solvers.
Fieldtrip and SPM offer two implementations of the BEM. The first one, called Dipoli, was written by Oostendorp  and is not open source (only binary files for UNIX systems are available), while the second one, called BEMCP, is opensource and was written by Christophe Phillips during his PhD . The Dipoli solver implements a linear collocation method with Isolated Skull Approach (ISA) , whereas BEMCP implements a simple linear collocation method. The Dipoli implementation details can be found in . Another implementation with linear collocation (with and without ISA) can be found in the Matlab toolbox called Helsinki BEM . The MNE package written in pure C code by Hämäläinen also offers a linear collocation (with ISA) implementation of the BEM. The Brainstorm toolbox in its latest version uses only sphere models for both EEG and MEG. Recently the EEGLAB toolbox also has provided a package called NFT that is based on a BEM called METU . Finally, the Simbio forward solver also consists of a BEM with linear collocation and ISA.
Commercial software packages are not listed here. However, to our knowledge, commercial products that provide a BEM solver for forward modeling implement a linear collocation method with ISA. This is for example the case of ASA . Note also that beyond the field of brain research, alternative BEM implementation exist. The SCIRun/BioPSE project contains for example a BEM implementation based on  that can solve the forward problem of electrocardiography .
The accuracy of forward solvers can be assessed for simple geometries such as nested spheres, by comparison with analytical results. The precision of a forward solution is tested with two measures. the RDM (Relative Difference Measure) and the MAG (Magnitude ratio) .
In both of these expression, the norm is the discrete ℓ2 norm over the set of sensor measurements. The closer to 0 (resp. to 1) the RDM (resp. the MAG), the better it is.
Results: accuracy of the electric potential simulations
The implementations tested for EEG are: OpenMEEG with and without adaptive numerical integration (abbr. OM and OMNA), Simbio (abbr. SB), Helsinki BEM with and without ISA (abbr. HBI and HB), Dipoli (abbr. DP) and BEMCP (abbr. CP). The METU solver was also tested but we were unable to obtain the precisions advertised in , so it was decided not to include it in the comparison.
From these simulations it can be observed that:
HB and CP, that implement a simple linear collocation method, have similar results and are clearly the less precise solvers.
HBI, SB and DP, that implement a linear collocation method with ISA, have very similar results. SB and HBI are however slightly more accurate than DP.
OpenMEEG provides the most precise solutions even when no adaptive integration is used. The adaptive integration significantly improves the results, particularly when the meshes are coarsely sampled (42 and 162 vertices per layer).
Results: accuracy of the magnetic field simulations
We next present results for MEG forward modeling. MEG manufacturers propose 3 kinds of sensors (magnetometers, axial gradiometers, and planar gradiometers), all of which are oriented radially with respect to the helmet.
Results: computation speed
The OpenMEEG Software Package
All the tests performed in this paper were made using the version 2.0 of OpenMEEG.
OpenMEEG is distributed under the French opensource license CeCILL-B. It is intended to give users the freedom to modify and redistribute the software. It is therefore compatible with popular opensource licenses such as the GPL and BSD licenses. The CeCILL-B license imposes to anybody distributing a software incorporating OpenMEEG the obligation to give credits (by citing the appropriate publications), in order for all contributions to be properly identified and acknowledged. The references to be acknowledged are , and the present article.
OpenMEEG is implemented in C/C++ with limited external dependencies. It uses the Intel MKL libraries on Windows and ATLAS (BLAS/LAPACK) on Unix systems for fast and accurate linear algebra. A modified version of the MATIO library http://sourceforge.net/projects/matio has been integrated in OpenMEEG for Matlab compatible IOs for vectors and matrices. The source code of OpenMEEG is hosted on the INRIA GForge platform and is accessible to an anonymous user via a public version control system. OpenMEEG binaries and source code are both available from http://openmeeg.gforge.inria.fr.
OpenMEEG is available as precompiled binaries for GNU-Linux systems, Mac OS and Windows. OpenMEEG's build and packaging system is based on CMake/CPackhttp://www.cmake.org allowing easy development and deployment on all architectures.
Deployment on multiple architectures with heterogenous hardware and software environments requires testing procedures to assess the stability of the solutions provided by compiled binaries. This testing procedure is run through the CMake/CTest testing software. OpenMEEG test suite guarantees the integrity of the results obtained by MEG, EEG and EIT forward solvers. A part of the tests consists of running OpenMEEG on a 3-layer spherical geometry like the one presented in Figure 2. Outputs are then compared to analytical results to test that the accuracy is not degraded by a modification of the code.
Considerable efforts have been made to facilitate the use of OpenMEEG by the M/EEG community. OpenMEEG can be simply invoked via a command line interface, or via higher levels languages. OpenMEEG can also be called from Python or via the Fieldtrip Toolbox, where it has been fully integrated in the M/EEG forward modeling routines.
OpenMEEG demo script in Python
Import openmeeg as om
# Load data
condFile = 'om_demo.cond'
geomFile = 'om_demo.geom'
dipoleFile = 'cortex.dip'
squidsFile = 'meg_squids.txt'
electrodesFile = 'eeg_electrodes.txt'
geom = om.Geometry()
dipoles = om.Matrix()
squids = om.Sensors()
electrodes = om.Matrix()
# Compute forward problem
gaussOrder = 3; # Integration order
hm = om.HeadMat(geom,gaussOrder)
hminv = hm.inverse()
dsm = om.DipSourceMat (geom, dipoles, gaussOrder)
ds2 mm = om.DipSource2MEGMat (dipoles, squids).
h2 mm = om.Head2MEGMat (geom, squids)
h2em = om.Head2EEGMat (geom, electrodes).
gain_meg = om.GainMEG (hminv, dsm, h2 mm, ds2mm)
gain_eeg = om.GainEEG (hminv, dsm, h2em)
OpenMEEG demo script in Matlab
%% Structure for BEM volume conduction model
%% Each layer mesh is indexed by k
% vol.bnd(k).pnt. : vertices for mesh "k"
% vol.bnd (k).tri : triangles for mesh "k"
% %% Set the conductivities of each domain
% vol .cond : conductivities
%% EEG electrodes
% sens.pnt : locations of electrodes
%% Positions of the dipoles
% pos :locations of dipoles
%% Compute the BEM
% choose BEM method (OpenMEEG, BEMCP or Dipoli)
cfg.method = 'openmeeg';
% Compute the BEM matrix
vol = ft_prepare_bemmodel(cfg, vol);
cfg. vol = vol;
cfg. grid. pos = pos;
cfg. elec = sens;
% Compute leadfield
% with no orientation constraint
lf_openmeeg = ft_prepare_leadfield(cfg);
The benchmark presented in the previous section was run within the Fieldtrip environment and its MATLAB source code can be obtained for noncommercial use from the authors. Since SPM uses the same code as Fieldtrip for forward modeling, SPM can now benefit from integration of OpenMEEG. Moreover, the binary format used by OpenMEEG is that of Matlab, by use of the opensource MATIO library.
A sample dataset for M/EEG forward modeling can be downloaded from http://openmeeg.gforge.inria.fr. The sample dataset is provided with scripts that can be run to compute MEG and EEG leadfields on a realistic 3-layer model.
A tutorial for OpenMEEG is available on the web site, and it is briefly summarised in Additional file 1.The tutorial describes the low-level interface and details the different steps to be followed when computing M/EEG lead fields (Figure 9). Developper documentation can be generated via doxygen http://www.stack.nl/~dimitri/doxygen/.
In this paper, the OpenMEEG software project has been detailed, from the mathematical grounds of the symmetric BEM to more practical aspects.
The relevance of the OpenMEEG solver for quasistatic bioelectromagnetics has been demonstrated by a benchmark incorporating many alternative solvers in the context of M/EEG forward modeling. According to the results of this simulation study, OpenMEEG outperforms all the alternative solvers tested. By providing state-of-the-art solutions for both EEG and MEG forward problems, OpenMEEG enables the combined use of these two complementary modalities.
It should be mentioned that OpenMEEG is being used for many problems in the field of quasistatic bioelectromagnetics, including Electrical Impedance Tomography, Intracranial electric potentials, Functional Electrical Stimulation and Cortical Mapping. This wide range of application domains, as well as its integration into high-level languages make OpenMEEG unique and particularly valuable for basic and clinical research purposes.
The symmetric BEM
In early numerical experiments to compare a Boundary Element and a Finite Element Method (FEM) for forward electroencephalography, we found a superior accuracy of the FEM . This triggered a quest to improve the precision of Boundary Element Methods and led us to study the extended Green representation theorem . We proposed a common formalism for the integral formulations of the forward EEG problem, and derived three different Boundary Element Methods within the same framework . In this section we recall the mathematical background of Boundary Element Methods, and present both the double-layer BEM, which is the most widespread method, and the symmetric BEM, which is a new formulation.
A fundamental result in potential theory shows that a harmonic function (i.e., such that Δu = 0) is uniquely determined within a domain Ω from its value on the boundary ∂Ω (Dirichlet condition), or the value of its normal derivative (Neumann condition). The Green Representation Theorem gives an explicit representation of a piecewise-harmonic function as a combination of boundary integrals of its jumps and the jumps of its normal derivative across interfaces. Before stating this theorem, some notation must be defined.
The restriction of a function f to a surface S j is indicated by f sj .
- The functions and represent the interior and exterior limits of f on S j :
- The jump of a function f across S j is denoted by:
∂ n V = n·∇V denotes the partial derivative of V in the direction of a unit vector n,
The function is the fundamental solution of the Laplacian in ℝ3, such that -ΔG = δ0.
The notation is simplified by introducing two integral operators, which map a scalar function f on ∂Ω to another scalar function on ∂Ω: the "double-layer" operator , and the "single-layer" operators . For an operator , its restriction maps a function of S j to a function of S i .
where is the adjoint of the operator . The Geselowitz formula exploits only the first boundary integral representation equation (5), while it is possible to exploit both (5) and (6). Thus three Boundary Element Methods can be derived within a unified setting: a BEM involving only single-layer potentials, a BEM involving only double-layer potentials, and a symmetric BEM combining single- and double-layer potentials . We concentrate hereforth on the double-layer and on the symmetric BEMs.
The double-layer BEM
The above formula was established by Geselowitz , and was the only one used to model electroencephalography or electrocardiography, until recently, when  showed the diversity of BEMs that can be derived. This classical BEM is called a double-layer BEM because it only involves the double-layer operator .
The symmetric BEM
The originality of the symmetric Boundary Element Method is to consider a different piecewise harmonic function for each domain: the function u Ω i equal to within Ω i and to outside of Ω i . This is indeed harmonic in ℝ3\∂Ω i , and the representation equations (5) and (6) can be applied, leading to a system of integral equations involving two types of unknowns: the potential V i and the normal current (σ∂ n V) i on each interface.
where (resp.) is defined as σ i + σ j (resp. ) and where b1 and c1 are the coefficients of the P0 (resp. P1) boundary element decomposition of the source term (resp. ).
Blocks N ij and D ij map a potential V j on S j to a function defined on S i . Block S ij maps a normal current p j on S j to a function defined on S i . The resulting matrix is block-diagonal, and symmetric, hence the name "symmetric BEM".
In summary, the symmetric BEM introduces an additional unknown into the problem. the normal current, and uses an additional set of representation equations linking the normal current and the potential. The symmetric BEM departs from the double-layer BEM in several ways:
the normal current to each surface is explicitely modeled;
only the surfaces which bound a common compartment have an interaction (whence the blocks of zeros in the matrix);
only the surfaces which bound a compartment containing sources have a source term;
the matrix is symmetric;
the matrix is larger for a given head model.
The authors acknowledge support from the ANR grant ViMAGINE ANR-08-BLAN-0250-02, and for EO from a PhD grant from the Regional Council of Provence Alpes Cote d'Azur. Help is gratefully acknowledged from C. Micheli and R. Oostenveld regarding the integration of OpenMEEG within Fieldtrip, and from A. Anwander, M. Dannhauer and C. Wolters regarding the use of Simbio.
- 8.Voth EJ: The inverse problem of electrocardiography. industrial solutions and simulations. IJBEM 2005., 7(2):Google Scholar
- 12.Goncalves S, de Munck J, Verbunt J, Heethaar R, Lopes da Silva F: In vivo measurement of the brain and skull resistivities using an EIT-based method and the combined analysis of SEF/SEP data. IEEE Transactions on Biomedical Engineering 2003, 50(9):1124–1128. 10.1109/TBME.2003.816072CrossRefGoogle Scholar
- 14.Clerc M, Adde G, Kybic J, Papadopoulo T, Badier JM: In vivo conductivity estimation with symmetric boundary elements. In International Journal of Bioelectromagnetism Edited by: Malmivuo J. 2005, 7: 307–310.Google Scholar
- 15.Jacquir S, Fruitet J, Guiraud D, Clerc M: Computation of the electrical potential inside the nerve induced by an electrical stimulus. EMBC 2007: Proceedings of the 29th Annual International Conference of the IEEE Engineering in Medicine and Biology Society 2007.Google Scholar
- 16.Laforêt J, Guiraud D, Clerc M: A toolchain to simulate and investigate selective stimulation strategies for FES. EMBC 2009: Proceedings of the 30th Annual International Conference of the IEEE Engineering in Medicine and Biology Society 2009.Google Scholar
- 20.Bonnet M: Boundary Integral Equations Methods for Solids and Fluids. John Wiley and Sons; 1999.Google Scholar
- 21.Clerc M, Dervieux A, Faugeras O, Keriven R, Kybic J, Papadopoulo T: Comparison of BEM and FEM methods for the E/MEG problem. Proceedings of BIOMAG Conference 2002.Google Scholar
- 23.Phillips C: Source estimation in EEG. PhD thesis. Université de Liège; 2000.Google Scholar
This article is published under license to BioMed Central Ltd. This is an Open Access article distributed under the terms of the Creative Commons Attribution License (http://creativecommons.org/licenses/by/2.0), which permits unrestricted use, distribution, and reproduction in any medium, provided the original work is properly cited.