<!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>Processing Large Amounts of Images on Hadoop with OpenCV</article-title>
      </title-group>
      <contrib-group>
        <contrib contrib-type="author">
          <string-name>Timofei Epanchintsev</string-name>
          <xref ref-type="aff" rid="aff0">0</xref>
          <xref ref-type="aff" rid="aff1">1</xref>
        </contrib>
        <contrib contrib-type="author">
          <string-name>Andrey Sozykin</string-name>
          <xref ref-type="aff" rid="aff0">0</xref>
          <xref ref-type="aff" rid="aff1">1</xref>
        </contrib>
        <contrib contrib-type="author">
          <string-name>Hadoop</string-name>
        </contrib>
        <aff id="aff0">
          <label>0</label>
          <institution>IMM UB RAS</institution>
          ,
          <addr-line>Yekaterinburg</addr-line>
          ,
          <country country="RU">Russia</country>
        </aff>
        <aff id="aff1">
          <label>1</label>
          <institution>Ural Federal University</institution>
          ,
          <addr-line>Yekaterinburg</addr-line>
          ,
          <country country="RU">Russia</country>
        </aff>
      </contrib-group>
      <fpage>137</fpage>
      <lpage>143</lpage>
      <abstract>
        <p>Modern image collections cannot be processed e ciently on one computer due to large collection sizes and high computational costs of modern image processing algorithms. Hence, image processing often requires distributed computing. However, distributed computing is a complicated subject that demands deep technical knowledge and often cannot be used by researches who develop image processing algorithms. The framework is needed that allows the researches to concentrate on image processing tasks and hides from them the complicated details of distributed computing. In addition, the framework should provide the researches with the familiar image processing tools. The paper describes the extension to the MapReduce Image Processing (MIPr) framework that provides the ability to use OpenCV in Hadoop cluster for distributed image processing. The modi ed MIPr framework allows the development of image processing programs in Java using the OpenCV Java binding. The performance testing of created system on the cloud cluster demonstrated near-linear scalability.</p>
      </abstract>
      <kwd-group>
        <kwd>OpenCV tributed processing</kwd>
      </kwd-group>
    </article-meta>
  </front>
  <body>
    <sec id="sec-1">
      <title>-</title>
      <p>Image processing is one of the important tasks in many areas of research such as
medical imaging, remote sensing, astronomy, Internet analysis, etc. The industry
also widely uses image processing.</p>
      <p>
        Nowadays, image processing often requires distributed computing. The sizes
of modern image collections, for example, the Yahoo 100 million creative
commons ickr images for research [
        <xref ref-type="bibr" rid="ref6">6</xref>
        ], are large (terabytes and petabytes of data);
such collections cannot be stored and processed e ciently on a single computer.
In addition, contemporary image processing algorithms are becoming very
complex and, hence, computationally intensive.
      </p>
      <p>However, distributed computing is a complicated subject that requires deep
technical knowledge. Many scientists, who developed image processing
algorithms, does not have the quali cation required to use distributed computing
e ciently. They need an image processing framework that hides the complicated
details of distributed computing from the application developers and allows them
to concentrate on image processing tasks and algorithms.</p>
      <p>
        Previously, we have developed the MapReduce Image Processing framework
(MIPr) [
        <xref ref-type="bibr" rid="ref4">4</xref>
        ], which allows to process images on Apache Hadoop cluster using
the MapReduce technology. MIPr provides the image representations in the
Hadoop internal format, which are suitable for MapReduce processing, and the
input/output tools for image processing integration into the Hadoop data
workow. In addition, MIPr includes high-level image processing API for application
developers who are not familiar with Hadoop.
      </p>
      <p>However, providing the application developers with a convenient framework
is not enough for e cient distributed image processing. The developers must
be able to use image processing tools that they already know together with
the framework. In such case, the developers can quickly create software for
distributed computing framework, or even use their existing software. Otherwise,
the developers will have to implement image processing algorithms from scratch,
which require a lot of time and labor.</p>
      <p>
        In this paper we describe an approach for using the popular open source
computer vision library OpenCV [
        <xref ref-type="bibr" rid="ref1">1</xref>
        ] for distributed image processing on a Hadoop
cluster with the help of the MIPr framework. OpenCV includes more than 2500
computer vision and machine learning algorithms for image and video processing.
2
      </p>
    </sec>
    <sec id="sec-2">
      <title>Related Work</title>
      <p>
        Several systems can be used for image processing in Hadoop. HIPI (Hadoop
Image Processing Interface) [
        <xref ref-type="bibr" rid="ref5">5</xref>
        ] is a framework speci cally designed to enable
