<!DOCTYPE article PUBLIC "-//NLM//DTD JATS (Z39.96) Journal Archiving and Interchange DTD v1.0 20120330//EN" "JATS-archivearticle1.dtd">
<article xmlns:xlink="http://www.w3.org/1999/xlink">
  <front>
    <journal-meta>
      <journal-title-group>
        <journal-title>D. Melnyk)</journal-title>
      </journal-title-group>
    </journal-meta>
    <article-meta>
      <title-group>
        <article-title>Feature Extraction from a Noisy ECG Signal by Clustering ECG Images</article-title>
      </title-group>
      <contrib-group>
        <contrib contrib-type="author">
          <string-name>Roman Melnyk</string-name>
          <xref ref-type="aff" rid="aff0">0</xref>
        </contrib>
        <contrib contrib-type="author">
          <string-name>Denys Melnyk</string-name>
          <xref ref-type="aff" rid="aff0">0</xref>
        </contrib>
        <aff id="aff0">
          <label>0</label>
          <institution>Lviv Polytechnic National University Lviv</institution>
          ,
          <country country="UA">Ukraine</country>
        </aff>
      </contrib-group>
      <pub-date>
        <year>2025</year>
      </pub-date>
      <volume>000</volume>
      <fpage>0</fpage>
      <lpage>0002</lpage>
      <abstract>
        <p>The presented work considers an approach to processing a single-channel ECG signal represented by an image cropped from a 12-lead protocol from a cardiograph. The signal is strongly noisy. The processing includes such algorithms as thresholding, flood filling, clustering, and others. The goal of processing is to formulate a graph that makes it possible to determine time intervals and geometric regions by which ECG graphs differ from each other, and by which they can be recognized and classified. The control parameters of the clustering algorithm enable the program to extract a discrete representation of graphs for varying levels of noise.</p>
      </abstract>
      <kwd-group>
        <kwd>eol&gt;ECG signal</kwd>
        <kwd>noise</kwd>
        <kwd>image processing</kwd>
        <kwd>threshold</kwd>
        <kwd>flood-filling</kwd>
        <kwd>clustering</kwd>
        <kwd>comparison</kwd>
        <kwd>pixel intensity 1</kwd>
      </kwd-group>
    </article-meta>
  </front>
  <body>
    <sec id="sec-1">
      <title>1. Introduction</title>
    </sec>
    <sec id="sec-2">
      <title>2. ECG image processing</title>
      <p>The visual ECG signal recorded by a standard device is not very clear, and on paper, it is connected
