line_descriptor.hpp 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. /*M///////////////////////////////////////////////////////////////////////////////////////
  2. //
  3. // IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
  4. //
  5. // By downloading, copying, installing or using the software you agree to this license.
  6. // If you do not agree to this license, do not download, install,
  7. // copy or use the software.
  8. //
  9. //
  10. // License Agreement
  11. // For Open Source Computer Vision Library
  12. //
  13. // Copyright (C) 2013, OpenCV Foundation, all rights reserved.
  14. // Third party copyrights are property of their respective owners.
  15. //
  16. // Redistribution and use in source and binary forms, with or without modification,
  17. // are permitted provided that the following conditions are met:
  18. //
  19. // * Redistribution's of source code must retain the above copyright notice,
  20. // this list of conditions and the following disclaimer.
  21. //
  22. // * Redistribution's in binary form must reproduce the above copyright notice,
  23. // this list of conditions and the following disclaimer in the documentation
  24. // and/or other materials provided with the distribution.
  25. //
  26. // * The name of the copyright holders may not be used to endorse or promote products
  27. // derived from this software without specific prior written permission.
  28. //
  29. // This software is provided by the copyright holders and contributors "as is" and
  30. // any express or implied warranties, including, but not limited to, the implied
  31. // warranties of merchantability and fitness for a particular purpose are disclaimed.
  32. // In no event shall the Intel Corporation or contributors be liable for any direct,
  33. // indirect, incidental, special, exemplary, or consequential damages
  34. // (including, but not limited to, procurement of substitute goods or services;
  35. // loss of use, data, or profits; or business interruption) however caused
  36. // and on any theory of liability, whether in contract, strict liability,
  37. // or tort (including negligence or otherwise) arising in any way out of
  38. // the use of this software, even if advised of the possibility of such damage.
  39. //
  40. //M*/
  41. #ifndef __OPENCV_LINE_DESCRIPTOR_HPP__
  42. #define __OPENCV_LINE_DESCRIPTOR_HPP__
  43. #include "opencv2/line_descriptor/descriptor.hpp"
  44. /** @defgroup line_descriptor Binary descriptors for lines extracted from an image
  45. Introduction
  46. ------------
  47. One of the most challenging activities in computer vision is the extraction of useful information
  48. from a given image. Such information, usually comes in the form of points that preserve some kind of
  49. property (for instance, they are scale-invariant) and are actually representative of input image.
  50. The goal of this module is seeking a new kind of representative information inside an image and
  51. providing the functionalities for its extraction and representation. In particular, differently from
  52. previous methods for detection of relevant elements inside an image, lines are extracted in place of
  53. points; a new class is defined ad hoc to summarize a line's properties, for reuse and plotting
  54. purposes.
  55. Computation of binary descriptors
  56. ---------------------------------
  57. To obtatin a binary descriptor representing a certain line detected from a certain octave of an
  58. image, we first compute a non-binary descriptor as described in @cite LBD . Such algorithm works on
  59. lines extracted using EDLine detector, as explained in @cite EDL . Given a line, we consider a
  60. rectangular region centered at it and called *line support region (LSR)*. Such region is divided
  61. into a set of bands \f$\{B_1, B_2, ..., B_m\}\f$, whose length equals the one of line.
  62. If we indicate with \f$\bf{d}_L\f$ the direction of line, the orthogonal and clockwise direction to line
  63. \f$\bf{d}_{\perp}\f$ can be determined; these two directions, are used to construct a reference frame
  64. centered in the middle point of line. The gradients of pixels \f$\bf{g'}\f$ inside LSR can be projected
  65. to the newly determined frame, obtaining their local equivalent
  66. \f$\bf{g'} = (\bf{g}^T \cdot \bf{d}_{\perp}, \bf{g}^T \cdot \bf{d}_L)^T \triangleq (\bf{g'}_{d_{\perp}}, \bf{g'}_{d_L})^T\f$.
  67. Later on, a Gaussian function is applied to all LSR's pixels along \f$\bf{d}_\perp\f$ direction; first,
  68. we assign a global weighting coefficient \f$f_g(i) = (1/\sqrt{2\pi}\sigma_g)e^{-d^2_i/2\sigma^2_g}\f$ to
  69. *i*-th row in LSR, where \f$d_i\f$ is the distance of *i*-th row from the center row in LSR,
  70. \f$\sigma_g = 0.5(m \cdot w - 1)\f$ and \f$w\f$ is the width of bands (the same for every band). Secondly,
  71. considering a band \f$B_j\f$ and its neighbor bands \f$B_{j-1}, B_{j+1}\f$, we assign a local weighting
  72. \f$F_l(k) = (1/\sqrt{2\pi}\sigma_l)e^{-d'^2_k/2\sigma_l^2}\f$, where \f$d'_k\f$ is the distance of *k*-th
  73. row from the center row in \f$B_j\f$ and \f$\sigma_l = w\f$. Using the global and local weights, we obtain,
  74. at the same time, the reduction of role played by gradients far from line and of boundary effect,
  75. respectively.
  76. Each band \f$B_j\f$ in LSR has an associated *band descriptor(BD)* which is computed considering
  77. previous and next band (top and bottom bands are ignored when computing descriptor for first and
  78. last band). Once each band has been assignen its BD, the LBD descriptor of line is simply given by
  79. \f[LBD = (BD_1^T, BD_2^T, ... , BD^T_m)^T.\f]
  80. To compute a band descriptor \f$B_j\f$, each *k*-th row in it is considered and the gradients in such
  81. row are accumulated:
  82. \f[\begin{matrix} \bf{V1}^k_j = \lambda \sum\limits_{\bf{g}'_{d_\perp}>0}\bf{g}'_{d_\perp}, & \bf{V2}^k_j = \lambda \sum\limits_{\bf{g}'_{d_\perp}<0} -\bf{g}'_{d_\perp}, \\ \bf{V3}^k_j = \lambda \sum\limits_{\bf{g}'_{d_L}>0}\bf{g}'_{d_L}, & \bf{V4}^k_j = \lambda \sum\limits_{\bf{g}'_{d_L}<0} -\bf{g}'_{d_L}\end{matrix}.\f]
  83. with \f$\lambda = f_g(k)f_l(k)\f$.
  84. By stacking previous results, we obtain the *band description matrix (BDM)*
  85. \f[BDM_j = \left(\begin{matrix} \bf{V1}_j^1 & \bf{V1}_j^2 & \ldots & \bf{V1}_j^n \\ \bf{V2}_j^1 & \bf{V2}_j^2 & \ldots & \bf{V2}_j^n \\ \bf{V3}_j^1 & \bf{V3}_j^2 & \ldots & \bf{V3}_j^n \\ \bf{V4}_j^1 & \bf{V4}_j^2 & \ldots & \bf{V4}_j^n \end{matrix} \right) \in \mathbb{R}^{4\times n},\f]
  86. with \f$n\f$ the number of rows in band \f$B_j\f$:
  87. \f[n = \begin{cases} 2w, & j = 1||m; \\ 3w, & \mbox{else}. \end{cases}\f]
  88. Each \f$BD_j\f$ can be obtained using the standard deviation vector \f$S_j\f$ and mean vector \f$M_j\f$ of
  89. \f$BDM_J\f$. Thus, finally:
  90. \f[LBD = (M_1^T, S_1^T, M_2^T, S_2^T, \ldots, M_m^T, S_m^T)^T \in \mathbb{R}^{8m}\f]
  91. Once the LBD has been obtained, it must be converted into a binary form. For such purpose, we
  92. consider 32 possible pairs of BD inside it; each couple of BD is compared bit by bit and comparison
  93. generates an 8 bit string. Concatenating 32 comparison strings, we get the 256-bit final binary
  94. representation of a single LBD.
  95. */
  96. #endif