MTF
SPSS.h
1 #ifndef MTF_SPSS_H
2 #define MTF_SPSS_H
3 
4 #include "AppearanceModel.h"
5 
6 _MTF_BEGIN_NAMESPACE
7 
9  double k;
10  ImageBase *pix_mapper;
11 
12  SPSSParams(const AMParams *am_params,
13  double _k,
14  ImageBase *_pix_mapper);
15  SPSSParams(const SPSSParams *params = nullptr);
16 };
17 
18 struct SPSSDist : AMDist{
19  typedef bool is_kdtree_distance;
20  typedef double ElementType;
21  typedef double ResultType;
22  SPSSDist(const string &_name, const double _c) : AMDist(_name), c(_c){}
23  double operator()(const double* a, const double* b,
24  size_t size, double worst_dist = -1) const override;
25  double accum_dist(const ElementType& a,
26  const ElementType& b, int) const{
27  return -(2 * a*b + c) / (a*a + b*b + c);
28  }
29 private:
30  const double c;
31 };
32 
34 class SPSS : public AppearanceModel{
35 public:
36  typedef SPSSParams ParamType;
37  typedef SPSSDist DistType;
38 
39  SPSS(const ParamType *spss_params = nullptr, const int _n_channels = 1);
40 
41  double getLikelihood() const override;
42 
43  //-------------------------------initialize functions------------------------------------//
44  void initializePixVals(const Matrix2Xd& init_pts) override;
45  void initializeSimilarity() override;
46  void initializeGrad() override;
47  void initializeHess() override{}
48 
49  //-------------------------------update functions------------------------------------//
50  void updatePixVals(const Matrix2Xd& curr_pts) override;
51 
52  void updateSimilarity(bool prereq_only = true) override;
53  void updateInitGrad() override;
54  // nothing is done here since curr_grad is same as and shares memory with curr_pix_diff
55  void updateCurrGrad() override;
56 
57  void cmptInitHessian(MatrixXd &d2f_dp2, const MatrixXd &dI0_dp) override;
58  void cmptInitHessian(MatrixXd &d2f_dp2, const MatrixXd &dI0_dp,
59  const MatrixXd &d2I0_dp2) override;
60 
61  void cmptCurrHessian(MatrixXd &d2f_dp2, const MatrixXd &dIt_dp) override;
62  void cmptCurrHessian(MatrixXd &d2f_dp2, const MatrixXd &dIt_dp,
63  const MatrixXd &d2It_dp2) override;
64 
65  void cmptSelfHessian(MatrixXd &d2f_dp2, const MatrixXd &dIt_dp) override;
66  void cmptSelfHessian(MatrixXd &d2f_dp2, const MatrixXd &dIt_dp,
67  const MatrixXd &d2It_dp2) override;
68 
69  /*Support for FLANN library*/
70  const DistType* getDistFunc() override{
71  return new DistType(name, c);
72  }
73  unsigned int getDistFeatSize() override{ return patch_size; }
74  void initializeDistFeat() override{}
75  void updateDistFeat(double* feat_addr) override;
76  const double* getDistFeat() override{ return getCurrPixVals().data(); }
77  void updateDistFeat() override{}
78 
79 protected:
80  ParamType params;
81 
82  double c;
83  VectorXd f_vec, f_vec_den;
84  VectorXd I0_sqr, It_sqr;
85 };
86 
87 _MTF_END_NAMESPACE
88 
89 #endif
Definition: SPSS.h:18
Definition: AMParams.h:12
Sum of Pixelwise Structural Similarity.
Definition: SPSS.h:34
Distance functor for FLANN.
Definition: AppearanceModel.h:40
void initializeDistFeat() override
to be called once during initialization if any of the distance feature functionality is to be used ...
Definition: SPSS.h:74
Definition: ImageBase.h:51
unsigned int getDistFeatSize() override
returns the size of the distance vector
Definition: SPSS.h:73
void updateDistFeat() override
computes a "distance" vector using the current image patch such that, when the distance vectors corre...
Definition: SPSS.h:77
Definition: SPSS.h:8
Similarity function that indicates how well a candidate warped patch matches the template.
Definition: AppearanceModel.h:63
void initializeHess() override
even though the Hessian of the error norm w.r.t.
Definition: SPSS.h:47