Basic Image AlgorithmS Library  2.8.0
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
TextureTransformAffine.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 __TextureTransformAffine__hh__
26 #define __TextureTransformAffine__hh__
27 
28 #include <Base/Common/BIASpragmaStart.hh>
29 #include <Image/TextureTransform.hh>
30 
31 
32 namespace BIAS {
33 
34  /** @class TextureTransformAffine
35  * @brief analytic properties of affine image warp
36  *
37  * See BIAS::TextureTransform for explanation of methods.
38  * @author koeser 01/2008
39  **/
40  class BIASImage_EXPORT TextureTransformAffine: public TextureTransform {
41  public:
42  TextureTransformAffine():origin_(0.0,0.0) {
43  P_.newsize(6);
44  for (unsigned int i=0; i<6; i++) P_[i] = 0;
45  }
46 
48 
49  int MapForward(const HomgPoint2D& src, HomgPoint2D& sink) const;
50 
51  int MapBackward(const HomgPoint2D& sink, HomgPoint2D& src) const;
52 
54  Matrix2x2<double>& Jac) const {
55  Jac = A_;
56  return 0;
57  }
58 
60  Matrix2x2<double>& Jac) const {
61  Jac = Ainv_;
62  return 0;
63  }
64 
65  /** @brief local warp is the same at any image position */
66  virtual bool TextureJacobianIsConstant() const { return true;};
67 
68  int ParameterJacobianForward(Matrix<double>& Jac,
69  const HomgPoint2D& src) ;
70 
71  int ParameterJacobianBackward(Matrix<double>& Jac,
72  const HomgPoint2D& sink);
73 
74  /** @brief the jacobian depends on x */
75  bool ParameterJacobianIsConstant() const { return false;};
76 
77 
78  int ParameterInversionJacobian(Matrix<double>& Jac) const;
79 
80 
81  /** @brief a11-1, a12, a21, a22-1, dx, dy */
82  void SetParameters(const Vector<double>& p);
83 
84  void ComposeWithInverseDeltaP(const Vector<double>& deltaP);
85 
88  A[0][0] = Ainv_[0][0];
89  A[0][1] = Ainv_[0][1];
90  A[0][2] = txinv_;
91  A[1][0] = Ainv_[1][0];
92  A[1][1] = Ainv_[1][1];
93  A[1][2] = tyinv_;
94  A[2][2] = 1;
95  return ExtractParameters(A);
96  }
97 
98  /** @brief origin relative to which rotation and scale is performed */
99  void SetOrigin(const Vector2<double>& origin) {
100  origin_ = origin;
101  SetParameters(P_);
102  }
103 
104  /** @brief origin relative to which rotation and scale is performed */
105  const Vector2<double>& GetOrigin() const {
106  return origin_;
107  }
108 
109  virtual TextureTransformAffine* Clone() const {
110  return new TextureTransformAffine(*this);
111  }
112 
113  /** @brief set up A and t from parameters */
114  inline void InterpretParameters(const Vector<double>& p,
115  double& A00,double& A01,
116  double& A10,double& A11,
117  double& tx, double& ty) {
118  BIASASSERT(p.Size()==6);
119  A00 = p[0]+1.0;
120  A01 = p[1];
121  A10 = p[2];
122  A11 = p[3]+1.0;
123 
124  tx = p[4] - (p[0]*origin_[0]+p[1]*origin_[1]);
125  ty = p[5] - (p[2]*origin_[0]+p[3]*origin_[1]);
126  }
127 
129  const {
130  Vector<double> p(6);
131  p[0] = A[0][0] - 1.0;
132  p[1] = A[0][1];
133  p[2] = A[1][0];
134  p[3] = A[1][1] - 1.0;
135 
136  p[4] = A[0][2] + (p[0]*origin_[0]+p[1]*origin_[1]);
137  p[5] = A[1][2] + (p[2]*origin_[0]+p[3]*origin_[1]);
138  return p;
139  }
140 
141 
142  protected:
143  /// cached local warp and inverse
145  /// cached displacement and inverse
146  double tx_, ty_, txinv_, tyinv_;
147  /// origin relative to which rotation and scale is performed
149  };
150 
151 } // end namespace BIAS
152 
153 #endif
analytic properties of affine image warp
class HomgPoint2D describes a point with 2 degrees of freedom in projective coordinates.
Definition: HomgPoint2D.hh:67
const Vector2< double > & GetOrigin() const
origin relative to which rotation and scale is performed
void SetOrigin(const Vector2< double > &origin)
origin relative to which rotation and scale is performed
virtual Vector< double > GetInverseParameters() const
returns parameter vector which undoes the current warp
void InterpretParameters(const Vector< double > &p, double &A00, double &A01, double &A10, double &A11, double &tx, double &ty)
set up A and t from parameters
class for representing parameterized image warps, such as homography, displacement, ...
unsigned int Size() const
length of the vector
Definition: Vector.hh:143
virtual bool TextureJacobianIsConstant() const
local warp is the same at any image position
int TextureJacobianForward(const HomgPoint2D &src, Matrix2x2< double > &Jac) const
shape change of the local region when mapping forward
Vector< double > ExtractParameters(const Matrix3x3< double > &A) const
virtual TextureTransformAffine * Clone() const
virtual covariant copy constructor, caller must eventually destroy the created object ...
int TextureJacobianBackward(const HomgPoint2D &sink, Matrix2x2< double > &Jac) const
shape change of the local region when mapping backward
bool ParameterJacobianIsConstant() const
the jacobian depends on x
Vector2< double > origin_
origin relative to which rotation and scale is performed