ximgproc.hpp 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  1. /*
  2. * By downloading, copying, installing or using the software you agree to this license.
  3. * If you do not agree to this license, do not download, install,
  4. * copy or use the software.
  5. *
  6. *
  7. * License Agreement
  8. * For Open Source Computer Vision Library
  9. * (3 - clause BSD License)
  10. *
  11. * Redistribution and use in source and binary forms, with or without modification,
  12. * are permitted provided that the following conditions are met :
  13. *
  14. * * Redistributions of source code must retain the above copyright notice,
  15. * this list of conditions and the following disclaimer.
  16. *
  17. * * Redistributions in binary form must reproduce the above copyright notice,
  18. * this list of conditions and the following disclaimer in the documentation
  19. * and / or other materials provided with the distribution.
  20. *
  21. * * Neither the names of the copyright holders nor the names of the contributors
  22. * may be used to endorse or promote products derived from this software
  23. * without specific prior written permission.
  24. *
  25. * This software is provided by the copyright holders and contributors "as is" and
  26. * any express or implied warranties, including, but not limited to, the implied
  27. * warranties of merchantability and fitness for a particular purpose are disclaimed.
  28. * In no event shall copyright holders or contributors be liable for any direct,
  29. * indirect, incidental, special, exemplary, or consequential damages
  30. * (including, but not limited to, procurement of substitute goods or services;
  31. * loss of use, data, or profits; or business interruption) however caused
  32. * and on any theory of liability, whether in contract, strict liability,
  33. * or tort(including negligence or otherwise) arising in any way out of
  34. * the use of this software, even if advised of the possibility of such damage.
  35. */
  36. #ifndef __OPENCV_XIMGPROC_HPP__
  37. #define __OPENCV_XIMGPROC_HPP__
  38. #include "ximgproc/edge_filter.hpp"
  39. #include "ximgproc/disparity_filter.hpp"
  40. #include "ximgproc/sparse_match_interpolator.hpp"
  41. #include "ximgproc/structured_edge_detection.hpp"
  42. #include "ximgproc/edgeboxes.hpp"
  43. #include "ximgproc/seeds.hpp"
  44. #include "ximgproc/segmentation.hpp"
  45. #include "ximgproc/fast_hough_transform.hpp"
  46. #include "ximgproc/estimated_covariance.hpp"
  47. #include "ximgproc/weighted_median_filter.hpp"
  48. #include "ximgproc/slic.hpp"
  49. #include "ximgproc/lsc.hpp"
  50. #include "ximgproc/paillou_filter.hpp"
  51. #include "ximgproc/fast_line_detector.hpp"
  52. #include "ximgproc/deriche_filter.hpp"
  53. #include "ximgproc/peilin.hpp"
  54. #include "ximgproc/fourier_descriptors.hpp"
  55. #include "ximgproc/ridgefilter.hpp"
  56. #include "ximgproc/brightedges.hpp"
  57. #include "ximgproc/run_length_morphology.hpp"
  58. #include "ximgproc/edgepreserving_filter.hpp"
  59. #include "ximgproc/color_match.hpp"
  60. /** @defgroup ximgproc Extended Image Processing
  61. @{
  62. @defgroup ximgproc_edge Structured forests for fast edge detection
  63. This module contains implementations of modern structured edge detection algorithms,
  64. i.e. algorithms which somehow takes into account pixel affinities in natural images.
  65. @defgroup ximgproc_edgeboxes EdgeBoxes
  66. @defgroup ximgproc_filters Filters
  67. @defgroup ximgproc_superpixel Superpixels
  68. @defgroup ximgproc_segmentation Image segmentation
  69. @defgroup ximgproc_fast_line_detector Fast line detector
  70. @defgroup ximgproc_fourier Fourier descriptors
  71. @defgroup ximgproc_run_length_morphology Binary morphology on run-length encoded image
  72. These functions support morphological operations on binary images. In order to be fast and space efficient binary images are encoded with a run-length representation.
  73. This representation groups continuous horizontal sequences of "on" pixels together in a "run". A run is charactarized by the column position of the first pixel in the run, the column
  74. position of the last pixel in the run and the row position. This representation is very compact for binary images which contain large continuous areas of "on" and "off" pixels. A checkerboard
  75. pattern would be a good example. The representation is not so suitable for binary images created from random noise images or other images where little correlation between neighboring pixels
  76. exists.
  77. The morphological operations supported here are very similar to the operations supported in the imgproc module. In general they are fast. However on several occasions they are slower than the functions
  78. from imgproc. The structuring elements of cv::MORPH_RECT and cv::MORPH_CROSS have very good support from the imgproc module. Also small structuring elements are very fast in imgproc (presumably
  79. due to opencl support). Therefore the functions from this module are recommended for larger structuring elements (cv::MORPH_ELLIPSE or self defined structuring elements). A sample application
  80. (run_length_morphology_demo) is supplied which allows to compare the speed of some morphological operations for the functions using run-length encoding and the imgproc functions for a given image.
  81. Run length encoded images are stored in standard opencv images. Images have a single column of cv::Point3i elements. The number of rows is the number of run + 1. The first row contains
  82. the size of the original (not encoded) image. For the runs the following mapping is used (x: column begin, y: column end (last column), z: row).
  83. The size of the original image is required for compatiblity with the imgproc functions when the boundary handling requires that pixel outside the image boundary are
  84. "on".
  85. @}
  86. */
  87. namespace cv
  88. {
  89. namespace ximgproc
  90. {
  91. enum ThinningTypes{
  92. THINNING_ZHANGSUEN = 0, // Thinning technique of Zhang-Suen
  93. THINNING_GUOHALL = 1 // Thinning technique of Guo-Hall
  94. };
  95. /**
  96. * @brief Specifies the binarization method to use in cv::ximgproc::niBlackThreshold
  97. */
  98. enum LocalBinarizationMethods{
  99. BINARIZATION_NIBLACK = 0, //!< Classic Niblack binarization. See @cite Niblack1985 .
  100. BINARIZATION_SAUVOLA = 1, //!< Sauvola's technique. See @cite Sauvola1997 .
  101. BINARIZATION_WOLF = 2, //!< Wolf's technique. See @cite Wolf2004 .
  102. BINARIZATION_NICK = 3 //!< NICK technique. See @cite Khurshid2009 .
  103. };
  104. //! @addtogroup ximgproc
  105. //! @{
  106. /** @brief Performs thresholding on input images using Niblack's technique or some of the
  107. popular variations it inspired.
  108. The function transforms a grayscale image to a binary image according to the formulae:
  109. - **THRESH_BINARY**
  110. \f[dst(x,y) = \fork{\texttt{maxValue}}{if \(src(x,y) > T(x,y)\)}{0}{otherwise}\f]
  111. - **THRESH_BINARY_INV**
  112. \f[dst(x,y) = \fork{0}{if \(src(x,y) > T(x,y)\)}{\texttt{maxValue}}{otherwise}\f]
  113. where \f$T(x,y)\f$ is a threshold calculated individually for each pixel.
  114. The threshold value \f$T(x, y)\f$ is determined based on the binarization method chosen. For
  115. classic Niblack, it is the mean minus \f$ k \f$ times standard deviation of
  116. \f$\texttt{blockSize} \times\texttt{blockSize}\f$ neighborhood of \f$(x, y)\f$.
  117. The function can't process the image in-place.
  118. @param _src Source 8-bit single-channel image.
  119. @param _dst Destination image of the same size and the same type as src.
  120. @param maxValue Non-zero value assigned to the pixels for which the condition is satisfied,
  121. used with the THRESH_BINARY and THRESH_BINARY_INV thresholding types.
  122. @param type Thresholding type, see cv::ThresholdTypes.
  123. @param blockSize Size of a pixel neighborhood that is used to calculate a threshold value
  124. for the pixel: 3, 5, 7, and so on.
  125. @param k The user-adjustable parameter used by Niblack and inspired techniques. For Niblack, this is
  126. normally a value between 0 and 1 that is multiplied with the standard deviation and subtracted from
  127. the mean.
  128. @param binarizationMethod Binarization method to use. By default, Niblack's technique is used.
  129. Other techniques can be specified, see cv::ximgproc::LocalBinarizationMethods.
  130. @sa threshold, adaptiveThreshold
  131. */
  132. CV_EXPORTS_W void niBlackThreshold( InputArray _src, OutputArray _dst,
  133. double maxValue, int type,
  134. int blockSize, double k, int binarizationMethod = BINARIZATION_NIBLACK );
  135. /** @brief Applies a binary blob thinning operation, to achieve a skeletization of the input image.
  136. The function transforms a binary blob image into a skeletized form using the technique of Zhang-Suen.
  137. @param src Source 8-bit single-channel image, containing binary blobs, with blobs having 255 pixel values.
  138. @param dst Destination image of the same size and the same type as src. The function can work in-place.
  139. @param thinningType Value that defines which thinning algorithm should be used. See cv::ximgproc::ThinningTypes
  140. */
  141. CV_EXPORTS_W void thinning( InputArray src, OutputArray dst, int thinningType = THINNING_ZHANGSUEN);
  142. /** @brief Performs anisotropic diffusian on an image.
  143. The function applies Perona-Malik anisotropic diffusion to an image. This is the solution to the partial differential equation:
  144. \f[{\frac {\partial I}{\partial t}}={\mathrm {div}}\left(c(x,y,t)\nabla I\right)=\nabla c\cdot \nabla I+c(x,y,t)\Delta I\f]
  145. Suggested functions for c(x,y,t) are:
  146. \f[c\left(\|\nabla I\|\right)=e^{{-\left(\|\nabla I\|/K\right)^{2}}}\f]
  147. or
  148. \f[ c\left(\|\nabla I\|\right)={\frac {1}{1+\left({\frac {\|\nabla I\|}{K}}\right)^{2}}} \f]
  149. @param src Grayscale Source image.
  150. @param dst Destination image of the same size and the same number of channels as src .
  151. @param alpha The amount of time to step forward by on each iteration (normally, it's between 0 and 1).
  152. @param K sensitivity to the edges
  153. @param niters The number of iterations
  154. */
  155. CV_EXPORTS_W void anisotropicDiffusion(InputArray src, OutputArray dst, float alpha, float K, int niters );
  156. //! @}
  157. }
  158. }
  159. #endif // __OPENCV_XIMGPROC_HPP__