<!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>Proceedings</journal-title>
      </journal-title-group>
    </journal-meta>
    <article-meta>
      <article-id pub-id-type="doi">10.18287/1613-0073-2015-1490-262</article-id>
      <title-group>
        <article-title>The enhancement of the operating speed of the algorithm of adaptive compression of binary bitmap images</article-title>
      </title-group>
      <contrib-group>
        <contrib contrib-type="author">
          <string-name>Borusyak A.V.</string-name>
          <xref ref-type="aff" rid="aff0">0</xref>
        </contrib>
        <aff id="aff0">
          <label>0</label>
          <institution>Research Institute of Applied Mathematics and Cybernetics Lobachevsky Nizhni Novgorod State University National Research University</institution>
        </aff>
      </contrib-group>
      <pub-date>
        <year>2015</year>
      </pub-date>
      <volume>1490</volume>
      <fpage>262</fpage>
      <lpage>267</lpage>
      <abstract>
        <p>The paper deals with the problem of the enhancement of the operating speed of the algorithm of adaptive compression of binary bitmap images (BBI) on the basis of entropy coding using context simulation. The influence of the size of the maximal order context on the compression rate is considered. The enhancement of the speed of the algorithm depending on the number of the threads used is considered.</p>
      </abstract>
      <kwd-group>
        <kwd>compression</kwd>
        <kwd>optimization</kwd>
        <kwd>binary images</kwd>
        <kwd>context-based modeling</kwd>
      </kwd-group>
    </article-meta>
  </front>
  <body>
    <sec id="sec-1">
      <title>1. Introduction</title>
      <p>The development of specialized algorithms, targeted for a specific data type,
remains relevant in many areas. These algorithms use the knowledge of the internal
data structure to achieve a greater degree of compression. One of the important areas
is the compression of monochrome black-and-white binary images (MBI). Among the
most effective methods of compression of data with a certain structure and specificity
there are contextual data compression techniques based on the PPM technique
(Prediction by Partial Matching).</p>
      <p>The PPM algorithm involves entropy coding using individual context models (CM)
for each context, encountered in the stream of encoded data. Each CM includes the
counters for all the characters, encountered after the corresponding context. At the
same time, the implicit weighting of estimates is used for the application of the
context models of several orders. The PPM model itself only predicts the value of a
character, while the encoding itself is performed by an encoder using entropy coding
algorithms, such as Huffman's algorithm and arithmetic encoding.
this algorithm, as compared to the standard PPM algorithm, is the use of
twodimensional binary context of a specific shape and size, instead of standard
onedimensional context. The use of the property of the two-dimensionality of data in the
process of image compression makes it possible to substantially improve the
compression ratio, by taking into account the relationships between the neighboring
pixels both in horizontal and vertical directions.</p>
      <p>The algorithm uses a specific context shape and models of 31th, 11th, 7th, 4th and
zeroth order. The B-tree storage structure is used for the efficient storage of context
models in the memory.</p>
      <p>The following techniques and methods are used in the algorithm: the proprietary
algorithm of the estimation of the probability of escape, the method of exclusion of
the last encountered symbol, the method of scaling the last encountered symbol using
the chosen scaling factor, the modified method of information inheritance.</p>
      <p>An arithmetic encoder is used as the entropy encoder. The decoding process is
symmetric to the coding process.</p>
      <p>
        The implementation of the algorithm has shown high efficiency in terms of the
compression ratio (Rc), but the time expenditures were too high. The time, required
for encoding, was reduced by 1.5-2 times by optimization of the computation [
        <xref ref-type="bibr" rid="ref3">3</xref>
        ].
However, even after the optimization, the process of encoding remains
timeconsuming. Moreover, for large images with low redundancy the context model tree
grows too quickly, resulting in a high level of RAM consumption and frequent calls
for the context model tree purge procedure. The context model tree purge procedure is
required for the limitation of RAM consumption. At the same time, frequent calls for
this procedure slow down the operating speed of the algorithm and reduce the Rc.
      </p>
      <p>This paper deals with the problem of the reduction of the algorithm run-time and
RAM consumption. To further enhance the operating speed of the algorithm, the
methods of the parallelization and reduction of the size of maximal order context
(MOC) are proposed.</p>
    </sec>
    <sec id="sec-2">
      <title>3. Optimization of the time complexity of the algorithm</title>
      <p>
        One way to enhance the speed of the algorithm is the optimization of existing
computations. As part of the work [
        <xref ref-type="bibr" rid="ref2">2</xref>
        ], various approaches to the enhancement of the
operating speed of the algorithm by means of the optimization of computations are
proposed. The brief description of the proposed techniques is given below.
      </p>
      <p>In order to optimize the computation function of a new MOC, the sequence order
