photo.hpp 38 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856
  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) 2000-2008, Intel Corporation, all rights reserved.
  14. // Copyright (C) 2008-2012, Willow Garage Inc., all rights reserved.
  15. // Third party copyrights are property of their respective owners.
  16. //
  17. // Redistribution and use in source and binary forms, with or without modification,
  18. // are permitted provided that the following conditions are met:
  19. //
  20. // * Redistribution's of source code must retain the above copyright notice,
  21. // this list of conditions and the following disclaimer.
  22. //
  23. // * Redistribution's in binary form must reproduce the above copyright notice,
  24. // this list of conditions and the following disclaimer in the documentation
  25. // and/or other materials provided with the distribution.
  26. //
  27. // * The name of the copyright holders may not be used to endorse or promote products
  28. // derived from this software without specific prior written permission.
  29. //
  30. // This software is provided by the copyright holders and contributors "as is" and
  31. // any express or implied warranties, including, but not limited to, the implied
  32. // warranties of merchantability and fitness for a particular purpose are disclaimed.
  33. // In no event shall the Intel Corporation or contributors be liable for any direct,
  34. // indirect, incidental, special, exemplary, or consequential damages
  35. // (including, but not limited to, procurement of substitute goods or services;
  36. // loss of use, data, or profits; or business interruption) however caused
  37. // and on any theory of liability, whether in contract, strict liability,
  38. // or tort (including negligence or otherwise) arising in any way out of
  39. // the use of this software, even if advised of the possibility of such damage.
  40. //
  41. //M*/
  42. #ifndef OPENCV_PHOTO_HPP
  43. #define OPENCV_PHOTO_HPP
  44. #include "opencv2/core.hpp"
  45. #include "opencv2/imgproc.hpp"
  46. /**
  47. @defgroup photo Computational Photography
  48. This module includes photo processing algorithms
  49. @{
  50. @defgroup photo_inpaint Inpainting
  51. @defgroup photo_denoise Denoising
  52. @defgroup photo_hdr HDR imaging
  53. This section describes high dynamic range imaging algorithms namely tonemapping, exposure alignment,
  54. camera calibration with multiple exposures and exposure fusion.
  55. @defgroup photo_decolor Contrast Preserving Decolorization
  56. Useful links:
  57. http://www.cse.cuhk.edu.hk/leojia/projects/color2gray/index.html
  58. @defgroup photo_clone Seamless Cloning
  59. Useful links:
  60. https://www.learnopencv.com/seamless-cloning-using-opencv-python-cpp
  61. @defgroup photo_render Non-Photorealistic Rendering
  62. Useful links:
  63. http://www.inf.ufrgs.br/~eslgastal/DomainTransform
  64. https://www.learnopencv.com/non-photorealistic-rendering-using-opencv-python-c/
  65. @}
  66. */
  67. namespace cv
  68. {
  69. //! @addtogroup photo
  70. //! @{
  71. //! @addtogroup photo_inpaint
  72. //! @{
  73. //! the inpainting algorithm
  74. enum
  75. {
  76. INPAINT_NS = 0, //!< Use Navier-Stokes based method
  77. INPAINT_TELEA = 1 //!< Use the algorithm proposed by Alexandru Telea @cite Telea04
  78. };
  79. /** @brief Restores the selected region in an image using the region neighborhood.
  80. @param src Input 8-bit, 16-bit unsigned or 32-bit float 1-channel or 8-bit 3-channel image.
  81. @param inpaintMask Inpainting mask, 8-bit 1-channel image. Non-zero pixels indicate the area that
  82. needs to be inpainted.
  83. @param dst Output image with the same size and type as src .
  84. @param inpaintRadius Radius of a circular neighborhood of each point inpainted that is considered
  85. by the algorithm.
  86. @param flags Inpainting method that could be cv::INPAINT_NS or cv::INPAINT_TELEA
  87. The function reconstructs the selected image area from the pixel near the area boundary. The
  88. function may be used to remove dust and scratches from a scanned photo, or to remove undesirable
  89. objects from still images or video. See <http://en.wikipedia.org/wiki/Inpainting> for more details.
  90. @note
  91. - An example using the inpainting technique can be found at
  92. opencv_source_code/samples/cpp/inpaint.cpp
  93. - (Python) An example using the inpainting technique can be found at
  94. opencv_source_code/samples/python/inpaint.py
  95. */
  96. CV_EXPORTS_W void inpaint( InputArray src, InputArray inpaintMask,
  97. OutputArray dst, double inpaintRadius, int flags );
  98. //! @} photo_inpaint
  99. //! @addtogroup photo_denoise
  100. //! @{
  101. /** @brief Perform image denoising using Non-local Means Denoising algorithm
  102. <http://www.ipol.im/pub/algo/bcm_non_local_means_denoising/> with several computational
  103. optimizations. Noise expected to be a gaussian white noise
  104. @param src Input 8-bit 1-channel, 2-channel, 3-channel or 4-channel image.
  105. @param dst Output image with the same size and type as src .
  106. @param templateWindowSize Size in pixels of the template patch that is used to compute weights.
  107. Should be odd. Recommended value 7 pixels
  108. @param searchWindowSize Size in pixels of the window that is used to compute weighted average for
  109. given pixel. Should be odd. Affect performance linearly: greater searchWindowsSize - greater
  110. denoising time. Recommended value 21 pixels
  111. @param h Parameter regulating filter strength. Big h value perfectly removes noise but also
  112. removes image details, smaller h value preserves details but also preserves some noise
  113. This function expected to be applied to grayscale images. For colored images look at
  114. fastNlMeansDenoisingColored. Advanced usage of this functions can be manual denoising of colored
  115. image in different colorspaces. Such approach is used in fastNlMeansDenoisingColored by converting
  116. image to CIELAB colorspace and then separately denoise L and AB components with different h
  117. parameter.
  118. */
  119. CV_EXPORTS_W void fastNlMeansDenoising( InputArray src, OutputArray dst, float h = 3,
  120. int templateWindowSize = 7, int searchWindowSize = 21);
  121. /** @brief Perform image denoising using Non-local Means Denoising algorithm
  122. <http://www.ipol.im/pub/algo/bcm_non_local_means_denoising/> with several computational
  123. optimizations. Noise expected to be a gaussian white noise
  124. @param src Input 8-bit or 16-bit (only with NORM_L1) 1-channel,
  125. 2-channel, 3-channel or 4-channel image.
  126. @param dst Output image with the same size and type as src .
  127. @param templateWindowSize Size in pixels of the template patch that is used to compute weights.
  128. Should be odd. Recommended value 7 pixels
  129. @param searchWindowSize Size in pixels of the window that is used to compute weighted average for
  130. given pixel. Should be odd. Affect performance linearly: greater searchWindowsSize - greater
  131. denoising time. Recommended value 21 pixels
  132. @param h Array of parameters regulating filter strength, either one
  133. parameter applied to all channels or one per channel in dst. Big h value
  134. perfectly removes noise but also removes image details, smaller h
  135. value preserves details but also preserves some noise
  136. @param normType Type of norm used for weight calculation. Can be either NORM_L2 or NORM_L1
  137. This function expected to be applied to grayscale images. For colored images look at
  138. fastNlMeansDenoisingColored. Advanced usage of this functions can be manual denoising of colored
  139. image in different colorspaces. Such approach is used in fastNlMeansDenoisingColored by converting
  140. image to CIELAB colorspace and then separately denoise L and AB components with different h
  141. parameter.
  142. */
  143. CV_EXPORTS_W void fastNlMeansDenoising( InputArray src, OutputArray dst,
  144. const std::vector<float>& h,
  145. int templateWindowSize = 7, int searchWindowSize = 21,
  146. int normType = NORM_L2);
  147. /** @brief Modification of fastNlMeansDenoising function for colored images
  148. @param src Input 8-bit 3-channel image.
  149. @param dst Output image with the same size and type as src .
  150. @param templateWindowSize Size in pixels of the template patch that is used to compute weights.
  151. Should be odd. Recommended value 7 pixels
  152. @param searchWindowSize Size in pixels of the window that is used to compute weighted average for
  153. given pixel. Should be odd. Affect performance linearly: greater searchWindowsSize - greater
  154. denoising time. Recommended value 21 pixels
  155. @param h Parameter regulating filter strength for luminance component. Bigger h value perfectly
  156. removes noise but also removes image details, smaller h value preserves details but also preserves
  157. some noise
  158. @param hColor The same as h but for color components. For most images value equals 10
  159. will be enough to remove colored noise and do not distort colors
  160. The function converts image to CIELAB colorspace and then separately denoise L and AB components
  161. with given h parameters using fastNlMeansDenoising function.
  162. */
  163. CV_EXPORTS_W void fastNlMeansDenoisingColored( InputArray src, OutputArray dst,
  164. float h = 3, float hColor = 3,
  165. int templateWindowSize = 7, int searchWindowSize = 21);
  166. /** @brief Modification of fastNlMeansDenoising function for images sequence where consecutive images have been
  167. captured in small period of time. For example video. This version of the function is for grayscale
  168. images or for manual manipulation with colorspaces. For more details see
  169. <http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.131.6394>
  170. @param srcImgs Input 8-bit 1-channel, 2-channel, 3-channel or
  171. 4-channel images sequence. All images should have the same type and
  172. size.
  173. @param imgToDenoiseIndex Target image to denoise index in srcImgs sequence
  174. @param temporalWindowSize Number of surrounding images to use for target image denoising. Should
  175. be odd. Images from imgToDenoiseIndex - temporalWindowSize / 2 to
  176. imgToDenoiseIndex - temporalWindowSize / 2 from srcImgs will be used to denoise
  177. srcImgs[imgToDenoiseIndex] image.
  178. @param dst Output image with the same size and type as srcImgs images.
  179. @param templateWindowSize Size in pixels of the template patch that is used to compute weights.
  180. Should be odd. Recommended value 7 pixels
  181. @param searchWindowSize Size in pixels of the window that is used to compute weighted average for
  182. given pixel. Should be odd. Affect performance linearly: greater searchWindowsSize - greater
  183. denoising time. Recommended value 21 pixels
  184. @param h Parameter regulating filter strength. Bigger h value
  185. perfectly removes noise but also removes image details, smaller h
  186. value preserves details but also preserves some noise
  187. */
  188. CV_EXPORTS_W void fastNlMeansDenoisingMulti( InputArrayOfArrays srcImgs, OutputArray dst,
  189. int imgToDenoiseIndex, int temporalWindowSize,
  190. float h = 3, int templateWindowSize = 7, int searchWindowSize = 21);
  191. /** @brief Modification of fastNlMeansDenoising function for images sequence where consecutive images have been
  192. captured in small period of time. For example video. This version of the function is for grayscale
  193. images or for manual manipulation with colorspaces. For more details see
  194. <http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.131.6394>
  195. @param srcImgs Input 8-bit or 16-bit (only with NORM_L1) 1-channel,
  196. 2-channel, 3-channel or 4-channel images sequence. All images should
  197. have the same type and size.
  198. @param imgToDenoiseIndex Target image to denoise index in srcImgs sequence
  199. @param temporalWindowSize Number of surrounding images to use for target image denoising. Should
  200. be odd. Images from imgToDenoiseIndex - temporalWindowSize / 2 to
  201. imgToDenoiseIndex - temporalWindowSize / 2 from srcImgs will be used to denoise
  202. srcImgs[imgToDenoiseIndex] image.
  203. @param dst Output image with the same size and type as srcImgs images.
  204. @param templateWindowSize Size in pixels of the template patch that is used to compute weights.
  205. Should be odd. Recommended value 7 pixels
  206. @param searchWindowSize Size in pixels of the window that is used to compute weighted average for
  207. given pixel. Should be odd. Affect performance linearly: greater searchWindowsSize - greater
  208. denoising time. Recommended value 21 pixels
  209. @param h Array of parameters regulating filter strength, either one
  210. parameter applied to all channels or one per channel in dst. Big h value
  211. perfectly removes noise but also removes image details, smaller h
  212. value preserves details but also preserves some noise
  213. @param normType Type of norm used for weight calculation. Can be either NORM_L2 or NORM_L1
  214. */
  215. CV_EXPORTS_W void fastNlMeansDenoisingMulti( InputArrayOfArrays srcImgs, OutputArray dst,
  216. int imgToDenoiseIndex, int temporalWindowSize,
  217. const std::vector<float>& h,
  218. int templateWindowSize = 7, int searchWindowSize = 21,
  219. int normType = NORM_L2);
  220. /** @brief Modification of fastNlMeansDenoisingMulti function for colored images sequences
  221. @param srcImgs Input 8-bit 3-channel images sequence. All images should have the same type and
  222. size.
  223. @param imgToDenoiseIndex Target image to denoise index in srcImgs sequence
  224. @param temporalWindowSize Number of surrounding images to use for target image denoising. Should
  225. be odd. Images from imgToDenoiseIndex - temporalWindowSize / 2 to
  226. imgToDenoiseIndex - temporalWindowSize / 2 from srcImgs will be used to denoise
  227. srcImgs[imgToDenoiseIndex] image.
  228. @param dst Output image with the same size and type as srcImgs images.
  229. @param templateWindowSize Size in pixels of the template patch that is used to compute weights.
  230. Should be odd. Recommended value 7 pixels
  231. @param searchWindowSize Size in pixels of the window that is used to compute weighted average for
  232. given pixel. Should be odd. Affect performance linearly: greater searchWindowsSize - greater
  233. denoising time. Recommended value 21 pixels
  234. @param h Parameter regulating filter strength for luminance component. Bigger h value perfectly
  235. removes noise but also removes image details, smaller h value preserves details but also preserves
  236. some noise.
  237. @param hColor The same as h but for color components.
  238. The function converts images to CIELAB colorspace and then separately denoise L and AB components
  239. with given h parameters using fastNlMeansDenoisingMulti function.
  240. */
  241. CV_EXPORTS_W void fastNlMeansDenoisingColoredMulti( InputArrayOfArrays srcImgs, OutputArray dst,
  242. int imgToDenoiseIndex, int temporalWindowSize,
  243. float h = 3, float hColor = 3,
  244. int templateWindowSize = 7, int searchWindowSize = 21);
  245. /** @brief Primal-dual algorithm is an algorithm for solving special types of variational problems (that is,
  246. finding a function to minimize some functional). As the image denoising, in particular, may be seen
  247. as the variational problem, primal-dual algorithm then can be used to perform denoising and this is
  248. exactly what is implemented.
  249. It should be noted, that this implementation was taken from the July 2013 blog entry
  250. @cite MA13 , which also contained (slightly more general) ready-to-use source code on Python.
  251. Subsequently, that code was rewritten on C++ with the usage of openCV by Vadim Pisarevsky at the end
  252. of July 2013 and finally it was slightly adapted by later authors.
  253. Although the thorough discussion and justification of the algorithm involved may be found in
  254. @cite ChambolleEtAl, it might make sense to skim over it here, following @cite MA13 . To begin
  255. with, we consider the 1-byte gray-level images as the functions from the rectangular domain of
  256. pixels (it may be seen as set
  257. \f$\left\{(x,y)\in\mathbb{N}\times\mathbb{N}\mid 1\leq x\leq n,\;1\leq y\leq m\right\}\f$ for some
  258. \f$m,\;n\in\mathbb{N}\f$) into \f$\{0,1,\dots,255\}\f$. We shall denote the noised images as \f$f_i\f$ and with
  259. this view, given some image \f$x\f$ of the same size, we may measure how bad it is by the formula
  260. \f[\left\|\left\|\nabla x\right\|\right\| + \lambda\sum_i\left\|\left\|x-f_i\right\|\right\|\f]
  261. \f$\|\|\cdot\|\|\f$ here denotes \f$L_2\f$-norm and as you see, the first addend states that we want our
  262. image to be smooth (ideally, having zero gradient, thus being constant) and the second states that
  263. we want our result to be close to the observations we've got. If we treat \f$x\f$ as a function, this is
  264. exactly the functional what we seek to minimize and here the Primal-Dual algorithm comes into play.
  265. @param observations This array should contain one or more noised versions of the image that is to
  266. be restored.
  267. @param result Here the denoised image will be stored. There is no need to do pre-allocation of
  268. storage space, as it will be automatically allocated, if necessary.
  269. @param lambda Corresponds to \f$\lambda\f$ in the formulas above. As it is enlarged, the smooth
  270. (blurred) images are treated more favorably than detailed (but maybe more noised) ones. Roughly
  271. speaking, as it becomes smaller, the result will be more blur but more sever outliers will be
  272. removed.
  273. @param niters Number of iterations that the algorithm will run. Of course, as more iterations as
  274. better, but it is hard to quantitatively refine this statement, so just use the default and
  275. increase it if the results are poor.
  276. */
  277. CV_EXPORTS_W void denoise_TVL1(const std::vector<Mat>& observations,Mat& result, double lambda=1.0, int niters=30);
  278. //! @} photo_denoise
  279. //! @addtogroup photo_hdr
  280. //! @{
  281. enum { LDR_SIZE = 256 };
  282. /** @brief Base class for tonemapping algorithms - tools that are used to map HDR image to 8-bit range.
  283. */
  284. class CV_EXPORTS_W Tonemap : public Algorithm
  285. {
  286. public:
  287. /** @brief Tonemaps image
  288. @param src source image - CV_32FC3 Mat (float 32 bits 3 channels)
  289. @param dst destination image - CV_32FC3 Mat with values in [0, 1] range
  290. */
  291. CV_WRAP virtual void process(InputArray src, OutputArray dst) = 0;
  292. CV_WRAP virtual float getGamma() const = 0;
  293. CV_WRAP virtual void setGamma(float gamma) = 0;
  294. };
  295. /** @brief Creates simple linear mapper with gamma correction
  296. @param gamma positive value for gamma correction. Gamma value of 1.0 implies no correction, gamma
  297. equal to 2.2f is suitable for most displays.
  298. Generally gamma \> 1 brightens the image and gamma \< 1 darkens it.
  299. */
  300. CV_EXPORTS_W Ptr<Tonemap> createTonemap(float gamma = 1.0f);
  301. /** @brief Adaptive logarithmic mapping is a fast global tonemapping algorithm that scales the image in
  302. logarithmic domain.
  303. Since it's a global operator the same function is applied to all the pixels, it is controlled by the
  304. bias parameter.
  305. Optional saturation enhancement is possible as described in @cite FL02 .
  306. For more information see @cite DM03 .
  307. */
  308. class CV_EXPORTS_W TonemapDrago : public Tonemap
  309. {
  310. public:
  311. CV_WRAP virtual float getSaturation() const = 0;
  312. CV_WRAP virtual void setSaturation(float saturation) = 0;
  313. CV_WRAP virtual float getBias() const = 0;
  314. CV_WRAP virtual void setBias(float bias) = 0;
  315. };
  316. /** @brief Creates TonemapDrago object
  317. @param gamma gamma value for gamma correction. See createTonemap
  318. @param saturation positive saturation enhancement value. 1.0 preserves saturation, values greater
  319. than 1 increase saturation and values less than 1 decrease it.
  320. @param bias value for bias function in [0, 1] range. Values from 0.7 to 0.9 usually give best
  321. results, default value is 0.85.
  322. */
  323. CV_EXPORTS_W Ptr<TonemapDrago> createTonemapDrago(float gamma = 1.0f, float saturation = 1.0f, float bias = 0.85f);
  324. /** @brief This is a global tonemapping operator that models human visual system.
  325. Mapping function is controlled by adaptation parameter, that is computed using light adaptation and
  326. color adaptation.
  327. For more information see @cite RD05 .
  328. */
  329. class CV_EXPORTS_W TonemapReinhard : public Tonemap
  330. {
  331. public:
  332. CV_WRAP virtual float getIntensity() const = 0;
  333. CV_WRAP virtual void setIntensity(float intensity) = 0;
  334. CV_WRAP virtual float getLightAdaptation() const = 0;
  335. CV_WRAP virtual void setLightAdaptation(float light_adapt) = 0;
  336. CV_WRAP virtual float getColorAdaptation() const = 0;
  337. CV_WRAP virtual void setColorAdaptation(float color_adapt) = 0;
  338. };
  339. /** @brief Creates TonemapReinhard object
  340. @param gamma gamma value for gamma correction. See createTonemap
  341. @param intensity result intensity in [-8, 8] range. Greater intensity produces brighter results.
  342. @param light_adapt light adaptation in [0, 1] range. If 1 adaptation is based only on pixel
  343. value, if 0 it's global, otherwise it's a weighted mean of this two cases.
  344. @param color_adapt chromatic adaptation in [0, 1] range. If 1 channels are treated independently,
  345. if 0 adaptation level is the same for each channel.
  346. */
  347. CV_EXPORTS_W Ptr<TonemapReinhard>
  348. createTonemapReinhard(float gamma = 1.0f, float intensity = 0.0f, float light_adapt = 1.0f, float color_adapt = 0.0f);
  349. /** @brief This algorithm transforms image to contrast using gradients on all levels of gaussian pyramid,
  350. transforms contrast values to HVS response and scales the response. After this the image is
  351. reconstructed from new contrast values.
  352. For more information see @cite MM06 .
  353. */
  354. class CV_EXPORTS_W TonemapMantiuk : public Tonemap
  355. {
  356. public:
  357. CV_WRAP virtual float getScale() const = 0;
  358. CV_WRAP virtual void setScale(float scale) = 0;
  359. CV_WRAP virtual float getSaturation() const = 0;
  360. CV_WRAP virtual void setSaturation(float saturation) = 0;
  361. };
  362. /** @brief Creates TonemapMantiuk object
  363. @param gamma gamma value for gamma correction. See createTonemap
  364. @param scale contrast scale factor. HVS response is multiplied by this parameter, thus compressing
  365. dynamic range. Values from 0.6 to 0.9 produce best results.
  366. @param saturation saturation enhancement value. See createTonemapDrago
  367. */
  368. CV_EXPORTS_W Ptr<TonemapMantiuk>
  369. createTonemapMantiuk(float gamma = 1.0f, float scale = 0.7f, float saturation = 1.0f);
  370. /** @brief The base class for algorithms that align images of the same scene with different exposures
  371. */
  372. class CV_EXPORTS_W AlignExposures : public Algorithm
  373. {
  374. public:
  375. /** @brief Aligns images
  376. @param src vector of input images
  377. @param dst vector of aligned images
  378. @param times vector of exposure time values for each image
  379. @param response 256x1 matrix with inverse camera response function for each pixel value, it should
  380. have the same number of channels as images.
  381. */
  382. CV_WRAP virtual void process(InputArrayOfArrays src, std::vector<Mat>& dst,
  383. InputArray times, InputArray response) = 0;
  384. };
  385. /** @brief This algorithm converts images to median threshold bitmaps (1 for pixels brighter than median
  386. luminance and 0 otherwise) and than aligns the resulting bitmaps using bit operations.
  387. It is invariant to exposure, so exposure values and camera response are not necessary.
  388. In this implementation new image regions are filled with zeros.
  389. For more information see @cite GW03 .
  390. */
  391. class CV_EXPORTS_W AlignMTB : public AlignExposures
  392. {
  393. public:
  394. CV_WRAP virtual void process(InputArrayOfArrays src, std::vector<Mat>& dst,
  395. InputArray times, InputArray response) CV_OVERRIDE = 0;
  396. /** @brief Short version of process, that doesn't take extra arguments.
  397. @param src vector of input images
  398. @param dst vector of aligned images
  399. */
  400. CV_WRAP virtual void process(InputArrayOfArrays src, std::vector<Mat>& dst) = 0;
  401. /** @brief Calculates shift between two images, i. e. how to shift the second image to correspond it with the
  402. first.
  403. @param img0 first image
  404. @param img1 second image
  405. */
  406. CV_WRAP virtual Point calculateShift(InputArray img0, InputArray img1) = 0;
  407. /** @brief Helper function, that shift Mat filling new regions with zeros.
  408. @param src input image
  409. @param dst result image
  410. @param shift shift value
  411. */
  412. CV_WRAP virtual void shiftMat(InputArray src, OutputArray dst, const Point shift) = 0;
  413. /** @brief Computes median threshold and exclude bitmaps of given image.
  414. @param img input image
  415. @param tb median threshold bitmap
  416. @param eb exclude bitmap
  417. */
  418. CV_WRAP virtual void computeBitmaps(InputArray img, OutputArray tb, OutputArray eb) = 0;
  419. CV_WRAP virtual int getMaxBits() const = 0;
  420. CV_WRAP virtual void setMaxBits(int max_bits) = 0;
  421. CV_WRAP virtual int getExcludeRange() const = 0;
  422. CV_WRAP virtual void setExcludeRange(int exclude_range) = 0;
  423. CV_WRAP virtual bool getCut() const = 0;
  424. CV_WRAP virtual void setCut(bool value) = 0;
  425. };
  426. /** @brief Creates AlignMTB object
  427. @param max_bits logarithm to the base 2 of maximal shift in each dimension. Values of 5 and 6 are
  428. usually good enough (31 and 63 pixels shift respectively).
  429. @param exclude_range range for exclusion bitmap that is constructed to suppress noise around the
  430. median value.
  431. @param cut if true cuts images, otherwise fills the new regions with zeros.
  432. */
  433. CV_EXPORTS_W Ptr<AlignMTB> createAlignMTB(int max_bits = 6, int exclude_range = 4, bool cut = true);
  434. /** @brief The base class for camera response calibration algorithms.
  435. */
  436. class CV_EXPORTS_W CalibrateCRF : public Algorithm
  437. {
  438. public:
  439. /** @brief Recovers inverse camera response.
  440. @param src vector of input images
  441. @param dst 256x1 matrix with inverse camera response function
  442. @param times vector of exposure time values for each image
  443. */
  444. CV_WRAP virtual void process(InputArrayOfArrays src, OutputArray dst, InputArray times) = 0;
  445. };
  446. /** @brief Inverse camera response function is extracted for each brightness value by minimizing an objective
  447. function as linear system. Objective function is constructed using pixel values on the same position
  448. in all images, extra term is added to make the result smoother.
  449. For more information see @cite DM97 .
  450. */
  451. class CV_EXPORTS_W CalibrateDebevec : public CalibrateCRF
  452. {
  453. public:
  454. CV_WRAP virtual float getLambda() const = 0;
  455. CV_WRAP virtual void setLambda(float lambda) = 0;
  456. CV_WRAP virtual int getSamples() const = 0;
  457. CV_WRAP virtual void setSamples(int samples) = 0;
  458. CV_WRAP virtual bool getRandom() const = 0;
  459. CV_WRAP virtual void setRandom(bool random) = 0;
  460. };
  461. /** @brief Creates CalibrateDebevec object
  462. @param samples number of pixel locations to use
  463. @param lambda smoothness term weight. Greater values produce smoother results, but can alter the
  464. response.
  465. @param random if true sample pixel locations are chosen at random, otherwise they form a
  466. rectangular grid.
  467. */
  468. CV_EXPORTS_W Ptr<CalibrateDebevec> createCalibrateDebevec(int samples = 70, float lambda = 10.0f, bool random = false);
  469. /** @brief Inverse camera response function is extracted for each brightness value by minimizing an objective
  470. function as linear system. This algorithm uses all image pixels.
  471. For more information see @cite RB99 .
  472. */
  473. class CV_EXPORTS_W CalibrateRobertson : public CalibrateCRF
  474. {
  475. public:
  476. CV_WRAP virtual int getMaxIter() const = 0;
  477. CV_WRAP virtual void setMaxIter(int max_iter) = 0;
  478. CV_WRAP virtual float getThreshold() const = 0;
  479. CV_WRAP virtual void setThreshold(float threshold) = 0;
  480. CV_WRAP virtual Mat getRadiance() const = 0;
  481. };
  482. /** @brief Creates CalibrateRobertson object
  483. @param max_iter maximal number of Gauss-Seidel solver iterations.
  484. @param threshold target difference between results of two successive steps of the minimization.
  485. */
  486. CV_EXPORTS_W Ptr<CalibrateRobertson> createCalibrateRobertson(int max_iter = 30, float threshold = 0.01f);
  487. /** @brief The base class algorithms that can merge exposure sequence to a single image.
  488. */
  489. class CV_EXPORTS_W MergeExposures : public Algorithm
  490. {
  491. public:
  492. /** @brief Merges images.
  493. @param src vector of input images
  494. @param dst result image
  495. @param times vector of exposure time values for each image
  496. @param response 256x1 matrix with inverse camera response function for each pixel value, it should
  497. have the same number of channels as images.
  498. */
  499. CV_WRAP virtual void process(InputArrayOfArrays src, OutputArray dst,
  500. InputArray times, InputArray response) = 0;
  501. };
  502. /** @brief The resulting HDR image is calculated as weighted average of the exposures considering exposure
  503. values and camera response.
  504. For more information see @cite DM97 .
  505. */
  506. class CV_EXPORTS_W MergeDebevec : public MergeExposures
  507. {
  508. public:
  509. CV_WRAP virtual void process(InputArrayOfArrays src, OutputArray dst,
  510. InputArray times, InputArray response) CV_OVERRIDE = 0;
  511. CV_WRAP virtual void process(InputArrayOfArrays src, OutputArray dst, InputArray times) = 0;
  512. };
  513. /** @brief Creates MergeDebevec object
  514. */
  515. CV_EXPORTS_W Ptr<MergeDebevec> createMergeDebevec();
  516. /** @brief Pixels are weighted using contrast, saturation and well-exposedness measures, than images are
  517. combined using laplacian pyramids.
  518. The resulting image weight is constructed as weighted average of contrast, saturation and
  519. well-exposedness measures.
  520. The resulting image doesn't require tonemapping and can be converted to 8-bit image by multiplying
  521. by 255, but it's recommended to apply gamma correction and/or linear tonemapping.
  522. For more information see @cite MK07 .
  523. */
  524. class CV_EXPORTS_W MergeMertens : public MergeExposures
  525. {
  526. public:
  527. CV_WRAP virtual void process(InputArrayOfArrays src, OutputArray dst,
  528. InputArray times, InputArray response) CV_OVERRIDE = 0;
  529. /** @brief Short version of process, that doesn't take extra arguments.
  530. @param src vector of input images
  531. @param dst result image
  532. */
  533. CV_WRAP virtual void process(InputArrayOfArrays src, OutputArray dst) = 0;
  534. CV_WRAP virtual float getContrastWeight() const = 0;
  535. CV_WRAP virtual void setContrastWeight(float contrast_weiht) = 0;
  536. CV_WRAP virtual float getSaturationWeight() const = 0;
  537. CV_WRAP virtual void setSaturationWeight(float saturation_weight) = 0;
  538. CV_WRAP virtual float getExposureWeight() const = 0;
  539. CV_WRAP virtual void setExposureWeight(float exposure_weight) = 0;
  540. };
  541. /** @brief Creates MergeMertens object
  542. @param contrast_weight contrast measure weight. See MergeMertens.
  543. @param saturation_weight saturation measure weight
  544. @param exposure_weight well-exposedness measure weight
  545. */
  546. CV_EXPORTS_W Ptr<MergeMertens>
  547. createMergeMertens(float contrast_weight = 1.0f, float saturation_weight = 1.0f, float exposure_weight = 0.0f);
  548. /** @brief The resulting HDR image is calculated as weighted average of the exposures considering exposure
  549. values and camera response.
  550. For more information see @cite RB99 .
  551. */
  552. class CV_EXPORTS_W MergeRobertson : public MergeExposures
  553. {
  554. public:
  555. CV_WRAP virtual void process(InputArrayOfArrays src, OutputArray dst,
  556. InputArray times, InputArray response) CV_OVERRIDE = 0;
  557. CV_WRAP virtual void process(InputArrayOfArrays src, OutputArray dst, InputArray times) = 0;
  558. };
  559. /** @brief Creates MergeRobertson object
  560. */
  561. CV_EXPORTS_W Ptr<MergeRobertson> createMergeRobertson();
  562. //! @} photo_hdr
  563. //! @addtogroup photo_decolor
  564. //! @{
  565. /** @brief Transforms a color image to a grayscale image. It is a basic tool in digital printing, stylized
  566. black-and-white photograph rendering, and in many single channel image processing applications
  567. @cite CL12 .
  568. @param src Input 8-bit 3-channel image.
  569. @param grayscale Output 8-bit 1-channel image.
  570. @param color_boost Output 8-bit 3-channel image.
  571. This function is to be applied on color images.
  572. */
  573. CV_EXPORTS_W void decolor( InputArray src, OutputArray grayscale, OutputArray color_boost);
  574. //! @} photo_decolor
  575. //! @addtogroup photo_clone
  576. //! @{
  577. //! seamlessClone algorithm flags
  578. enum
  579. {
  580. /** The power of the method is fully expressed when inserting objects with complex outlines into a new background*/
  581. NORMAL_CLONE = 1,
  582. /** The classic method, color-based selection and alpha masking might be time consuming and often leaves an undesirable
  583. halo. Seamless cloning, even averaged with the original image, is not effective. Mixed seamless cloning based on a loose selection proves effective.*/
  584. MIXED_CLONE = 2,
  585. /** Monochrome transfer allows the user to easily replace certain features of one object by alternative features.*/
  586. MONOCHROME_TRANSFER = 3};
  587. /** @example samples/cpp/tutorial_code/photo/seamless_cloning/cloning_demo.cpp
  588. An example using seamlessClone function
  589. */
  590. /** @brief Image editing tasks concern either global changes (color/intensity corrections, filters,
  591. deformations) or local changes concerned to a selection. Here we are interested in achieving local
  592. changes, ones that are restricted to a region manually selected (ROI), in a seamless and effortless
  593. manner. The extent of the changes ranges from slight distortions to complete replacement by novel
  594. content @cite PM03 .
  595. @param src Input 8-bit 3-channel image.
  596. @param dst Input 8-bit 3-channel image.
  597. @param mask Input 8-bit 1 or 3-channel image.
  598. @param p Point in dst image where object is placed.
  599. @param blend Output image with the same size and type as dst.
  600. @param flags Cloning method that could be cv::NORMAL_CLONE, cv::MIXED_CLONE or cv::MONOCHROME_TRANSFER
  601. */
  602. CV_EXPORTS_W void seamlessClone( InputArray src, InputArray dst, InputArray mask, Point p,
  603. OutputArray blend, int flags);
  604. /** @brief Given an original color image, two differently colored versions of this image can be mixed
  605. seamlessly.
  606. @param src Input 8-bit 3-channel image.
  607. @param mask Input 8-bit 1 or 3-channel image.
  608. @param dst Output image with the same size and type as src .
  609. @param red_mul R-channel multiply factor.
  610. @param green_mul G-channel multiply factor.
  611. @param blue_mul B-channel multiply factor.
  612. Multiplication factor is between .5 to 2.5.
  613. */
  614. CV_EXPORTS_W void colorChange(InputArray src, InputArray mask, OutputArray dst, float red_mul = 1.0f,
  615. float green_mul = 1.0f, float blue_mul = 1.0f);
  616. /** @brief Applying an appropriate non-linear transformation to the gradient field inside the selection and
  617. then integrating back with a Poisson solver, modifies locally the apparent illumination of an image.
  618. @param src Input 8-bit 3-channel image.
  619. @param mask Input 8-bit 1 or 3-channel image.
  620. @param dst Output image with the same size and type as src.
  621. @param alpha Value ranges between 0-2.
  622. @param beta Value ranges between 0-2.
  623. This is useful to highlight under-exposed foreground objects or to reduce specular reflections.
  624. */
  625. CV_EXPORTS_W void illuminationChange(InputArray src, InputArray mask, OutputArray dst,
  626. float alpha = 0.2f, float beta = 0.4f);
  627. /** @brief By retaining only the gradients at edge locations, before integrating with the Poisson solver, one
  628. washes out the texture of the selected region, giving its contents a flat aspect. Here Canny Edge %Detector is used.
  629. @param src Input 8-bit 3-channel image.
  630. @param mask Input 8-bit 1 or 3-channel image.
  631. @param dst Output image with the same size and type as src.
  632. @param low_threshold %Range from 0 to 100.
  633. @param high_threshold Value \> 100.
  634. @param kernel_size The size of the Sobel kernel to be used.
  635. @note
  636. The algorithm assumes that the color of the source image is close to that of the destination. This
  637. assumption means that when the colors don't match, the source image color gets tinted toward the
  638. color of the destination image.
  639. */
  640. CV_EXPORTS_W void textureFlattening(InputArray src, InputArray mask, OutputArray dst,
  641. float low_threshold = 30, float high_threshold = 45,
  642. int kernel_size = 3);
  643. //! @} photo_clone
  644. //! @addtogroup photo_render
  645. //! @{
  646. //! Edge preserving filters
  647. enum
  648. {
  649. RECURS_FILTER = 1, //!< Recursive Filtering
  650. NORMCONV_FILTER = 2 //!< Normalized Convolution Filtering
  651. };
  652. /** @brief Filtering is the fundamental operation in image and video processing. Edge-preserving smoothing
  653. filters are used in many different applications @cite EM11 .
  654. @param src Input 8-bit 3-channel image.
  655. @param dst Output 8-bit 3-channel image.
  656. @param flags Edge preserving filters: cv::RECURS_FILTER or cv::NORMCONV_FILTER
  657. @param sigma_s %Range between 0 to 200.
  658. @param sigma_r %Range between 0 to 1.
  659. */
  660. CV_EXPORTS_W void edgePreservingFilter(InputArray src, OutputArray dst, int flags = 1,
  661. float sigma_s = 60, float sigma_r = 0.4f);
  662. /** @brief This filter enhances the details of a particular image.
  663. @param src Input 8-bit 3-channel image.
  664. @param dst Output image with the same size and type as src.
  665. @param sigma_s %Range between 0 to 200.
  666. @param sigma_r %Range between 0 to 1.
  667. */
  668. CV_EXPORTS_W void detailEnhance(InputArray src, OutputArray dst, float sigma_s = 10,
  669. float sigma_r = 0.15f);
  670. /** @example samples/cpp/tutorial_code/photo/non_photorealistic_rendering/npr_demo.cpp
  671. An example using non-photorealistic line drawing functions
  672. */
  673. /** @brief Pencil-like non-photorealistic line drawing
  674. @param src Input 8-bit 3-channel image.
  675. @param dst1 Output 8-bit 1-channel image.
  676. @param dst2 Output image with the same size and type as src.
  677. @param sigma_s %Range between 0 to 200.
  678. @param sigma_r %Range between 0 to 1.
  679. @param shade_factor %Range between 0 to 0.1.
  680. */
  681. CV_EXPORTS_W void pencilSketch(InputArray src, OutputArray dst1, OutputArray dst2,
  682. float sigma_s = 60, float sigma_r = 0.07f, float shade_factor = 0.02f);
  683. /** @brief Stylization aims to produce digital imagery with a wide variety of effects not focused on
  684. photorealism. Edge-aware filters are ideal for stylization, as they can abstract regions of low
  685. contrast while preserving, or enhancing, high-contrast features.
  686. @param src Input 8-bit 3-channel image.
  687. @param dst Output image with the same size and type as src.
  688. @param sigma_s %Range between 0 to 200.
  689. @param sigma_r %Range between 0 to 1.
  690. */
  691. CV_EXPORTS_W void stylization(InputArray src, OutputArray dst, float sigma_s = 60,
  692. float sigma_r = 0.45f);
  693. //! @} photo_render
  694. //! @} photo
  695. } // cv
  696. #endif