<!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>algorith m for hu m an position co m parison to te m plate and its perform ance and precision research</article-title>
      </title-group>
      <contrib-group>
        <contrib contrib-type="author">
          <string-name>Karolis Ryselis</string-name>
          <email>Karolis.Ryselis@ktu.edu</email>
          <xref ref-type="aff" rid="aff0">0</xref>
          <xref ref-type="aff" rid="aff1">1</xref>
        </contrib>
        <contrib contrib-type="author">
          <string-name>Tautvydas Petkus</string-name>
          <email>Tautvydas.Petkus@ktu.edu</email>
          <xref ref-type="aff" rid="aff0">0</xref>
          <xref ref-type="aff" rid="aff1">1</xref>
        </contrib>
        <contrib contrib-type="author">
          <string-name>Kaunas</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>Lithuania</string-name>
          <xref ref-type="aff" rid="aff0">0</xref>
          <xref ref-type="aff" rid="aff1">1</xref>
        </contrib>
        <aff id="aff0">
          <label>0</label>
          <institution>Department of Software Engineering</institution>
        </aff>
        <aff id="aff1">
          <label>1</label>
          <institution>Kaunas University of Technology</institution>
        </aff>
      </contrib-group>
      <fpage>33</fpage>
      <lpage>36</lpage>
      <abstract>
        <p>-This article presents efficient algorithm to calculate Hausdorff distance metric and heuristic algorithm</p>
      </abstract>
      <kwd-group>
        <kwd>Kinect</kwd>
        <kwd>Hausdorff distance</kwd>
        <kwd>pattern matching</kwd>
      </kwd-group>
    </article-meta>
  </front>
  <body>
    <sec id="sec-1">
      <title>-</title>
      <p>that
maximizes amount of intersecting points in two point sets very
quickly. Performance and precision research of those algorithms
is presented. It is shown that algorithm is applicable for real time
position tracking using “Kinect” device.</p>
      <p>
        INTRODUCTION
“Kinect” sensor is a motion tracking device presented by
“Microsoft”. It is one of the most popular motion tracking
devices used at home. “Kinect’s” application programmable
interface presents external applications with current human
position [
        <xref ref-type="bibr" rid="ref1">1</xref>
        ]: skeleton stream that consists of processed human
joint position information; depth stream, which is a
twodimensional matrix with data about every pixel’s distance
from the sensor to the closest object in its direction; body index
matrix which assigns every pixel to a tracked player’s body.
Skeleton stream is processed by “Kinect” and presents external
application
      </p>
      <p>with information about human body parts.</p>
      <p>
        Therefore, it is applicable when information about separate
body parts is needed. However, it is shown by some researches
[
        <xref ref-type="bibr" rid="ref2">2</xref>
        ] that skeleton stream is only accurate when the user is
visible by “Kinect” comfortably and the user is standing.
Skeleton is warped under different conditions.
      </p>
      <p>Specialized algorithms are needed to process data from
other data streams and compare them to a template. All data
streams present the user with large amount of data compared
to preprocessed skeleton stream. Thus, they require efficient
algorithms to process them if real time or near real time
tracking is required.</p>
      <p>
        The easiest and simplest to process data stream is body
index stream. If only one human is tracked this stream is easily
deduced to a binary matrix where 1 represents a pixel that
belongs to human body, 0 – that is does not. Hausdorff distance
metric is a good metric for this kind of data [
        <xref ref-type="bibr" rid="ref3">3</xref>
        ]. Say that  =
      </p>
      <p>= { 1,  2, … ,   } are finite sets of
points. Then Hausdorff distance is defined as follows:
 ( ,  ) = max⁡(ℎ( ,  ), ℎ( ,  )), kur
ℎ( ,  ) = max min‖ −  ‖
 ∈
 ∈
(1)
(2)</p>
    </sec>
    <sec id="sec-2">
      <title>Copyright © 2017 held by the authors</title>
      <p>Here ‖ −  ‖ could be any distance metric between points
 and  , e, g., Euclidean norm or  2 norm. Semantically this
metric shows the distance to the most distance point from the
other set corresponding to a chosen distance metric.</p>
      <p>Looking at (2) formula it is trivial to see that direct
calculation of the metric has computational complexity of

 (</p>
      <p>) because all points of both sets must be compared. If
≈  , complexity approaches to  ( 2) and is not applicable
for real time use.</p>
      <p>II.</p>
      <p>HAUSDORFF DISTANCE CALCULATION METHODS</p>
      <sec id="sec-2-1">
        <title>Yanir Taflev’s method</title>
        <p>Yanir Taflev presents an open source solution to compute</p>
      </sec>
    </sec>
    <sec id="sec-3">
      <title>Hausdorff distance</title>
      <p>
        metric [
        <xref ref-type="bibr" rid="ref4">4</xref>
        ]. This algorithm does not