image processing in Hadoop. OpenIMAJ (Open Intelligent Multimedia Analysis
for Java) [
        <xref ref-type="bibr" rid="ref2">2</xref>
        ] contains several Hadoop implementation of computer vision
algorithms. In contrast to our work neither system supports the OpenCV library.
      </p>
      <p>
        The image processing cloud with the OpenCV support was built at the Prairie
View A&amp;M University (PVAMU)[
        <xref ref-type="bibr" rid="ref7">7</xref>
        ]. The PVAMU cloud provides the Platform
as a Service for distributed image processing and storage, which includes the
Hadoop cluster and the OpenCV library. Two types of Hadoop InputFormat and
OutputFormat based on OpenCV have been developed: for image and video les.
Hadoop Streaming is used for data processing. Hence, it is possible to use various
programming languages to develop image processing algorithms. Unfortunately,
the authors did not share their implementation of OpenCV support for Hadoop.
Hence, the system can be used only in the PVAMU cloud, which is not very
convenient. Sometimes, copying a large image collection to the remote cloud
through the network requires more time than the processing of the images. Our
MIPr framework is open sourced and freely available to use in any Hadoop
cluster, not only at the cloud platform. On the other hand, the PVAMU cloud has
two advantages compared with the MIPr: the ability to process not only images,
but also videos, and the support of multiple languages for implementation of
image and video processing algorithms.
Image processing libraries
      </p>
      <p>Libraries
Java API</p>
      <p>C++ API</p>
      <p>Python API
Map-Reduce Drivers OpenCV Map-Reduce</p>
      <p>Driver</p>
      <p>Image
processing</p>
      <p>API</p>
      <p>I/O
OpenCV I/O tools:
- Input Format
- Combine File Input Format
- Record Reader
- Output Format
- Record Writer</p>
      <p>Serialization</p>
      <p>Mat writable</p>
      <p>Core
components
3 Integration of OpenCV Library into the MIPr</p>
      <p>Framework
The MIPr framework has an open architecture, which allows adding new image
representation based on various libraries. The extended architecture of MIPr
with the support of OpenCV library is presented in Fig 1. The extensions
include an OpenCV-based image representation in the Hadoop internal format,
input/output tools for inclusion of OpenCV-based images into the Hadoop data
work ow, and MapReduce Driver to execute Hadoop programs with the OpenCV
support.</p>
      <sec id="sec-2-1">
        <title>3.1 Image Representation</title>
        <p>OpenCV uses the Mat class as an image container, and most of OpenCV image
processing functions accept Mat as an argument. Hence, the Mat class was chosen
to build the OpenCV-based image format in MIPr. Similar to other MIPr image
representation formats, the Hadoop Writable interface was used for serialization.
By combining these two components, the MatWritable image format was created,
which is suitable for use as a value in MapReduce programs.</p>
      </sec>
      <sec id="sec-2-2">
        <title>3.2 Input/Output tools</title>
        <p>For reading images from the Hadoop Distributed File System (HDFS) into
the memory for processing, two types of InputFormat for OpenCV have
been developed: OpenCVFileInputFormat and
OpenCVCombineFileInputFormat. OpenCVFileInputFormat reads one image at a time and is suitable for
big images (larger than the HDFS block size). In contrast with it,
OpenCVCombineFileInputFormat reads several images from the same HDFS block in one
operation and is suitable for processing large amount of small les. Both
InputFormats produce pairs &lt; le name, MatWritable&gt;
(OpenCVCombineFileInputFormat can produce several pairs if the HDSF block contains several images).
To actually read an image from HDFS and present it in the MatWritable format,
the OpenCVRecordReader was developed, which is used both by the
OpenCVFileInputFormat and OpenCVCombineFileInputFormat.</p>
        <p>For writing the OpenCV-based images to HDFS after processing, special
implementations of OutputFormat and RecordWriter, which are capable of
working with MatWritable, were developed. In contrast to the traditional Hadoop
approach, the created components preserve the original names of image les.
3.3</p>
      </sec>
      <sec id="sec-2-3">
        <title>MapReduce Driver</title>
        <p>MapReduce driver is intended to execute the MapReduce program on the cluster.
The developed OpenCV MapReduce driver sets up the appropriate InputFormat
and OutputFormat, de nes the MapReduce values type as a MatWritable, loads
OpenCV native C++ library, and executes the job on the Hadoop cluster. To
distribute the binary OpenCV C++ library to the cluster nodes, the Hadoop
distributed cache is used.</p>
      </sec>
      <sec id="sec-2-4">
        <title>3.4 Image Processing</title>
        <p>The MIPr extensions use the OpenCV Java binding. In contrast to the PVAMU
