Basic Image AlgorithmS Library  2.8.0
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
TextureTransform.hh
1 /*
2 This file is part of the BIAS library (Basic ImageAlgorithmS).
3 
4 Copyright (C) 2003-2009 (see file CONTACT for details)
5  Multimediale Systeme der Informationsverarbeitung
6  Institut fuer Informatik
7  Christian-Albrechts-Universitaet Kiel
8 
9 
10 BIAS is free software; you can redistribute it and/or modify
11 it under the terms of the GNU Lesser General Public License as published by
12 the Free Software Foundation; either version 2.1 of the License, or
13 (at your option) any later version.
14 
15 BIAS is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU Lesser General Public License for more details.
19 
20 You should have received a copy of the GNU Lesser General Public License
21 along with BIAS; if not, write to the Free Software
22 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 */
24 
25 #ifndef __TextureTransform__hh__
26 #define __TextureTransform__hh__
27 
28 #include <Base/Common/BIASpragmaStart.hh>
29 
30 #include <Base/Debug/Debug.hh>
31 #include <Base/Geometry/HomgPoint2D.hh>
32 #include <Base/Math/Matrix2x2.hh>
33 #include <Base/Math/Vector.hh>
34 #include <Geometry/HMatrix.hh>
35 #include <vector>
36 
37 
38 namespace BIAS {
39 
40  /** @class TextureTransform
41  * @brief class for representing parameterized image warps, such as
42  * homography, displacement, ...
43  *
44  * These classes can be exploited for mapping of images ("stitching")
45  * or for registration (gradient based estimation of the warp
46  * parameters ("KLT"), see BIAS::ImageAlignment, BIAS::BackwardMapping).
47  *
48  * This base class only defines the interface for all derived transforms.
49  * The transformations must form a group, i.e. each concatenation of
50  * transformations of the same class must also be a transformation of that
51  * class: For instance, two displacements concatenated are expressable as
52  * one "big" displacement. You must specify how to fuse the parameters
53  * into the parameter for the concatenated transform (e.g. addition).
54  *
55  * The transformations must depend on a minimal number of parameters,
56  * e.g. 6 parameters for the affine transformation. The parameter vector 0
57  * must represent the identity warp.
58  *
59  * You must at least provide the MapBackward and MapForward function. You
60  * can also provide the TextureJacobian functions, which - given
61  * two neighboring pixels in one image - measure their distance in the
62  * other image (imagine "local magnification"). These functions are needed
63  * for anti-aliased BackwardMapping and they can be approximated numerically
64  * very stable and well (but due to sampling not very fast).
65  * If you are interested in gradient based image
66  * registration, you should also provide the parameter jacobians, which tell
67  * how the mapping changes, when the parameters change. The approximation
68  * of these Jacobians is heuristic and presumably not very good. See
69  * TextureTransformHomography for an example.
70  *
71  * @author koeser 01/2008
72  **/
73  class BIASImage_EXPORT TextureTransform {
74  public:
75 
76  virtual ~TextureTransform(){};
77 
78  /** @brief override the current state with the new parameters, the meaning
79  * of the parameters is defined in the derived class'es SetParameters(). */
80  virtual void SetParameters(const Vector<double>& p) = 0;
81 
82  /** @brief get the current parameter vector */
83  void GetParameters(Vector<double>& p) const { p = P_; }
84 
85  /** @brief map a point in image "source" to a point in image "sink" */
86  virtual int MapForward(const HomgPoint2D& src, HomgPoint2D& sink) const=0;
87 
88  /** @brief map a point in image "source" to a point in image "sink" */
89  virtual int MapBackward(const HomgPoint2D& sink, HomgPoint2D& source)
90  const = 0;
91 
92  /** @brief concatenate *this and an inverse transform with param deltaP
93  and save new parameter vector to *this. Apart from very simple
94  transformations like displacement THIS IS NOT A SIMPLE ADDITION but
95  rather a multiplication-like operation!
96 
97  This function is particularly important for inverse compositional image
98  alignment (KLT) */
99  virtual void ComposeWithInverseDeltaP(const Vector<double>& deltaP) = 0;
100 
101  /** @brief shape change of the local region when mapping forward */
102  virtual int TextureJacobianForward(const HomgPoint2D& src,
103  Matrix2x2<double>& Jac) const;
104 
105  /** @brief shape change of the local region when mapping backward */
106  virtual int TextureJacobianBackward(const HomgPoint2D& sink,
107  Matrix2x2<double>& Jac) const;
108 
109  /** @brief return true if the texture jacobian does not depend on the image
110  position */
111  virtual bool TextureJacobianIsConstant() const = 0;
112 
113  /** @brief transformed position change when parameters change */
114  virtual int ParameterJacobianForward(Matrix<double>& Jac,
115  const HomgPoint2D& src);
116 
117  /** @brief transformed position change when parameters change */
118  virtual int ParameterJacobianBackward(Matrix<double>& Jac,
119  const HomgPoint2D& sink);
120 
121  /** @brief compute parameters for inverse operation and obtain the jacobian
122  of the inverse parameters with respect to the original parameters for
123  error propagation */
124  virtual int ParameterInversionJacobian(Matrix<double>& Jac) const {
125  BIASERR("not implemented in derived class. Could also be done HERE numerically by calling GetInverseParameters"); BIASABORT;
126  return -1;
127  }
128 
129  /**@brief returns parameter vector which undoes the current warp */
131  BIASERR("not implmented."); BIASABORT;
132  return Vector<double>();
133  }
134 
135  /** @brief return true, if the parameter jacobian does not depend on the
136  image position */
137  virtual bool ParameterJacobianIsConstant() const = 0;
138 
139  /** @brief virtual covariant copy constructor, caller must eventually
140  destroy the created object */
141  virtual TextureTransform* Clone() const = 0;
142 
143  protected:
144  /// current set of parameters, see SetParameters for meaning
146  };
147 
148 
149 } // end namespace BIAS
150 
151 #endif
virtual Vector< double > GetInverseParameters() const
returns parameter vector which undoes the current warp
class HomgPoint2D describes a point with 2 degrees of freedom in projective coordinates.
Definition: HomgPoint2D.hh:67
Vector< double > P_
current set of parameters, see SetParameters for meaning
class for representing parameterized image warps, such as homography, displacement, ...
virtual int ParameterInversionJacobian(Matrix< double > &Jac) const
compute parameters for inverse operation and obtain the jacobian of the inverse parameters with respe...
void GetParameters(Vector< double > &p) const
get the current parameter vector