of the context pixels was changed from fixed, predetermined by a programmer, to
serial row-major, from the leftmost pixel of the context, which is in line with the pixel
to be encoded, to the rightmost, located as far as possible in vertical direction from the
pixel to be encoded. This conversion made it possible to reduce the number of access
operations to the image when calculating a new MOC from the value of the entire
context to the value of the context in height. In the transition to a new line of the
image, the fast computation was realized only for those context pixels that did not go
beyond the boundaries of the image. A method of calculating lower order contexts,
using the MOC calculated with the help of the predetermined mask, is proposed. A
mask is a fixed list of serial numbers of MOC pixels, specified by a programmer.</p>
      <p>In order to limit RAM consumption, the upper limit for the number of context
models, stored in a context model tree, is introduced. When the predefined limit is
exceeded, the tree of maximal order context models is purged completely.</p>
      <p>A link to a parent context model was added to each context model, in order to
accelerate the operation of identification of the parent context model, used in
information inheritance and in the escape to the lower order contexts.</p>
      <p>Initially, the algorithm used the AVL-tree structure to store the context models.
Various options of the storage of the model tree were considered. As a result of the
experimental testing, the B-tree turned out to be more efficient with respect to the
operating speed, and it was taken as the basic structure for the storage of the context
model tree.</p>
      <p>The transition of the program to the Qt 4.8.3 programming environment made it
possible to improve efficiency and make the program structure more flexible.</p>
      <p>The procedure of the updating of the percentage indicator of the
encoding/decoding process was also optimized to improve efficiency.</p>
      <p>The above approaches made it possible to reduce significantly, by 1.5-2 times, the
time, required for encoding/decoding. The RAM consumption was also limited.
Despite the fact that the acceleration proved to be essential, the algorithm still was
significantly slower than its counterparts. Due to that, the work on the improvement
of the algorithm performance was continued.</p>
    </sec>
    <sec id="sec-3">
      <title>4. The dependence of the main compression parameters on the value of the context</title>
      <p>One way to enhance the operating speed of programs is to identify the "hot spots of
a program" or, in other words, the parts of the program code, consuming the most
amount of computer resources. As a result of the research conducted by using a
profiler, it was found, that most of the CPU time and RAM are consumed by the
functions of calculating a new MOC and searching for a new CM in the CM tree. As
noted above, these functions have already been optimized with respect to
computation. However, it was noted, that MOC size has a strong influence on the
operation of the said functions. Consequently, MOC size affects not only the
compression ratio, but also the operating speed of the algorithm and the amount of
memory consumed. It has been suggested, that in case of decrease in the MOC size to
a certain level, Rc will be reduced slightly, but the compression rate will increase
significantly. In view of this, the experiments were conducted to identify the
dependence of Rc, compression time and RAM consumption on the MOC size. The
results of this experiment are presented in Table 1. According to the experiments
conducted, in case of the reduction of the size of the context to 15, the compression
ratio is reduced slightly, while a significant decrease in the time required for
compression and reduction of the amount of the RAM consumed are noted. The
reduction of MOC size to less than 15 leads to a significant reduction in the
compression ratio complete with less significant reduction in the RAM consumed and
the time required for compression. In Tables 1-3, the rows correspond to the number
of the compressed file, and the columns correspond to the size of the maximal order
File\context
1
2
3
4
5
File\context
1
2
3
4
5
context. At the same time, the reduction of MOC size to below 20 almost does not
affect the level of RAM consumption.</p>
    </sec>
    <sec id="sec-4">
      <title>5. Parallelization of the encoding algorithm</title>
      <p>
        Modern computers are often equipped with processors, containing multiple cores,
which enables parallel computing. This feature is currently often used to speed up the
algorithms. In order to further enhance the coding/decoding speed, the possibility of
encoding and decoding BBI through the parallelization of processing into multiple
threads was implemented in the compression algorithm. The parallelization algorithm
for the compression of indexed images [
        <xref ref-type="bibr" rid="ref3">3</xref>
        ] is used as the basis of the parallelization
algorithm. The ability to split the image into n parts is implemented. Assume the
vertical dimension (height) of the image for H, the horizontal dimension (width) for
W. The image is divided as follows: if the number of parts is equal to 4, the image is
divided along the lines, connecting the midpoints of the opposite sides. If n ≠ 4, the
vertical sides of the image are divided into n-1 equal parts with the height equal to
H/n, and one part with the height (H-H/n*(n-1)). After splitting the image into several
parts, each part of the image is compressed as an individual image in a separate
15
0.77
2.67
3.56
214.62
155.85
15
99.73
4.83
58.07
2.54
50.34
thread. This approach makes it possible to use the capabilities of modern computers,
evenly distributing the load on processor cores, while slightly reducing the
compression efficiency. It is assumed that with this approach, the increase in the
number of threads by n times will increase the compression rate to n times, provided
that the number n is less than or equal to the nc number of the processor cores. At the
same time, the rate will increase in proportion to the number of threads. If the n
number is greater than the nc, the increase in the compression rate, approximately
equal to the use of the nc threads, is expected. During the computation on a dual core
PC1 (CPU – Core 2 Duo E7400 2.8 GHz) and a quad-PC2 (CPU – Core i5-3230M
2.6 GHz) the following results were obtained:
      </p>
      <p>Where, in the first column of Tables 4 and 5 the number of threads used for image