cloud, MIPr utilizes the standard Hadoop Mappers and Reducers for image
processing. Hence, only Java is supported for developing image processing
algorithms in MIPr using OpenCV.
4</p>
      </sec>
    </sec>
    <sec id="sec-3">
      <title>Performance evaluation</title>
      <p>In order to estimate the performance and scalability of the proposed approach,
two computational experiments with the modi ed MIPr implementation have
been conducted. The Microsoft Azure HDInsight cluster in the Microsoft Azure
cloud platform have been used for the experiments. The cluster consists of 18
nodes: 2 head nodes and 16 computational nodes. The con guration of the nodes
is presented in the Table 1.</p>
      <p>
        The MIRFLICKR-1M image collection (one million of images downloaded
from Flickr, 118GB total size) [
        <xref ref-type="bibr" rid="ref3">3</xref>
        ] was used as a benchmark dataset. The following
image processing operations were performed during the experiments:
{ conversion of color images to grayscale;
{ face detection;
{ Canny edge detection.
The purpose of the rst experiment was to estimate the scalability of the
modi ed MIPr implementation with the growing number of nodes in the cluster.
During this experiment, the entire MIRFLICKR-1M image collection was
processed using varying number of nodes. In addition to the cluster implementation,
the performance of sequential image processing was measured. The results are
presented in Fig. 2. With the exception of single node cluster, the system has
near-linear scalability. A poor performance of the single node cluster, as
compared with the sequential implementation, is caused by the Hadoop overhead.
      </p>
      <p>The second experiment was aimed at estimating how the system scales with
the increasing volume of images. For this purpose, the whole cluster was used
to process varying number of images. The results are presented in Fig. 3
(logarithmic scale). For small datasets ( the number of images is less than 10000),
there is no di erence in processing time due to the cluster overhead. However,
the scalability for large image collection processing is near-linear.</p>
      <p>Near-linear scalability of the modi ed MIPr implementation is an expected
result, because images are processed independently.
Processing time,</p>
      <p>sec
10000
1000
100
10
1</p>
      <p>Img2Gray</p>
      <p>FaceDetection</p>
      <p>CannyEdgeDetection
1000
10000
100000</p>
      <p>1000000</p>
      <p>Number of images in the collecton
The approach to use OpenCV library for distributed image processing on a
Hadoop cluster was presented. The approach is based on the previously
developed MIPr framework for image processing in Hadoop. The MIPr framework was
extended to include OpenCV-based image representation in the Hadoop internal
format, tools for reading images from HDFS and writing processed images back
to HDFS, and drivers for MapReduce jobs with OpenCV support. The
extension allows to develop image processing programs in Java using OpenCV Java
bindings.</p>
      <p>The performance of the modi ed MIPr implementation was evaluated. For
large clusters and image datasets the scalability is near-linear. Poor performance
of single node cluster and small dataset processing is caused by Hadoop overhead.</p>
      <p>MIPr framework is open sourced and available for free at https://github.
com/sozykin/mipr.</p>
      <p>
        Future work include porting MIPr to Apache Spark [
        <xref ref-type="bibr" rid="ref8">8</xref>
        ] for in-memory image
processing and providing the ability to use Python and C++ for developing
MapReduce image processing programs.
      </p>
      <p>Acknowledgements. The reported study was supported by RFBR (research
project No 14-07-31324 mol a) and by Microsoft Azure for Research Russia
Initiative. Our work was performed using the \Uran" supercomputer from Institute
of Mathematics and Mechanics UrB RAS.</p>
    </sec>
  </body>
  <back>
    <ref-list>
      <ref id="ref1">
        <mixed-citation>
          1.
          <string-name>
            <surname>Bradski</surname>
            ,
            <given-names>G.</given-names>
          </string-name>
          :
          <article-title>The opencv library</article-title>
          .
          <source>Dr. Dobb's Journal of Software Tools</source>
          (
          <year>2000</year>
          )
        </mixed-citation>
      </ref>
      <ref id="ref2">
        <mixed-citation>
          2.
          <string-name>
            <surname>Hare</surname>
            ,
            <given-names>J.S.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Samangooei</surname>
            ,
            <given-names>S.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Dupplaw</surname>
            ,
            <given-names>D.P.</given-names>
          </string-name>
          :
          <article-title>Openimaj and imageterrier: Java libraries and tools for scalable multimedia analysis and indexing of images</article-title>
          .
          <source>In: Proceedings of the 19th ACM international conference on Multimedia</source>
          . pp.
          <volume>691</volume>
          {
          <fpage>694</fpage>
          . MM '11,
          <string-name>
            <surname>ACM</surname>
          </string-name>
          , New York, NY, USA (
          <year>2011</year>
          ), http://doi.acm.
          <source>org/10</source>
          .1145/2072298. 2072421
        </mixed-citation>
      </ref>
      <ref id="ref3">
        <mixed-citation>
          3.
          <string-name>
            <surname>Huiskes</surname>
            ,
            <given-names>M.J.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Thomee</surname>
            ,
            <given-names>B.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Lew</surname>
            ,
            <given-names>M.S.</given-names>
          </string-name>
          :
          <article-title>New trends and ideas in visual concept detection: The mir ickr retrieval evaluation initiative</article-title>
          .
          <source>In: Proceedings of the International Conference on Multimedia Information Retrieval</source>
          . pp.
          <volume>527</volume>
          {
          <fpage>536</fpage>
          . MIR '10,
          <string-name>
            <surname>ACM</surname>
          </string-name>
          , New York, NY, USA (
          <year>2010</year>
          ), http://doi.acm.
          <source>org/10</source>
          .1145/1743384. 1743475
        </mixed-citation>
      </ref>
      <ref id="ref4">
        <mixed-citation>
          4.
          <string-name>
            <surname>Sozykin</surname>
            ,
            <given-names>A.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Epanchintsev</surname>
            ,
            <given-names>T.</given-names>
          </string-name>
          :
          <article-title>Mipr { a framework for distributed image processing using hadoop</article-title>
          .
          <source>In: Application of Information and Communication Technologies (AICT)</source>
          ,
          <year>2015</year>
          IEEE 9th International Conference on. pp.
          <volume>35</volume>
          {
          <issue>39</issue>
          (
          <year>2015</year>
          )
        </mixed-citation>
      </ref>
      <ref id="ref5">
        <mixed-citation>
          5.
          <string-name>
            <surname>Sweeney</surname>
            ,
            <given-names>C.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Liu</surname>
            ,
            <given-names>L.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Arietta</surname>
            ,
            <given-names>S.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Lawrence</surname>
            ,
            <given-names>J.:</given-names>
          </string-name>
          <article-title>HIPI: A Hadoop Image Processing Interface for Image-based MapReduce Tasks</article-title>
          . B.s. thesis, University of Virginia (
          <year>2011</year>
          )
        </mixed-citation>
      </ref>
      <ref id="ref6">
        <mixed-citation>
          6.
          <string-name>
            <surname>Thomee</surname>
            ,
            <given-names>B.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Shamma</surname>
            ,
            <given-names>D.A.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Friedland</surname>
            ,
            <given-names>G.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Elizalde</surname>
            ,
            <given-names>B.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Ni</surname>
            ,
            <given-names>K.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Poland</surname>
            ,
            <given-names>D.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Borth</surname>
            ,
            <given-names>D.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Li</surname>
            ,
            <given-names>L.J.:</given-names>
          </string-name>
          <article-title>The new data and new challenges in multimedia research</article-title>
          .
          <source>arXiv preprint arXiv:1503</source>
          .
          <year>01817</year>
          (
          <year>2015</year>
          )
        </mixed-citation>
      </ref>
      <ref id="ref7">
        <mixed-citation>
          7.
          <string-name>
            <surname>Yan</surname>
            ,
            <given-names>Y.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Huang</surname>
            ,
            <given-names>L.</given-names>
          </string-name>
          :
          <article-title>Large-scale image processing research cloud</article-title>
          .
          <source>In: CLOUD COMPUTING</source>
          <year>2014</year>
          : The Fifth International Conference on Cloud Computing, GRIDs, and Virtualization. pp.
          <volume>88</volume>
          {
          <issue>93</issue>
          (
          <year>2014</year>
          )
        </mixed-citation>
      </ref>
      <ref id="ref8">
        <mixed-citation>
          8.
          <string-name>
            <surname>Zaharia</surname>
            ,
            <given-names>M.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Chowdhury</surname>
            ,
            <given-names>M.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Franklin</surname>
            ,
            <given-names>M.J.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Shenker</surname>
            ,
            <given-names>S.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Stoica</surname>
            ,
            <given-names>I.</given-names>
          </string-name>
          :
          <article-title>Spark: Cluster computing with working sets</article-title>
          .
          <source>In: Proceedings of the 2Nd USENIX Conference on Hot Topics in Cloud Computing</source>
          . pp.
          <volume>10</volume>
          {
          <fpage>10</fpage>
          . HotCloud'10,
          <string-name>
            <given-names>USENIX</given-names>
            <surname>Association</surname>
          </string-name>
          , Berkeley, CA, USA (
          <year>2010</year>
          ), http://dl.acm.org/citation.cfm?id=
          <volume>1863103</volume>
          .
          <fpage>1863113</fpage>
        </mixed-citation>
      </ref>
    </ref-list>
  </back>
</article>