calculate the distance itself, it produces Hausdorff distance
matrices instead. Each point of such matrix shows the distance
to the closest point from set 
for each point of set  .
      </p>
      <p>Hausdorff distance is then equal to the maximum value of both
distance matrices.</p>
      <p>Hausdorff distance matrix is calculated by constructing
initial matrix first. A value of 0 is assigned to every point of
set  and</p>
      <p>∞ for all other points. For all points of set  the
matrix is traversed in squares of increasing size and a value of
square edge length is assigned if the value of that point is not
less that the length of square edge. Chebyshev distance is
computed because of such matrix construction.</p>
      <p>
        Algorithm is implemented in C# language and is used in
C# framework “Shape Matching Framework”.
“ElasticSearch” client created by “Vivid Solutions” is an
open source Java project [
        <xref ref-type="bibr" rid="ref5">5</xref>
        ]. It used discrete Hausdorff
distance
implementation.
      </p>
      <p>The
computed
distance
is
approximate. The algorithm is not given by “Vivid Solutions”.
The implementation is used to compare geometries in “Elastic</p>
    </sec>
    <sec id="sec-4">
      <title>Search” engine internally.</title>
      <sec id="sec-4-1">
        <title>C. Princeton University’s method</title>
        <p>
          Princeton University’s resolving library “RgResolve” uses
Hausdorff algorithm’s Java implementation [
          <xref ref-type="bibr" rid="ref6">6</xref>
          ]. Algorithm
relies on assumption that all points are sorted either clockwise
or counterclockwise. Points are then analyzed in this order.
Data is analyzed as a list of points instead of two-dimensional
matrix, which is different from Yanir Taflev’s implementation.
        </p>
        <p>The distance is calculated using Euclidean norm.
result of the algorithm must not depend on where the human is
standing. A transformation of human’s silhouette is needed
before computing Hausdorff distance. It must move the
silhouette to the position where it would intersect with the
template the most.
distance calculation algorithm:</p>
        <p>These requirements must be met by efficient Hausdorff</p>
        <p>Execution time is close to 30 ms with “Kinect’s” body
index stream data
Algorithm must find an optimal linear transformation
that makes the template and user’s silhouette be
oriented in such a way that the amount of intersecting
points is maximum and the Hausdorff distance is
minimum</p>
        <p>Say that we have two finite sets of points  =</p>
        <p>= { 1,  2, . . ,   }. Let us assume that the
human will be oriented vertically in the frame, i.e., the normal
vector of the base that the user is standing on is vertical. This
assumption eliminates the need of rotation transformation.
Two linear transformations need to be made: scale and shift.
Say that the center point of set  is   . The shape will be
scaled using this point as the center. Say that optimal scale
coefficient is  , optimal shift transformation vector - ⃗. Then
the transformed point set is
  = {  1,   2, … ,   } =  

( 2−  +⃗) , … ,  
+ (  −  +⃗)</p>
        <p />
      </sec>
    </sec>
    <sec id="sec-5">
      <title>After the transformation</title>
      <p>cardinality function
 ( ,   ) = | ∩   |
  =   + (  −  +  −  )</p>
      <p />
      <p>If silhouettes of template and human belong to the same
sequence
of
movement,
we
can
assume
that these
transformation parameters will stay constant during the
process of matching. Thus, they can be calculated in the
beginning and used later. This should speed up the tracking
even more. Then
 =   1 −   1
 =
ℎ2
ℎ1
  =   + (  −  + )

(8)
(9)
(10)
(11)</p>
      <p>Proposed Hausdorff distance calculation algorithm
Proposed algorithm is based on Yanir Taflev’s ideas, but is
better optimized for speed. The use of this algorithm
eliminates the need to convert data from two-dimensional
matrix to other formats, e.g., a list of points. Chebyshev
distance is used as distance metric. Firstly, a two-dimensional
matrix is set up. All points with coordinates that belong to the
silhouette are set to 0, others – with ∞. A point queue is
constructed. Initially it consists of all points that belong to the
silhouette. A point is taken from the queue and 8 surrounding
equidistant points are analyzed. The distance from the original
points to those surrounding points is always 1, so the distance
from the other silhouette to those points cannot be larger than
the original point’s distance increased by one. If this value is
less than already computed value for this point, this value is
updated and the point is added to the queue. Distance is
calculated for all points this way. All points that do not belong
to the other set are then removed because they do not
contribute to Hausdorff distance. Elements of this matrix show
the differences between the silhouettes. Two such matrices
must be calculated, so the computation of them can be made
parallel – their computation is independent.</p>
      <p>To reduce the amount of calculation matrix edges without
