<!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 />
    <article-meta>
      <title-group>
        <article-title>Implementation of Image Processing Algorithms on the Graphics Processing Units</article-title>
      </title-group>
      <contrib-group>
        <contrib contrib-type="author">
          <string-name>Natalia Papulovskaya</string-name>
          <xref ref-type="aff" rid="aff0">0</xref>
        </contrib>
        <contrib contrib-type="author">
          <string-name>Kirill Breslavskiy</string-name>
          <xref ref-type="aff" rid="aff0">0</xref>
        </contrib>
        <contrib contrib-type="author">
          <string-name>Valentin Kashitsin</string-name>
          <xref ref-type="aff" rid="aff0">0</xref>
        </contrib>
        <aff id="aff0">
          <label>0</label>
          <institution>Department of Information Technologies of the Ural Federal University</institution>
          ,
          <addr-line>620002, 19 Mira street, Ekaterinburg</addr-line>
          ,
          <country country="RU">Russia</country>
        </aff>
      </contrib-group>
      <fpage>118</fpage>
      <lpage>125</lpage>
      <abstract>
        <p>The paper describes features of the multithreaded algorithms implementation on contemporary CPU and GPU. The features of access of a graphics processing unit (GPU) memory are reviewed. The bottlenecks have been identified, in which there is a loss of speed in image processing. Recommendations are made for optimization of algorithms for processing image of various size. Examples of implementation of the algorithms are given in the software and hardware architecture CUDA, which is well suited for a wide range of applications with high parallelism.</p>
      </abstract>
      <kwd-group>
        <kwd>Image processing</kwd>
        <kwd>Graphics processing unit</kwd>
        <kwd>Parallel computing</kwd>
        <kwd>CUDA</kwd>
      </kwd-group>
    </article-meta>
  </front>
  <body>
    <sec id="sec-1">
      <title>Introduction</title>
      <p>Differences between the CPU and GPU
Any program running on CPU uses the operating memory, processor cache, and
processor itself. Being run on GPU, the working process of a program is more
complex: the algorithm and data should be previously uploaded to GPU before
use. The majority of graphics adapters are implemented with the PCI-Express
bus, which has limited bandwidth. This is one of the reasons why the central
processing unit can perform calculations faster. Obviously, the value of the data
and memory uploading time is the crucial parameter for calculation speed.</p>
      <p>The CUDA memory model includes the host DRAM memory (regular
operating memory), device DRAM (graphics memory), and registered and shared
memory that are located on every multiprocessor of the graphics chip. The
CUDA threads have access to all kinds of the GPU memory, which differ by
scope, speed, and size (Table 1). The registered memory is used for local
variables. Other variables that exceed the registered memory are placed in the local
memory, which is suited outside of the chip and has low access speed. The shared
memory is used for interaction between the threads. All threads have read/write
access to the global memory. The scope for global memory is the whole
application, and contents of the global memory doesn’t change while starting different
cores. Moreover, the central processor has also access to the global memory; this
is why the global memory is used for data exchange between the CPU and GPU.</p>
      <p>Types of memory available for the CUDA applications</p>
      <sec id="sec-1-1">
        <title>Type</title>
      </sec>
      <sec id="sec-1-2">
        <title>Scope Registered Thread</title>
      </sec>
      <sec id="sec-1-3">
        <title>Local</title>
      </sec>
      <sec id="sec-1-4">
        <title>Shared Global</title>
      </sec>
      <sec id="sec-1-5">
        <title>Thread</title>
      </sec>
      <sec id="sec-1-6">
        <title>Block</title>
      </sec>
      <sec id="sec-1-7">
        <title>Application Low Up to 4 Gb</title>
      </sec>
      <sec id="sec-1-8">
        <title>Speed Size</title>
        <p>16384 registers
