**2. Theory of mathematical morphology**

#### **2.1 The basic principle**

The morphological transform is very widespread in the domain of signal processing and image processing because of its robustness and its simple and fast calculation [25, 26].

Mathematical morphology, based on set operations, provides an approach to the development of nonlinear methods of signal processing, in which the form of a signal's information is incorporated [27]. In these operations, the result of a data set transformed by another set depends on the shapes of both sets involved. A structuring element must be designed according to the characteristics of shape of the signal to be extracted.

There are two basic morphological operators: erosion ð Þ ⊖ and dilation ð Þ ⊕ .

Opening and closing are derived operators defined in terms of erosion and dilation [28].

These operators are described in detail below with the corresponding mathematical expressions. Throughout this document denotes the discrete ECG signal of point size and the symmetrical structuring element of M points.

a. Erosion.

To obtain the eroded function of f(x), we attribute to f(x) its minimum value in the domain of the structuring element B and this, at each new displacement of B (**Figure 2**). The following formula illustrates the erosion of the function f(x) (original signal) by a structuring element *B* plane:

$$\varepsilon\_{\mathcal{B}}(f) = (\ulcorner \ominus \mathcal{B})(n) = \min\_{m=0,\ldots,M-1} \{ \ulcorner f(n) - \mathcal{B}(m) \}\tag{1}$$

b. Dilation.

To obtain the dilated function of *f(x)*, we attribute to *f(x)* its maximum value in the field of the structuring element *B* and this, with each new displacement of *B* (**Figure 2**). The following formula illustrates the dilation of the function *f(x)* (original signal) by a structuring element *B* plane:

$$\delta\_{\mathcal{B}}(f) = (\, \, f \oplus \mathcal{B})(n) = \max\_{m=0,\ldots,M-1} \{ \, \, f(n) + \mathcal{B}(m) \}\tag{2}$$

Erosion shrinks peaks and the crest lines. The peaks narrower than the element structuring disappear. At the same time, it widens the valleys and the minima [29].

**Figure 2.** *a) Eroded ECG signal. b) Dilated ECG signal.*

The dilation produces the opposite effects (fills in the valleys and thickens the peaks).

#### c. Opening.

As in mathematical morphology, the opening consists of the erosion followed by dilation. The opening of *f(x)* by the structuring element *B* plane has the following consequences on the initial function (**Figure 3**):

The opening removes the peaks but preserves the valleys [30], according to the equation:

$$
\gamma\_B(f) = f \circ B = f \ominus B \oplus B \tag{3}
$$

d. Closing.

As in mathematical morphology, closing consists of dilation followed by erosion (**Figure 3**). The closing of *f(x)* by the structuring element *B* plane, for its part, has the following consequences on the starting function [31]:

The closing fills the valleys [32] as follows:

$$
\rho\_B(f) = f \bullet B = f \oplus B \ominus B \tag{4}
$$

The "closing" and "opening" operators behave like filters; these are in the same time morphological Filters [33].

The opening and closing by adjunction create a simpler function than the initial function, by softening the latter in a nonlinear manner.

Opening (closing) eliminates positive (negative) peaks respectively that are narrower than the structuring element.

The opening (the closing) is located below (above) the initial function.

e. Structuring element.

After the selection of the morphology operator, the structuring element (SE) is the next component of the morphological analysis to be defined. Generally, only when the shape of the signal matches those of the structuring element that the signal can be preserved. Therefore, the shape, length (domain) and size (amplitude) of the structuring element should be chosen according to the signal to be analyzed. The shapes of the structuring element can vary regularly or irregularly, such as a triangle, line (flat), or a semicircle.

**Figure 3.** *a) Opening ECG signal. b) Closing ECG signal.*