by dotted coordinate axes. An increased fragment of such a signal is shown in Fig. 1 (three R-waves
from the lead I.
identify the characteristics of this signal. Thus, the new ECG signal image with width W and height</p>
      <sec id="sec-2-1">
        <title>H is used for the calculation of the signal function:</title>
        <p>where bi,j is the intensity of a pixel in i-th row and j-th column (0 or 200, black or yellow).</p>
        <p>
          The new graph is more convenient both for doctors and for further determining its features. Its
thickness is one pixel; the waves are clearer. The illustrative Fig. 3 shows two ECG graphs: the
original image, from the cardiograph, and the processed one.
(
          <xref ref-type="bibr" rid="ref1">1</xref>
          )
        </p>
        <p>
          The determination of the time intervals, wave amplitudes is carried out by isolating the main
signal peaks. For this, the K-means clustering algorithm works with W columns of the image
matrix. According to their average intensity, calculated by formula (
          <xref ref-type="bibr" rid="ref1">1</xref>
          ), clusters of columns with the
same intensity are formed.
        </p>
        <p>If the task is selection only R-wave features, the two output clusters are the input parameter.
Fig. 4 shows the input and the output images for the normal ECG signal with three R-waves.</p>
        <p>If other waves and segments are needed to be selected, the number of output clusters is
accepted as 9 or more. Fig. 5 shows the clustered image and its graph of intensity in columns.</p>
        <p>All time measurements of R, T, P, Q, S-waves and amplitudes are made directly on the image.
The advantages of this calculation compared to the input signal are as follows: there is no
ambiguity in determining the coordinates (straight lines and right angles are available in the
graph), there are no fluctuations on the graph, and this simplifies finding the maximum and
minimum values.</p>
      </sec>
    </sec>
    <sec id="sec-3">
      <title>3. Feature extraction from nosy ECG signal image</title>
      <p>The proposed algorithm can be applied to noisy ECG signals. Fig. 6 shows the input noisy and
original ECG segments from [10].</p>
      <p>The thickness of the noised line (together with fluctuations) is large enough and cannot be
replaced by its skeleton (if it is a task). Two cases are possible: including the signal in the upper
part or the lower part of the ECG image. They are illustrated in Fig. 7. For illustration purposes
only, the black background is replaced by green in two images, and the black signal is represented
81
in dark yellow in the first image (Fig. 7a).</p>
      <p>To estimate the received function, the ECG image corresponding to the original signal without
noise (in Fig. 8) is clustered too (without axes and numerals).</p>
      <p>One of the two assumptions can be accepted for analysis: either noise is normally distributed or
follows an irregular distribution. In the first case, the ECG image includes the full noisy signal to
form the upper border of the yellow part (dark yellow in Fig7a into yellow), or the ECG image is
without the noisy signal (black in Fig. 7b into black of background). Then, the approach from the
2nd section is applied to one of the two ECG images.</p>
      <p>In the second case, the noise level is at a different height from the signal. To account for this
fact, two images are combined into one for analysis (Fig. 9). In the first part, noise is dissolved in a
black background, and in the second, it is added to the yellow part carrying the signal.</p>
      <p>In the case of the two-story ECG image, the height of the yellow column in the upper story is
hi (under the signal), and in the lower story hi+ (including the thickness of the signal). So, the
task is to find all features for the signal graph of the points hi+1/2 , i W.</p>
      <p>
        In the noisy ECG signal in Fig. 9, finding its features means determining the coordinates of all
the elevations and depressions of the signal. In the first step, the determination of the time
intervals is carried out by isolating the main signal peaks (R-waves) that are periodically repeated.
For this, the columns of the image matrix participate in the clustering process. According to their
average intensity, calculated by formula (
        <xref ref-type="bibr" rid="ref1">1</xref>
        ), clusters of columns with the same intensity are
formed.
      </p>
      <p>The K-means clustering algorithm works with W columns. For the task of selection only
Rwave coordinates, the given number of output clusters is 2. Fig. 10a shows the clustered two-story
ECG image with three R-waves. Fig. 10b shows its intensity graph.</p>
      <p>a
b</p>
      <p>To underline all main depressions and elevations of the signal, it is necessary to run the
clustering for three output clusters. The coordinates of their components underline peaks and
depressions. It is shown in Fig. 11a. Its graph and the original graph are shown in Fig. 11b.
a
b</p>
      <p>In the following experiment, the number of initial clusters is taken to be 8 or more, and the
width of a column is 9 pixels. The number of clusters controls the spread of the graph values. The
cluster width controls the initial column size. Fig. 12 shows a cluster image superimposed on a
two-story ECG image and shows peaks and valleys. Unfortunately, they are poorly visible due to
the different transparency of the two components.</p>
      <p>Three intensity graphs are shown in Fig. 13: of the clustered two-story and filled original
images, and the original image (without clustering. The peaks and valleys coincide in their
coordinates. The amplitude values differ slightly due to the omission of color transformation when
filling the two parts of the ECG signal image and assigning the average pixel intensity to the
83</p>
      <p>For comparison, the noisy ECG signal is shown with the intensity graph of the clustered
twostory image in Fig. 14. It is clear that the latter allows us to calculate the areas of all depressions
and elevations as well as their coordinates.</p>
      <p>To illustrate levels of strips in the clustered noisy ECG image, linearly distributed cumulative
histograms (silhouettes in this case) are built for them. Filled in yellow and black, this silhouette is
shown in Fig. 15.</p>
      <p>For comparison, the original ECG signal superimposed with a baseline image is shown in Fig.
16. It contains four colors to mark depressions, elevations, black, and yellow backgrounds.</p>
      <p>Finally, the approach allows us to extract rectangular regions to estimate different dips and
peaks in the ECG signal. Once computed, these regions can be accepted as input for machine
learning and classification.</p>
      <p>Then, the features characterizing the ECG signal are determined by subtracting the base level
image from the image of an informative signal (processed):</p>
      <p>Similar pixels remain unchanged, the larger one (yellow&gt;black) becomes red, and the smaller
one (black&lt;yellow) becomes blue. As a result, the difference image shows all the depressions and
elevations of the original signal. They are marked with two colors in Fig. 17: the first are blue, the
second are red.</p>
      <p>
        ( ) =  (
) −  (0)
(
        <xref ref-type="bibr" rid="ref2">2</xref>
        )
      </p>
      <p>The last operation completes the preparation of any signal image from the cardiograph to a
form with separated amplitude areas, ready for calculating the amplitude characteristics.</p>
      <p>The difference image is covered with a 1×10 grid (each period is covered with 5 equal
fragments). Dividing the intervals of different ECG signals into the same number of fragments
allows us to obtain characteristics of these signals of the same dimension, regardless of the heart
rate. The R-waves are excluded in Fig. 18.</p>
      <p>Then, the average percentage values of the ten color areas are reflected by a histogram for blue
and red components. As a result, the new view of the normal ECG signal is shown in Fig. 19.</p>
    </sec>
    <sec id="sec-4">
      <title>4. Application of machine learning</title>
      <p>The approach below is based on data obtained after processing images of some typical and test
signals. The data is time-independent and universal for all types of signals and their parts in
individual leads. To train and test the Brain.js neural network, time intervals, data from histograms
of signal difference images, namely: elevations and depressions regions, as well as baseline regions,
are used. Then, the machine learning software classifies the ECG signal image online immediately
after photographing the cardiogram according to the protocol received from the cardiograph. The
basis for comparing the new input signal is a set of previously collected and processed known ECG
signals.</p>
      <p>
        Two models have been developed for classification: the first by time intervals, and the second
by their time-independent features. In the first case, the distance between the R-waves should
belong to the interval 0.6-1.2 sec. Therefore, the training data has the form (-1, -1) for the time
interval less than 0.6 (tachycardia) and (
        <xref ref-type="bibr" rid="ref1 ref1">1, 1</xref>
        ) for the time interval more than 1.2 (bradycardia). The
test data has the form (
        <xref ref-type="bibr" rid="ref1">1, -1</xref>
        ) for the value within the required interval. Here, instead of just signs
(+, -), the value of one is taken.
      </p>
      <p>Thus, several operators for classification by the R-R distance, containing 2 input objects, are as
follows:
const network = new brain.NeuralNetwork();
network.train( [
{input:[1,-1], output:{normal:1}},
{input:[1,1], output:{tachycardia:1}},
{input:[-1,-1], output:{bradycardia:1}},
] );
let result = network.run([1,-1]);</p>
      <p>document.getElementById("demo").innerHTML =
"normal: " + result["normal"] + "&lt;br&gt;" + "bradycardia:
" + result["bradycardia"] + "&lt;br&gt;" + "tachycardia:
" + result["tachycardia"];
The result of this simple code is predictable:
normal:0.9129508137702942,
bradycardia:0.04934118315577507,
tachycardia: 0.07432011514902115.</p>
      <p>The second model can contain as many objects as the types of cardiograms that have been
processed to obtain their characteristics. Each object can be described by all components of the
histogram or only by its larger part, which represents the ST segment. It is obvious that the larger
the set of processed signals, the more components must be taken into account, while
simultaneously increasing the number of parts into which the intervals between R-waves are
divided.</p>
      <p>For the understanding of the logical flow of the application, only a few main JavaScript
operators are shown below (the number of iterations and the error threshold are controlled):
const network = new brain.NeuralNetwork();
// Train the Network with 4 input objects
network.train( [
{input:[-1.5, +0.8, 0, +32.0, -2.3, +4.2, -2.7, +2, -1.7,</p>
      <p>+1.1], output:{zero:1}},
{input:[-16.1, 0, -23.8, 0, 0, +2.9, 0, +4, -2.7,</p>
      <p>+0.5],output:{one:1}},
{input:[-5.5, 0, -20.8, 0, -7.5, +1.3, 0, +8, -5.1, 0],</p>
      <p>output:{two:1}},
{input:[0, +16, 0, +25, -1.5, 0, -1, 0, 0, +4.5],</p>
      <p>output:{three:1}},],
{
iterations: 50000,
errorThresh: 0.002,
} );</p>
      <p>To output the type of a heart disorder the following operator is used:
let result = network.run( [-4.5, +0.8, -18, 0.3, -5, 1, 0, +6,
6.1, 0] );
The classification results are as follows:
infarction: 0.05449743941426277,
normal: 0.04030778259038925,
abnormal: 0.9158487915992737,
ischemia: 0.0017213531536981463.</p>
      <p>In conclusion, the developed software, combined with machine learning, classifies four types of
ECG signals based on elevation and depression in the ST segment as well as heart rate regularity.</p>
    </sec>
    <sec id="sec-5">
      <title>5. Conclusions</title>
      <p>The presented work is an attempt to design a tool to assist a family doctor in quantitative and
qualitative analysis of an ECG graph obtained from a cardiograph. It considers an approach to
processing single-lead ECG images cropped from a 12-lead protocol recorded by a cardiograph and
photographed by a mobile device.</p>
      <p>Therefore, the input data are images, not numerical. Their processing consists of such
algorithms as thresholding, flood filling, K-means clustering, and others. The first two eliminate
background and artefacts. The rest simplify the function for finding temporal properties, stretch
the signal function, and select their depressions and elevations in a form of rectangles.</p>
      <p>The goal of processing is to formulate and determine temporal features and geometric regions
by which ECG graphs differ from each other, and by which they can be recognized and classified.
Image processing algorithms find the heart rate and its type of regularity, as well as the
depressions and elevations in amplitude in the signal period.</p>
      <p>The K-means clustering algorithm is used for the extraction of features from the noisy ECG
signal images. Data receives from image processing algorithms are prepared to be used in the
classification by Neural Networks.</p>
    </sec>
    <sec id="sec-6">
      <title>Declaration on Generative AI</title>
      <sec id="sec-6-1">
        <title>The authors have not employed any Generative AI tools.</title>
      </sec>
    </sec>
  </body>
  <back>
    <ref-list>
      <ref id="ref1">
        <mixed-citation>
          [1]
          <string-name>
            <given-names>A.</given-names>
            <surname>Burguera</surname>
          </string-name>
          ,
          <article-title>Fast QRS Detection and ECG Compression Based on Signal Structural Analysis</article-title>
          ,
          <source>IEEE Journal of Biomedical and Health Informatics</source>
          , Vol.
          <volume>23</volume>
          , No.
          <volume>1</volume>
          (
          <year>2019</year>
          )
          <fpage>123</fpage>
          131. doi:
          <volume>10</volume>
          .1109/JBHI.
          <year>2018</year>
          .
          <volume>2792404</volume>
          .
        </mixed-citation>
      </ref>
      <ref id="ref2">
        <mixed-citation>
          [2]
          <string-name>
            <given-names>M.</given-names>
            <surname>Ingale</surname>
          </string-name>
          ,
          <string-name>
            <given-names>R.</given-names>
            <surname>Cordeiro</surname>
          </string-name>
          ,
          <string-name>
            <given-names>S.</given-names>
            <surname>Thentu</surname>
          </string-name>
          ,
          <string-name>
            <given-names>Y.</given-names>
            <surname>Park</surname>
          </string-name>
          ,
          <string-name>
            <surname>N.</surname>
          </string-name>
          <article-title>Karimian, ECG Biometric Authentication: A Comparative Analysis</article-title>
          ,
          <source>IEEE Access</source>
          , Vol.
          <volume>8</volume>
          (
          <year>2020</year>
          )
          <fpage>117853</fpage>
          117866. doi:
          <volume>10</volume>
          .1109/ACCESS.
          <year>2020</year>
          .
          <volume>3004464</volume>
          .
        </mixed-citation>
      </ref>
      <ref id="ref3">
        <mixed-citation>
          [3]
          <string-name>
            <given-names>M. F.</given-names>
            <surname>Amri</surname>
          </string-name>
          ,
          <string-name>
            <given-names>M. I.</given-names>
            <surname>Rizqyaan</surname>
          </string-name>
          ,
          <string-name>
            <given-names>A.</given-names>
            <surname>Turnip</surname>
          </string-name>
          ,
          <article-title>ECG signal processing using offline wavelet transform method based on ECG-IoT device</article-title>
          ,
          <source>in: Proceedings of the 3rd International Conference on Information Technology</source>
          , Computer, and Electrical Engineering (ICITACEE),
          <year>2016</year>
          , pp.
          <fpage>1</fpage>
          <lpage>6</lpage>
          . doi:
          <volume>10</volume>
          .1109/ACCESS.
          <year>2023</year>
          .
          <volume>3308409</volume>
          .
        </mixed-citation>
      </ref>
      <ref id="ref4">
        <mixed-citation>
          [4]
          <string-name>
            <given-names>A.</given-names>
            <surname>Kumar</surname>
          </string-name>
          ,
          <string-name>
            <given-names>R.</given-names>
            <surname>Ranganathan</surname>
          </string-name>
          ,
          <string-name>
            <given-names>M.</given-names>
            <surname>Kumar</surname>
          </string-name>
          ,
          <string-name>
            <given-names>R.</given-names>
            <surname>Komaragiri</surname>
          </string-name>
          ,
          <article-title>Hardware Emulation of a Biorthogonal Wavelet Transform-Based Heart Rate Monitoring Device</article-title>
          ,
          <source>IEEE Sensors Journal</source>
          , Vol.
          <volume>21</volume>
          , No.
          <volume>4</volume>
          (
          <year>2021</year>
          )
          <fpage>5271</fpage>
          5281. doi:
          <volume>10</volume>
          .1109/JSEN.
          <year>2020</year>
          .
          <volume>3034742</volume>
          .
        </mixed-citation>
      </ref>
      <ref id="ref5">
        <mixed-citation>
          [5]
          <string-name>
            <given-names>H. B.</given-names>
            <surname>Seidel</surname>
          </string-name>
          ,
          <string-name>
            <surname>M. M.</surname>
          </string-name>
          <article-title>A. da</article-title>
          <string-name>
            <surname>Rosa</surname>
            , G. Paim,
            <given-names>E. A. C.</given-names>
          </string-name>
          da
          <string-name>
            <surname>Costa</surname>
            ,
            <given-names>S. J. M.</given-names>
          </string-name>
          <string-name>
            <surname>Almeida</surname>
            ,
            <given-names>S.</given-names>
          </string-name>
          <string-name>
            <surname>Bampi</surname>
          </string-name>
          ,
          <article-title>Approximate Pruned and Truncated Haar Discrete Wavelet Transform VLSI Hardware for EnergyEfficient ECG Signal Processing</article-title>
          ,
          <source>IEEE Transactions on Circuits and Systems I: Regular Papers</source>
          , Vol.
          <volume>68</volume>
          , No.
          <volume>5</volume>
          (
          <year>2021</year>
          )
          <year>1814</year>
          1826. doi:
          <volume>10</volume>
          .1109/TCSI.
          <year>2021</year>
          .
          <volume>3057584</volume>
          .
        </mixed-citation>
      </ref>
      <ref id="ref6">
        <mixed-citation>
          [6]
          <string-name>
            <given-names>S.</given-names>
            <surname>Shimauchi</surname>
          </string-name>
          ,
          <string-name>
            <given-names>K.</given-names>
            <surname>Eguchi</surname>
          </string-name>
          ,
          <string-name>
            <given-names>R.</given-names>
            <surname>Aoki</surname>
          </string-name>
          ,
          <string-name>
            <given-names>M.</given-names>
            <surname>Fukui</surname>
          </string-name>
          ,
          <string-name>
            <given-names>N.</given-names>
            <surname>Harada</surname>
          </string-name>
          ,
          <string-name>
            <surname>R-R Interval</surname>
          </string-name>
          <article-title>Estimation for Wearable Electrocardiogram Based on Single Complex Wavelet Filtering and MorphologBased Peak Selection</article-title>
          ,
          <source>IEEE Access</source>
          , Vol.
          <volume>9</volume>
          (
          <year>2021</year>
          )
          <fpage>60802</fpage>
          60827. doi:
          <volume>10</volume>
          .1109/ACCESS.
          <year>2021</year>
          .
          <volume>3070604</volume>
          .
        </mixed-citation>
      </ref>
      <ref id="ref7">
        <mixed-citation>
          [7]
          <string-name>
            <given-names>B.</given-names>
            <surname>Yuen</surname>
          </string-name>
          ,
          <string-name>
            <given-names>X.</given-names>
            <surname>Dong</surname>
          </string-name>
          , T. Lu,
          <article-title>Detecting Noisy ECG QRS Complexes Using WaveletCNN Autoencoder and ConvLSTM</article-title>
          , IEEE Access, Vol.
          <volume>8</volume>
          (
          <year>2020</year>
          )
          <fpage>143802</fpage>
          143817. doi:
          <volume>10</volume>
          .1109/ACCESS.
          <year>2020</year>
          .
          <volume>3012904</volume>
          .
        </mixed-citation>
      </ref>
      <ref id="ref8">
        <mixed-citation>
          [8]
          <string-name>
            <given-names>Y.</given-names>
            <surname>Hou</surname>
          </string-name>
          , R. Liu,
          <string-name>
            <given-names>M.</given-names>
            <surname>Shu</surname>
          </string-name>
          ,
          <string-name>
            <given-names>X.</given-names>
            <surname>Xie</surname>
          </string-name>
          ,
          <string-name>
            <given-names>C.</given-names>
            <surname>Chen</surname>
          </string-name>
          ,
          <article-title>Deep Neural Network Denoising Model Based on Sparse Representation Algorithm for ECG Signal</article-title>
          ,
          <source>IEEE Transactions on Instrumentation and Measurement</source>
          , Vol.
          <volume>72</volume>
          (
          <year>2023</year>
          )
          <article-title>1 11</article-title>
          . doi:
          <volume>10</volume>
          .1109/TIM.
          <year>2023</year>
          .
          <volume>3251408</volume>
          .
        </mixed-citation>
      </ref>
      <ref id="ref9">
        <mixed-citation>
          [9]
          <string-name>
            <given-names>C.</given-names>
            <surname>Lastre-Dominguez</surname>
          </string-name>
          ,
          <string-name>
            <given-names>V.</given-names>
            <surname>Jimenez-Ramos</surname>
          </string-name>
          ,
          <string-name>
            <given-names>H.</given-names>
            <surname>Azcaray-Rivera</surname>
          </string-name>
          ,
          <string-name>
            <given-names>E.</given-names>
            <surname>Perez-Campos</surname>
          </string-name>
          , J. MunozMinjares, Y. Shmaliy,
          <article-title>Denoising ECG Signals using Weighted Iterative UFIR Filtering</article-title>
          ,
          <source>WSEAS Transactions on signal processing</source>
          , Vol.
          <volume>19</volume>
          (
          <year>2023</year>
          )
          <fpage>148</fpage>
          157. doi:
          <volume>10</volume>
          .37394/232014.
          <year>2023</year>
          .
          <volume>19</volume>
          .16.
        </mixed-citation>
      </ref>
      <ref id="ref10">
        <mixed-citation>
          [10]
          <string-name>
            <given-names>S. A.</given-names>
            <surname>Chouakri</surname>
          </string-name>
          , F. B. reguig, S. Ahmaidi,
          <string-name>
            <given-names>O.</given-names>
            <surname>Fokapu</surname>
          </string-name>
          ,
          <string-name>
            <surname>Level-Dependent Wavelet</surname>
          </string-name>
          Denoising:
          <article-title>Application to very noisy ECG signals</article-title>
          ,
          <source>in: Proceedings of the 12th IEEE International Workshop on Systems, Signal and Image Processing (IWSSIP</source>
          <year>2005</year>
          ), Chalkida, Greece,
          <year>2005</year>
          .
        </mixed-citation>
      </ref>
    </ref-list>
  </back>
</article>