High per SM
Low</p>
      </sec>
      <sec id="sec-1-9">
        <title>Up to global memory size</title>
      </sec>
      <sec id="sec-1-10">
        <title>High 16 Kb per SM</title>
      </sec>
      <sec id="sec-1-11">
        <title>Applying</title>
      </sec>
      <sec id="sec-1-12">
        <title>Local variables</title>
      </sec>
      <sec id="sec-1-13">
        <title>Local variables,</title>
        <p>exceeding registered
memory
Threads inter operation
Data storage
with CPU</p>
        <p>Thus, the most data operations and exchange with the CPU are implemented
by the global memory, which has low speed, as seen from Table 1. The
memory delay problem in the CPU is solved by caching and code predicting. But
the GPU goes in the other way: in the case of waiting the data access in some
thread, the video chip attaches to another thread that has already got all
necessary data. Moreover, the video memory mostly has wider bandwidth than the
common memory. Instead of active cache memory used by the CPU, the graphics
cards have only 128-256 Kb of the cache memory, which is applied to bandwidth
extension and of reduction delays.</p>
        <p>Multithreading is supported in the GPU on the hardware level. Vendors
achieve instant switching between threads (by 1 clock cycle) and support up to
1024 threads on every core.</p>
        <p>Large number of threads in the CPU is not advisable due to significant time
loss while switching, which may consume up to several hundreds of clock-cycles.
In addition, one CPU core is able to process only 1 or 2 threads simultaneously.
3
3.1</p>
      </sec>
    </sec>
    <sec id="sec-2">
      <title>Benchmarks</title>
      <sec id="sec-2-1">
        <title>Baseline</title>
        <p>
          Performance tests were done on image processing algorithms software
implementation. Four different resolutions of image (50x50, 150x150, 300x300, and
512x512) were used with the quality of JPEG Quality 25 and JPEG Quality
100. As a reference image, the well-known file Lena.jpg [
          <xref ref-type="bibr" rid="ref6">6</xref>
          ], was used. Lenna or
Lena is the name given to a standard test image widely used in the field of image
processing since 1973.
        </p>
        <p>
          The images were processed by application of Sarcis [
          <xref ref-type="bibr" rid="ref7">7</xref>
          ] developed by the
Department of Information Technologies of the Ural Federal University. This
program is designed for image processing of color and gray scale images and
can be used for calculation both on the CPU and GPU. For the tests, four
algorithms were chosen: the weighted linear filter, reverse gradient filter, edge
detection Canny’s filter, and morphology processing filter erosion. An example
of application of the Canny’s filter is shown in Fig.1. Workstation configurations
CPU Intel Core i5-2450 (4 threads, 2.5Ghz), GPU NVIDIA GT630M (96 CUDA
cores, 800Mhz);
CPU Intel Core i7-860 (8 threads, 2.8Ghz), GPU NVIDIA GTX260 (216 CUDA
cores, 576Mhz);
CPU Intel Core i5-3470 (4 threads, 3.2Ghz), GPU NVIDIA GTX760Ti (1344
CUDA cores, 915Mhz).
3.2
        </p>
        <p>
          Theoretical description of filtering algorithms
Weighted linear filtering. The linear smoothing filters are good ones for
removing the Gaussian noise and, also, the other types of noise. A linear filter is
implemented using the weighted sum of the pixels in the successive windows.
Typically, the same pattern of weights is used in each window; this means that
the linear filter is spatially invariant and can be implemented using a convolution
mask. If different filter weights are used for different parts of the image (but the
filter is still implemented as a weighted sum), then the linear filter is spatially
varied [
          <xref ref-type="bibr" rid="ref8">8</xref>
          ].
        </p>
        <p>One of the simplest linear filters is implemented by a local averaging
operation where the value of each pixel is replaced by the average of all the values in
the local neighborhood. The weighted linear filtering mask is given by the mask
1 2 1
M = 116 2 4 2 . The main strategy is to set the largest weight at the central
1 2 1
pixel and inversely proportional to distance values to other pixels:</p>
        <p>Reverse gradient filter. The idea of the reverse gradient filter is in choosing