encoding is indicated. In the second and the third columns the corresponding
encoding time in seconds is indicated for PC1 and PC2. The last column shows the Rc
for this file, depending on the number of the threads used. This ratio depends on the
number of threads, but doesn't depend on the computer used for encoding, so the two
computers possess the same factors. It is seen from the experiments, that, as expected,
1
2
4
8
16
32
64
1
2
4
8
16
32
64
the optimal number of threads is equal to the number of cores in the system. Thus, the
compression ratio reduces linearly, but very slightly, and at 64 threads, the losses less
than 3% are observed, while at n-16 threads, the losses are less than 1%.</p>
    </sec>
    <sec id="sec-5">
      <title>6. Conclusion</title>
      <p>The problem of the enhancement of the operating speed of the algorithm of
adaptive compression of binary bitmap images was considered. The experiments were
conducted for the enhancement of the operating speed of the proposed algorithm by
parallelizing the algorithm into several threads and reducing MOC size. Both
approaches proved to be effective. The MOC size, the reduction to which greatly
reduces the file encoding time and significantly reduces RAM consumption, while
only slightly reducing the Rc, was identified. The experiments were conducted for
parallelizing the algorithm into several threads. Using these two approaches together,
it is possible to enhance the rate of compression to an average of 8 times on a
computer with a 4-core processor, to reduce RAM consumption by 2 times, with the
average Rc losses being less than 10%.</p>
    </sec>
    <sec id="sec-6">
      <title>Acknowledgments</title>
      <p>This work was supported by RFBR (Projects No. 13-07-00521-А and No.
13-0712211 OFI_M.)</p>
    </sec>
  </body>
  <back>
    <ref-list>
      <ref id="ref1">
        <mixed-citation>
          1.
          <string-name>
            <surname>Borusyak</surname>
            <given-names>AV</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Vasin</surname>
            <given-names>YuG</given-names>
          </string-name>
          ,
          <source>Zherzdev SV. Compression of Binary Graphics Using Context Simulation. Pattern Recognition and Image Analysis</source>
          ,
          <year>2013</year>
          ;
          <volume>23</volume>
          (
          <issue>2</issue>
          ):
          <fpage>207</fpage>
          -
          <lpage>210</lpage>
          .
        </mixed-citation>
      </ref>
      <ref id="ref2">
        <mixed-citation>
          2.
          <string-name>
            <surname>Borusyak</surname>
            <given-names>AV</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Vasin</surname>
            <given-names>YuG</given-names>
          </string-name>
          , Zherzdev SV.
          <article-title>Optimizing the computational complexity of the algorithm for adaptive compression of binary raster images</article-title>
          .
          <source>Proceedings of The 11-th International Conference “Pattern Recognition and Image Analysis: new information technologies”</source>
          ,
          <year>2013</year>
          ;
          <volume>1</volume>
          :
          <fpage>170</fpage>
          -
          <lpage>172</lpage>
          .
        </mixed-citation>
      </ref>
      <ref id="ref3">
        <mixed-citation>
          3.
          <string-name>
            <surname>Borusyak</surname>
            <given-names>AV</given-names>
          </string-name>
          ,
          <article-title>Vasin YuG</article-title>
          .
          <article-title>Compression of indexed graphic images using context modeling</article-title>
          .
          <source>Vestnik of the Lobachevsky State University of Nizhni Novgorod</source>
          ,
          <year>2014</year>
          ;
          <volume>4</volume>
          (
          <issue>1</issue>
          ):
          <fpage>486</fpage>
          -
          <lpage>492</lpage>
          .
        </mixed-citation>
      </ref>
      <ref id="ref4">
        <mixed-citation>
          4.
          <string-name>
            <surname>Vatolin</surname>
            <given-names>D</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Ratushnyak</surname>
            <given-names>A</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Smirnov</surname>
            <given-names>M</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Yurkin</surname>
            <given-names>V</given-names>
          </string-name>
          .
          <article-title>Methods of data compression. Construction of archivers, image and video compression</article-title>
          . Moscow: Dialog - MEPHI,
          <year>2003</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref5">
        <mixed-citation>
          5.
          <string-name>
            <given-names>Vasin</given-names>
            <surname>YuG. Zherzdev SV</surname>
          </string-name>
          .
          <article-title>Information Techniques for Hierarchical Image Coding</article-title>
          .
          <source>Pattern Recognition and Image Analysis</source>
          ,
          <year>2003</year>
          ,
          <volume>13</volume>
          (
          <issue>3</issue>
          ):
          <fpage>539</fpage>
          -
          <lpage>548</lpage>
          .
        </mixed-citation>
      </ref>
      <ref id="ref6">
        <mixed-citation>6. Source &lt;http://www.imagecompression.info/test_images&gt;.</mixed-citation>
      </ref>
    </ref-list>
  </back>
</article>