map.hpp 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  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. // Copyright (C) 2013, Alfonso Sanchez-Beato, all rights reserved.
  10. // Third party copyrights are property of their respective owners.
  11. //
  12. // Redistribution and use in source and binary forms, with or without modification,
  13. // are permitted provided that the following conditions are met:
  14. //
  15. // * Redistribution's of source code must retain the above copyright notice,
  16. // this list of conditions and the following disclaimer.
  17. //
  18. // * Redistribution's in binary form must reproduce the above copyright notice,
  19. // this list of conditions and the following disclaimer in the documentation
  20. // and/or other materials provided with the distribution.
  21. //
  22. // * The name of the copyright holders may not be used to endorse or promote products
  23. // derived from this software 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 the 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. //M*/
  37. #ifndef MAP_H_
  38. #define MAP_H_
  39. #include <opencv2/core.hpp> // Basic OpenCV structures (cv::Mat, Scalar)
  40. /** @defgroup reg Image Registration
  41. The Registration module implements parametric image registration. The implemented method is direct
  42. alignment, that is, it uses directly the pixel values for calculating the registration between a
  43. pair of images, as opposed to feature-based registration. The implementation follows essentially the
  44. corresponding part of @cite Szeliski06 .
  45. Feature based methods have some advantages over pixel based methods when we are trying to register
  46. pictures that have been shoot under different lighting conditions or exposition times, or when the
  47. images overlap only partially. On the other hand, the main advantage of pixel-based methods when
  48. compared to feature based methods is their better precision for some pictures (those shoot under
  49. similar lighting conditions and that have a significative overlap), due to the fact that we are
  50. using all the information available in the image, which allows us to achieve subpixel accuracy. This
  51. is particularly important for certain applications like multi-frame denoising or super-resolution.
  52. In fact, pixel and feature registration methods can complement each other: an application could
  53. first obtain a coarse registration using features and then refine the registration using a pixel
  54. based method on the overlapping area of the images. The code developed allows this use case.
  55. The module implements classes derived from the abstract classes cv::reg::Map or cv::reg::Mapper. The
  56. former models a coordinate transformation between two reference frames, while the later encapsulates
  57. a way of invoking a method that calculates a Map between two images. Although the objective has been
  58. to implement pixel based methods, the module can be extended to support other methods that can
  59. calculate transformations between images (feature methods, optical flow, etc.).
  60. Each class derived from Map implements a motion model, as follows:
  61. - MapShift: Models a simple translation
  62. - MapAffine: Models an affine transformation
  63. - MapProjec: Models a projective transformation
  64. MapProject can also be used to model affine motion or translations, but some operations on it are
  65. more costly, and that is the reason for defining the other two classes.
  66. The classes derived from Mapper are
  67. - MapperGradShift: Gradient based alignment for calculating translations. It produces a MapShift
  68. (two parameters that correspond to the shift vector).
  69. - MapperGradEuclid: Gradient based alignment for euclidean motions, that is, rotations and
  70. translations. It calculates three parameters (angle and shift vector), although the result is
  71. stored in a MapAffine object for convenience.
  72. - MapperGradSimilar: Gradient based alignment for calculating similarities, which adds scaling to
  73. the euclidean motion. It calculates four parameters (two for the anti-symmetric matrix and two
  74. for the shift vector), although the result is stored in a MapAffine object for better
  75. convenience.
  76. - MapperGradAffine: Gradient based alignment for an affine motion model. The number of parameters
  77. is six and the result is stored in a MapAffine object.
  78. - MapperGradProj: Gradient based alignment for calculating projective transformations. The number
  79. of parameters is eight and the result is stored in a MapProject object.
  80. - MapperPyramid: It implements hyerarchical motion estimation using a Gaussian pyramid. Its
  81. constructor accepts as argument any other object that implements the Mapper interface, and it is
  82. that mapper the one called by MapperPyramid for each scale of the pyramid.
  83. If the motion between the images is not very small, the normal way of using these classes is to
  84. create a MapperGrad\* object and use it as input to create a MapperPyramid, which in turn is called
  85. to perform the calculation. However, if the motion between the images is small enough, we can use
  86. directly the MapperGrad\* classes. Another possibility is to use first a feature based method to
  87. perform a coarse registration and then do a refinement through MapperPyramid or directly a
  88. MapperGrad\* object. The "calculate" method of the mappers accepts an initial estimation of the
  89. motion as input.
  90. When deciding which MapperGrad to use we must take into account that mappers with more parameters
  91. can handle more complex motions, but involve more calculations and are therefore slower. Also, if we
  92. are confident on the motion model that is followed by the sequence, increasing the number of
  93. parameters beyond what we need will decrease the accuracy: it is better to use the least number of
  94. degrees of freedom that we can.
  95. In the module tests there are examples that show how to register a pair of images using any of the
  96. implemented mappers.
  97. */
  98. namespace cv {
  99. namespace reg {
  100. //! @addtogroup reg
  101. //! @{
  102. /** @brief Base class for modelling a Map between two images.
  103. The class is only used to define the common interface for any possible map.
  104. */
  105. class CV_EXPORTS_W Map
  106. {
  107. public:
  108. /*!
  109. * Virtual destructor
  110. */
  111. virtual ~Map();
  112. /*!
  113. * Warps image to a new coordinate frame. The calculation is img2(x)=img1(T^{-1}(x)), as we
  114. * have to apply the inverse transformation to the points to move them to were the values
  115. * of img2 are.
  116. * \param[in] img1 Original image
  117. * \param[out] img2 Warped image
  118. */
  119. CV_WRAP virtual void warp(InputArray img1, OutputArray img2) const;
  120. /*!
  121. * Warps image to a new coordinate frame. The calculation is img2(x)=img1(T(x)), so in fact
  122. * this is the inverse warping as we are taking the value of img1 with the forward
  123. * transformation of the points.
  124. * \param[in] img1 Original image
  125. * \param[out] img2 Warped image
  126. */
  127. CV_WRAP virtual void inverseWarp(InputArray img1, OutputArray img2) const = 0;
  128. /*!
  129. * Calculates the inverse map
  130. * \return Inverse map
  131. */
  132. CV_WRAP virtual cv::Ptr<Map> inverseMap() const = 0;
  133. /*!
  134. * Changes the map composing the current transformation with the one provided in the call.
  135. * The order is first the current transformation, then the input argument.
  136. * \param[in] map Transformation to compose with.
  137. */
  138. CV_WRAP virtual void compose(cv::Ptr<Map> map) = 0;
  139. /*!
  140. * Scales the map by a given factor as if the coordinates system is expanded/compressed
  141. * by that factor.
  142. * \param[in] factor Expansion if bigger than one, compression if smaller than one
  143. */
  144. CV_WRAP virtual void scale(double factor) = 0;
  145. };
  146. //! @}
  147. }} // namespace cv::reg
  148. #endif // MAP_H_