the mask weights. The greater bright difference between the central and the next
point, the less weight is prescribed to the next point.</p>
        <p>The mean gradient module value calculated for each aperture brightness level
is:</p>
        <p>HG(l) =</p>
        <p>1
h(l)
h(l)
X Glm(i, j)
m=1
Where HG(l) is the mean brightness gradient function value for l; h(l) is the
number of points with brightness l; Gl(i, j) is the gradient value in the mth point
 −1 −1 −1 
with brightness l at position (i, j). The Laplace operator 52 =  −1 +8 −1  is
−1 −1 −1
used to calculate the gradient value</p>
        <p>
          Canny filter. The Canny filter is considered to be the optimal choice for
any task, which requires edge extraction or edge enhancement of elements with
different shapes and characteristics. This is due to its easy implementation and
ability to be adapted to different circumstances [
          <xref ref-type="bibr" rid="ref9">9</xref>
          ].
        </p>
        <p>There are the following three criteria for the algorithm:
• smart detection (increasing the signal/noise ratio);
• good localization (correct definition of boundary position);
• only one response to the border.
The Canny filter differs from other classic edge detecting filters because it
considers directionality of the element and permits personalization of the filter behavior
by choosing the value of parameters of the algorithm. This provides changes in
direction of the filter polarization and sensibility of the edge extraction.</p>
        <p>
          The algorithm runs in 5 separate steps [
          <xref ref-type="bibr" rid="ref10">10</xref>
          ].
1. Smoothing: blurring of the image to remove noise.
2. Finding gradients: the edges should be marked where the gradients of the
image have large magnitudes.
3. Non-maximum suppression: only local maxima should be marked as edges.
4. Using the double thresholds: potential edges are determined by using the
thresholds.
5. Edge tracking by hysteresis: the final edges are determined by suppressing
all edges that are not connected to a strongly determined edge.
        </p>
        <p>Morphological Image Processing. The morphological image processing
is a collection of non-linear operations related to the shape or morphology the
image features. Erosion of images is generally used for getting rid of the image
of random insertions. The idea is that the inclusions are eliminated by blurring,
while large and, thus, more visually important regions remain.</p>
        <p>a)
b)
c)</p>
        <p>Erosion (morphological narrowing) is a convolution of the image or its area
selected with some kernel. The kernel may be of arbitrary shape and size. Here,
in calculating the convolution, only one leading position is selected in core, which
is aligned with the current pixel. In many cases, the core is selected as a square
or circle with a leading position at the center (Fig. 2b). The core can be regarded
as a pattern or a mask.</p>
        <p>Applications of dilation is reduced to the passage pattern throughout the
image and use some operator to search for a local minimum intensities of the
pixels in the image, which covers the template. The gray color filled pixels appear
black due to erosion (Fig. 2c).
3.3</p>
      </sec>
      <sec id="sec-2-2">
        <title>Benchmark results</title>
        <p>Weighted linear filtering. As seen from graphs in Fig. 3, the images with size
50 × 50 are processed for the same time by both the CPU and GPU, excluding
NVIDIA GTX260, which works a little better. The larger images are processed
faster by the GPU.</p>
        <p>Reverse gradient filter.As seen from graphs in Fig. 4, application of the
reverse gradient filter gives comparable results w.r.t. the weighted linear filter.</p>
        <p>Canny filter. It is obvious from Fig. 5 that the CPU runs faster on images
up to 150 × 150 quality 25, but the GPU NVIDIA GT630M takes advantage
in times on larger images. The GPU NVIDIA GTX260 works better when the
CPU starts from images 300 × 300 regardless of image quality.</p>
        <p>Morphological Image Processing. Analysis of graphs in Fig. 6 shows
