MTF
NGF.h
1 #ifndef MTF_NGF_H
2 #define MTF_NGF_H
3 
4 #include "AppearanceModel.h"
5 #include <Eigen/Sparse>
6 
7 _MTF_BEGIN_NAMESPACE
8 
9 struct NGFParams : AMParams{
11  double eta;
13  bool use_ssd;
15  NGFParams(const AMParams *am_params,
16  double _eta, bool _use_ssd);
18  NGFParams(const NGFParams *params = nullptr);
19 };
20 
21 struct NGFDist : AMDist{
22  typedef double ElementType;
23  typedef double ResultType;
24  NGFDist(const string &_name, const bool _use_ssd,
25  const unsigned int _patch_size);
26  double operator()(const double* a, const double* b,
27  size_t size, double worst_dist = -1) const override;
28 private:
29  const bool use_ssd;
30  const unsigned int patch_size;
31 };
32 
34 class NGF : public AppearanceModel{
35 public:
36  typedef NGFParams ParamType;
37  typedef NGFDist DistType;
38  typedef SparseMatrix<double> SpMat;
39  typedef Triplet<double> SpTr;
40 
41  NGF(const ParamType *ngf_params = nullptr, const int _n_channels = 1);
42 
43  double getLikelihood() const override;
44 
45  //-------------------------------initialize functions------------------------------------//
46  void initializePixVals(const Matrix2Xd& init_pts) override;
47  void initializeSimilarity() override;
48  void initializeGrad() override;
49  void initializeHess() override{}
50 
51  //-------------------------------update functions------------------------------------//
52  void updatePixVals(const Matrix2Xd& curr_pts) override;
53  void updateSimilarity(bool prereq_only = true) override;
54  void updateInitGrad() override;
55  void updateCurrGrad() override;
56 
57  //-------------------------------interfacing functions------------------------------------//
58  void cmptSelfHessian(MatrixXd &self_hessian, const MatrixXd &curr_pix_jacobian) override;
59  void cmptSelfHessian(MatrixXd &self_hessian, const MatrixXd &curr_pix_jacobian,
60  const MatrixXd &curr_pix_hessian) override{
61  cmptSelfHessian(self_hessian, curr_pix_jacobian);
62  };
63 
64  // -------------------- distance feature functions -------------------- //
65  int feat_size;
66  VectorXd curr_feat_vec;
67  const DistType* getDistFunc() override{
68  return new DistType(name, params.use_ssd, patch_size);
69  }
70  unsigned int getDistFeatSize() override{ return feat_size; }
71  void initializeDistFeat() override;
72  void updateDistFeat(double* feat_addr) override;
73  const double* getDistFeat() override{ return curr_feat_vec.data(); }
74  void updateDistFeat() override{ updateDistFeat(curr_feat_vec.data()); }
75 
76 protected:
77  ParamType params;
78  double epsilon;
79 
80  PixGradT norm_dI0_dx, norm_dIt_dx;
81  Matrix2Xd _init_pts, _curr_pts;
82  VectorXd fac_t, fac_0, rc;
83  SpMat dr_dIt, dr_dI0;
84  VectorXd grad_I0_x, grad_I0_y, grad_It_x, grad_It_y;
85  VectorXd grad_I0_norm, grad_It_norm;
86  VectorXd grad_I0_squared_norm, grad_It_squared_norm;
87 
88 };
89 
90 _MTF_END_NAMESPACE
91 
92 #endif
unsigned int getDistFeatSize() override
returns the size of the distance vector
Definition: NGF.h:70
Definition: NGF.h:9
Definition: AMParams.h:12
double eta
estimate of noise level in the image
Definition: NGF.h:11
NGFParams(const AMParams *am_params, double _eta, bool _use_ssd)
value constructor
Distance functor for FLANN.
Definition: AppearanceModel.h:40
Normalized Gradient Fields.
Definition: NGF.h:34
void initializeHess() override
even though the Hessian of the error norm w.r.t.
Definition: NGF.h:49
Similarity function that indicates how well a candidate warped patch matches the template.
Definition: AppearanceModel.h:63
bool use_ssd
use SSD formulation of NGF (not implemented completely yet);
Definition: NGF.h:13
void updateDistFeat() override
computes a "distance" vector using the current image patch such that, when the distance vectors corre...
Definition: NGF.h:74
Definition: NGF.h:21