silhouette points are cut. The resulting cut matrix is minimum
rectangle matrix that contains all the points that belong to
silhouette.</p>
      <p>Common maximum of both matrices is Hausdorff distance.
Algorithm pseudocode is given below.</p>
      <p>
        matrices ← template matrix and user matrix
find common left upper corner of matrices
find common right lower corner of matrices
∀ matrix ∈ matrixes
do initialize queue and ret
while queue ≠ ø
do p ← take from queue
val ← get p value from ret
val ← val + 1
ret ← min(r, val) ∀⁡adjacent point
r to p
opposing matrix to 0
max(res2))
set
points
of
res
that
do
not
belong
to
hausdorff distance = max(max(res[
        <xref ref-type="bibr" rid="ref1">1</xref>
        ]),
      </p>
      <p>Precise calculation of such function is computationally
intensive, so heuristic algorithm is used instead.</p>
      <p>A fast and quite accurate heuristic for scale transformation
is to compute scale coefficient as the ratio of heights of the two
shapes. If template and user are in similar positions, e.g., both
are standing, both silhouettes could be made the same height.
Then
 = ℎ , where
ℎ</p>
      <p>METHOD OF RESEARCH</p>
      <p>Two properties of the algorithm are evaluated:
performance and precision.</p>
      <p>To evaluate performance different types of frames are set
up. The frames differ in size and distance between silhouettes.
Used frame sizes are 10% to 300% “Kinect’s” frame size in
steps of 10%. For each frame size, real human silhouette is
analyzed. Performance is measured when the human and the
template are in similar parts and in opposite parts of the frames.
Performance is compared to other existing algorithms’
performance. Each measure is run 10 times and execution time
average is found. Three modifications of the proposed
algorithm are measured – Hausdorff distance only, Hausdorff
distance with transformation and Hausdorff distance with
cached transformation parameters. Algorithm should work in
less than 30 ms, i.e., faster than “Kinect’ produces frames.</p>
      <p>To evaluate precision different real human silhouettes are
used. Best possible transformation is found using brute force
algorithm, Hausdorff distance is calculated using the optimal
transformation, then Hausdorff distance is found using the
transformation calculated using proposed algorithm and the
error is evaluated.</p>
      <p>V.</p>
      <p>RESEARCH RESULTS</p>
      <p>Execution times of all algorithms and all frame sizes are
shown in figure 1. Same silhouettes were used, but scaled.
Silhouettes were around a third of the frame apart.</p>
      <p>Unit value in diagrams represents algorithm with cached
transformation performance when frame size is equal to
“Kinect’s” frame size. This time is 26 ms for distant silhouettes
and 21 ms for close silhouettes on “Intel i7-3770K” processor
(3.5 GHz). Maximum acceptable value on those scales are 1.15
for distant silhouettes and 1.43 for close silhouettes. These
values are hardware-dependent and presented for approximate
evaluation. The processor used is a little more powerful than
“Kinect’s” system requirements (i7 series processor, 3.1 GHz
clock frequency).</p>
      <p>Algorithm performance
comparison, distant silhouettes
14</p>
      <p>The diagram reveals that “Elastic Search” algorithm is the
slowest, “RgResolve” – better, Y. Taflev’s algorithm would be
applicable up to frame size of 0.6 “Kinect 2” frame size. This
is close to “Kinect 1” frame size. Performance of proposed
algorithm varies and no clear dependency is visible, but
execution times slowly increase with increasing frame size. It
could be caused by parallel nature of the algorithm. Threads
are spawned by the runtime and operating system and
determination of their performance could be difficult to
predict. Nevertheless, frame sizes of around 1.3 “Kinect’s”
frame size and smaller are processed faster than in 1.15 relative
units and 1.7 and less – in 2 relative units.</p>
      <p>Figure 2 shows the result of similar measurements, but the
distance between the silhouettes was minimized. Other
algorithms had little to no impact because of this change, but
proposed algorithm performed better under those conditions.
1.5 relative units is reached at around 1.4-1.5 “Kinect’s” frame
size, 2.5 – at around 1.8-2 times larger frames than “Kinect’s”.
At round 3 “Kinect’s” frame sizes performance increase is
around 1.5 times compared to distant silhouette test.</p>
      <p>Algorithm performance
comparison, close silhouettes
0,1 0,3 0,5 0,7 0,9 1,1 1,3 1,5 1,7 1,9 2,1 2,3 2,5 2,7 2,9</p>
      <p>Frame edge size in Kinect's frames
Yanir Taflev
Proposed algorithm
Proposed algorithm with calculated transformation
Proposed algorithm with cached transformation
RgResolve</p>
      <p>ElasticSearch
Algorithm precision was tested using different human
silhouettes. Average error was 3.8%, minimum error – 0%
(exact result), maximum error – 15.5%, median error – 2.7%.
Data set size – 21 silhouettes.</p>
      <p>VI.</p>
      <p>CONCLUSIONS</p>
      <p>The proposed algorithm performs faster than existing open
source alternatives to calculate Hausdorff distance, but high
variation of execution speed is observed because of parallelism
involved in the calculations. Despite that, the algorithm in the
worst case works faster than in 30 ms with “Kinect 2”
recommended hardware, therefore it is applicable for human
motion tracking using “Kinect” sensors. Proposed algorithm is
precise if applied for human motion tracking and proposed
heuristic is worth applying, because it adds little to execution
times and precision loss is low.</p>
      <p>Proposed algorithm works faster with silhouettes in the
same part of frame than distant silhouettes. If this algorithm is
applied for human motion tracking and recommended
transformations are applied, this will always be the case and
comparison will always be fast.</p>
      <p>Algorithm is well suited for human position tracking when
the human does not change his position relative to sensor, only
his pose changes, or the human moves together with the
template silhouette. In this case proposed heuristics work well
and near-precise value of minimum Hausdorff distance with
Chebyshev metric is found in short time.</p>
    </sec>
    <sec id="sec-6">
      <title>REFERENCES</title>
    </sec>
  </body>
  <back>
    <ref-list>
      <ref id="ref1">
        <mixed-citation>
          [1]“Kinect API Overview,” [Online]. Available: https://msdn.microsoft.com/en-us/library/dn782033.aspx.
          <source>[Accessed 10 03</source>
          <year>2017</year>
          ].
        </mixed-citation>
      </ref>
      <ref id="ref2">
        <mixed-citation>
          [2]
          <string-name>
            <given-names>K.</given-names>
            <surname>Ryselis</surname>
          </string-name>
          , T. Petkus, “
          <article-title>Nestandartinių žmogaus kūno pozicijų atpažinimo tikslumo naudojant „Kinect 2.0“ jutiklius tyrimas</article-title>
          ,” Kaunas,
          <year>2015</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref3">
        <mixed-citation>
          [3]
          <string-name>
            <given-names>D. P.</given-names>
            <surname>Huttenlocher</surname>
          </string-name>
          ,
          <string-name>
            <given-names>G. A.</given-names>
            <surname>Klanderman</surname>
          </string-name>
          ,
          <string-name>
            <given-names>W. J.</given-names>
            <surname>Rucklidge</surname>
          </string-name>
          , “
          <article-title>Comparing Images using the Hausdorff Distance,”</article-title>
          <source>IEEE Transactions on Pattern Analysis and Machine Intelligence</source>
          , no.
          <issue>15</issue>
          , pp.
          <fpage>850</fpage>
          -
          <lpage>863</lpage>
          ,
          <year>1993</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref4">
        <mixed-citation>
          [4]
          <string-name>
            <given-names>Y.</given-names>
            <surname>Taflev</surname>
          </string-name>
          , “
          <article-title>Using the Hausdorff distance algorithm to point out differences between two drawings</article-title>
          ,”
          <volume>27</volume>
          09
          <year>2009</year>
          . [Online]. Available: https://www.codeproject.com/articles/42669/
          <article-title>using-the-hausdorffdistance-algorithm-to-point-ou</article-title>
          .
          <source>[Accessed 10 03</source>
          <year>2017</year>
          ].
        </mixed-citation>
      </ref>
      <ref id="ref5">
        <mixed-citation>
          [5]
          <string-name>
            <given-names>V.</given-names>
            <surname>Solutions</surname>
          </string-name>
          , “elasticsearch-client/DiscreteHausdorffDistance,” [Online]. Available: https://github.com/jprante/elasticsearchclient/blob/master/elasticsearch-client-jtsjdk5/src/main/java/com/vividsolutions/jts/algorithm/distance/Discre teHausdorffDistance.
          <source>java. [Accessed 10 03</source>
          <year>2017</year>
          ].
        </mixed-citation>
      </ref>
      <ref id="ref6">
        <mixed-citation>
          [6] “Hausdorff Distance,” Princeton University, [Online]. Available: http://www.princeton.edu/~rkatzwer/rgsolve/doc/edu/princeton/poly gon/HausdorffDistance.html.
          <source>[Accessed 12 03</source>
          <year>2017</year>
          ].
        </mixed-citation>
      </ref>
    </ref-list>
  </back>
</article>