Basic Image AlgorithmS Library  2.8.0
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
TrackerBaseAffine2.hh
1 /*
2 This file is part of the BIAS library (Basic ImageAlgorithmS).
3 
4 Copyright (C) 2003, 2004 (see file CONTACTS 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 #ifndef __TrackerBaseAffine2_hh__
25 #define __TrackerBaseAffine2_hh__
26 
27 #include <Matcher2D/TrackerBaseInterface.hh>
28 #include <Image/PyramidImage.hh>
29 
30 namespace BIAS {
31 
32  /** @class TrackerBaseAffine2
33  @ingroup g_tracker
34  @brief devel version of antialiased affine tracker
35  @author koeser 10/2007 */
36  template <class StorageType>
37  class BIASMatcher2D_EXPORT TrackerBaseAffine2
38  : public TrackerBaseInterface<StorageType>
39  {
40  public:
41  TrackerBaseAffine2(bool only4params = false);
42 
43  /** Estimate all 6 parameters or only 4? */
44  inline void SetOnly4(bool Only4) { _SimilarityTransformOnly = Only4; }
45  inline void SetMaxAffineChange(const KLT_TYPE maxerr) {
46  _MaxAffineChange=maxerr;
47  }
48 
49  /** enable brightness variance and offset invariant computation */
50  virtual void SetAffineBrightnessInvariance(bool bi) {
51  _AffineBrightnessInvariance = bi;
52  }
53 
54  inline bool IsSimilarityTransformOnly() {
55  return _SimilarityTransformOnly ;
56  }
57 
58 
59  inline void SetRegion1(const Matrix3x3<double>& R1){
60  R1_ = R1;
61  affineNormalization_ = true;
62  }
63 
64  inline void UnsetRegion1(){
65  R1_.SetIdentity();
66  affineNormalization_ = false;
67  }
68 
69  inline void SetInitialUncertainty(const Matrix<double>& Cov) {
70  initialCov_ = Cov;
71  }
72 
73  protected:
74  /// iteration stops if position refinement is less than *_Maxerror
75  KLT_TYPE _MaxAffineChange;
76 
77  /// Estimate all 6 parameters or only 4?
79 
80  /// workaround: save values from Track_ so we dont lose them
82  KLT_TYPE residuumMAD_;
83  KLT_TYPE residuumMSD_;
84 
87 
88  PyramidImage<StorageType> _pim1, _pgradim1x, _pgradim1y,
89  _pim2, _pgradim2x, _pgradim2y;
90 
91 
93 
94  /** @brief fill in computed residui from Track_ */
95  virtual void EvaluateResult_(KLT_TYPE& mad,KLT_TYPE& msd,
96  Matrix<KLT_TYPE>& cov);
97 
98 
99  virtual int Track_(Vector2<KLT_TYPE>& p1, Vector2<KLT_TYPE>& p2,
100  Vector2<KLT_TYPE>& result, KLT_TYPE& error,
101  int &iter,
102  const Matrix2x2<KLT_TYPE>& AffinePred,
103  Matrix2x2<KLT_TYPE>& AffineResult);
104 
105  /** @brief track using affine warp
106  @param p1 point in image 1
107  @param p2 prediction for point in image 2
108  @param p2A prediction for affine warp
109  @param result result after tracking
110  @param resultA affine warp after tracking
111  @param error maxnorm of last iteration step
112  @param iter number of iterations done
113  @param Cov resulting covariance
114  @param sad sum of absolute differences
115  @param ssd sum of squared differences
116  @param SimilarityTransformOnly only estimate A, not dx,dy
117  @param ComputeCovariance, if true Cov is computed using svd
118 
119  This implementation is based on Thorsten Thormaelen's version,
120  see cpp file.
121 
122  @author koeser 06/2005
123  */
124  int TrackAffine_(KLT_TYPE p1[2], KLT_TYPE p2[2],
125  const Matrix2x2<KLT_TYPE>& p2A,
126  KLT_TYPE result[2], Matrix2x2<KLT_TYPE>& resultA,
127  KLT_TYPE& error, int &iter, Matrix<KLT_TYPE>& Cov,
128  KLT_TYPE& mad, KLT_TYPE& msd,
129  bool SimilarityTransformOnly = false,
130  bool ComputeCovariance = true);
131 
132  // ------------ affine worker functions ----------------------------
133  void GetGradientWinAffine_(const KLT_TYPE& x, const KLT_TYPE& y,
134  const KLT_TYPE& Axx, const KLT_TYPE& Ayx,
135  const KLT_TYPE& Axy, const KLT_TYPE& Ayy,
136  const int halfwidth, const int halfheight,
137  KLT_TYPE* imgdiff,
138  KLT_TYPE* out_gradx,
139  KLT_TYPE* out_grady,
140  const Matrix<double>& Cov);
141 
142 
143  void BilinearRegion1_(KLT_TYPE x, KLT_TYPE y,
144  int hws, const Vector<double>& par,
145  const Matrix<double>& Cov);
146 
188  };
189 }
190 
191 #endif // __TrackerBaseAffine2_hh__
devel version of antialiased affine tracker
virtual void SetAffineBrightnessInvariance(bool bi)
enable brightness variance and offset invariant computation
bool _SimilarityTransformOnly
Estimate all 6 parameters or only 4?
Base class for the different tracking algorithms, defining the interfaces for the tracking functions...
KLT_TYPE _MaxAffineChange
iteration stops if position refinement is less than *_Maxerror
long int ComputeCovariance(long int NumErrors, long int NumParams, double *Jac, int *Permutation, double &SumOfSquaredErrors, Matrix< double > &Cov)
Compute covariance matrix from Levenberg-Marquardt resulting Jacobian matrix J(x) and permutation mat...
Definition: Minpack.cpp:289
void SetOnly4(bool Only4)
Estimate all 6 parameters or only 4?
void SetInitialUncertainty(const Matrix< double > &Cov)
PyramidImage< StorageType > _pim2
void SetMaxAffineChange(const KLT_TYPE maxerr)
void SetRegion1(const Matrix3x3< double > &R1)
Matrix< KLT_TYPE > Cov_
workaround: save values from Track_ so we dont lose them