that in using the morphological processing similar to Canny’s filter, the GPU
NVIDIA GT630M starts process faster than CPU from images size 50 × 50; and
the GPU NVIDIA GTX260 is faster from size 300 × 300.
Results of this research show a rise in the efficiency of the GPU computing while
image size grows. Nowadays, the images with resolution less than 1024 × 768 can
be found rarely. From resolutions 300 × 300, the GPU starts to process images
faster than the CPU; so, it is advisable to use image processing algorithms
applying the GPU computing. The CPU computing is suitable in small image
processing or hardware systems without the GPU.</p>
      </sec>
    </sec>
  </body>
  <back>
    <ref-list>
      <ref id="ref1">
        <mixed-citation>
          1.
          <string-name>
            <surname>Moore's Law</surname>
          </string-name>
          , http://www.mooreslaw.org/ csl783/canny.pdf (
          <year>2009</year>
          )
        </mixed-citation>
      </ref>
      <ref id="ref2">
        <mixed-citation>
          2.
          <string-name>
            <surname>GPGPU</surname>
          </string-name>
          .
          <article-title>General-Purpose Computation on Graphics Hardware</article-title>
          , http://gpgpu. org.
        </mixed-citation>
      </ref>
      <ref id="ref3">
        <mixed-citation>
          3.
          <string-name>
            <surname>Halfhill</surname>
            ,
            <given-names>T. R.</given-names>
          </string-name>
          :
          <article-title>Parallel processing with CUDA</article-title>
          .
          <source>Micriprocessor report</source>
          , http://www. nvidia.com/docs/IO/55972/220401-Reprint.pdf (
          <year>2008</year>
          )
        </mixed-citation>
      </ref>
      <ref id="ref4">
        <mixed-citation>4. NVIDIA. CUDA in Action, http://www.nvidia.com/object/cuda-home-new.html</mixed-citation>
      </ref>
      <ref id="ref5">
        <mixed-citation>
          5.
          <string-name>
            <surname>NVIDIA</surname>
            <given-names>CUDA</given-names>
          </string-name>
          :
          <article-title>Compute Unified Device Architecture</article-title>
          ,
          <source>NVIDIA Corp</source>
          .
          <article-title>(</article-title>
          <year>2007</year>
          ).
        </mixed-citation>
      </ref>
      <ref id="ref6">
        <mixed-citation>6. The Lenna Story, http://www.cs.cmu.edu/~chuck/lennapg/lenna.shtml</mixed-citation>
      </ref>
      <ref id="ref7">
        <mixed-citation>
          7.
          <string-name>
            <surname>Dorosinsky</surname>
            ,
            <given-names>L.G.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Kruglov</surname>
            ,
            <given-names>V.N.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Papulovskaya</surname>
            ,
            <given-names>N.V.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Chiryshev</surname>
            ,
            <given-names>A.V.</given-names>
          </string-name>
          :
          <article-title>CUDA technology in digital image processing</article-title>
          , Ekateringurg,
          <volume>192</volume>
          p.,(
          <year>2011</year>
          )
        </mixed-citation>
      </ref>
      <ref id="ref8">
        <mixed-citation>
          8.
          <string-name>
            <surname>Jain</surname>
            ,
            <given-names>R.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Kasturi</surname>
            ,
            <given-names>R.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Schunck</surname>
            ,
            <given-names>B.G.</given-names>
          </string-name>
          :
          <article-title>Machine vision</article-title>
          , http://www.cse.usf.edu/ ~r1k/MachineVisionBook/MachineVision.files/MachineVision-Chapter4.pdf,
          <volume>118</volume>
          -
          <fpage>122</fpage>
        </mixed-citation>
      </ref>
      <ref id="ref9">
        <mixed-citation>
          9.
          <string-name>
            <surname>Pirotti</surname>
            ,
            <given-names>F.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Vettore</surname>
            ,
            <given-names>A.</given-names>
          </string-name>
          :
          <article-title>Canny filter applications and implementation with grass</article-title>
          , http://www.academia.edu/313972/
        </mixed-citation>
      </ref>
      <ref id="ref10">
        <mixed-citation>10. Canny Edge Detection, http://www.cse.iitd.ernet.in/~pkalra/</mixed-citation>
      </ref>
    </ref-list>
  </back>
</article>