MTF
LKLD.h
1 #ifndef MTF_LKLD_H
2 #define MTF_LKLD_H
3 
4 #include "AppearanceModel.h"
5 
6 _MTF_BEGIN_NAMESPACE
7 
9 
11  int n_sub_regions_x, n_sub_regions_y;
13  int spacing_x, spacing_y;
19  int n_bins;
22  double pre_seed;
28  bool debug_mode;
29 
31  LKLDParams(const AMParams *am_params,
32  int _n_sub_regions_x, int _n_sub_regions_y,
33  int _spacing_x, int _spacing_y,
34  int _n_bins, double _pre_seed,
35  bool _partition_of_unity,
36  bool _debug_mode);
38  LKLDParams(const LKLDParams *params = nullptr);
39 };
40 
41 struct LKLDDist : AMDist{
42  typedef double ElementType;
43  typedef double ResultType;
44  LKLDDist(const string &_name, const unsigned int _feat_size) :
45  AMDist(_name), feat_size(_feat_size){}
46  double operator()(const double* a, const double* b,
47  size_t size, double worst_dist = -1) const override;
48 private:
49  const unsigned int feat_size;
50 };
51 
52 
53 // Localized Kullback–Leibler Divergence
54 class LKLD : public AppearanceModel{
55 public:
56  typedef LKLDParams ParamType;
57  typedef LKLDDist DistType;
58 
59  LKLD(const ParamType *kld_params = nullptr);
60 
61  double getLikelihood() const override{
62  return exp(f);
63  }
64 
65  void initializeSimilarity() override;
66  void initializeGrad() override;
67  void initializeHess() override;
68 
69  void updateSimilarity(bool prereq_only = true) override;
70  void updateInitGrad() override;
71  void updateCurrGrad() override;
72 
73  void cmptInitHessian(MatrixXd &hessian, const MatrixXd &curr_pix_jacobian) override;
74  void cmptCurrHessian(MatrixXd &hessian, const MatrixXd &curr_pix_jacobian) override;
75 
76  void cmptInitHessian(MatrixXd &init_hessian, const MatrixXd &init_pix_jacobian,
77  const MatrixXd &init_pix_hessian) override;
78  void cmptCurrHessian(MatrixXd &curr_hessian, const MatrixXd &curr_pix_jacobian,
79  const MatrixXd &curr_pix_hessian) override;
80 
81  void cmptSelfHessian(MatrixXd &self_hessian, const MatrixXd &curr_pix_jacobian) override;
82  void cmptSelfHessian(MatrixXd &self_hessian, const MatrixXd &curr_pix_jacobian,
83  const MatrixXd &curr_pix_hessian) override;
84 
88  const DistType* getDistFunc() override{
89  return new DistType(name, feat_size);
90  }
91  void initializeDistFeat() override;
92  unsigned int getDistFeatSize() override{ return feat_size; }
93  void updateDistFeat() override{
94  updateDistFeat(feat_vec.data());
95  }
96  const double* getDistFeat() override{ return feat_vec.data(); }
97  void updateDistFeat(double* feat_addr) override;
98 
99 private:
100 
101  ParamType params;
102 
103  char *log_fname;
104  char *time_fname;
105 
107  double hist_norm_mult;
108 
109  // let A = err_vec_size = n_bins*n_bins and N = n_pix = no. of pixels
110  MatrixXd init_hists, curr_hists;
111  MatrixXd init_hists_log, curr_hists_log;
112  MatrixXd init_grad_factors, curr_grad_factors;
113 
114  MatrixXd init_hist_mat, curr_hist_mat;
116  MatrixXd init_hist_grad, curr_hist_grad;
117  MatrixXd init_hist_hess, curr_hist_hess;
118 
119  int n_sub_regions;
120  int patch_size_x, patch_size_y;
121  int sub_region_size_x, sub_region_size_y;
122  int sub_region_n_pix;
123  MatrixX2i sub_region_x, sub_region_y;
124  MatrixXi sub_region_pix_id;
125 
126  int feat_size;
127  VectorXd feat_vec;
128 
129  // only used internally to increase speed by offlining as many computations as possible;
130  MatrixX2i _std_bspl_ids;
131  MatrixX2i _init_bspl_ids;
132  MatrixX2i _curr_bspl_ids;
133 };
134 
135 _MTF_END_NAMESPACE
136 
137 #endif
double getLikelihood() const override
returns a normalized version of the similarity that lies between 0 and 1 and can be interpreted as th...
Definition: LKLD.h:61
int n_sub_regions_x
no. of sub regions in horizontal and vertical directions
Definition: LKLD.h:11
Definition: LKLD.h:54
Definition: LKLD.h:8
bool debug_mode
decides whether logging data will be printed for debugging purposes; only matters if logging is enabl...
Definition: LKLD.h:28
Definition: AMParams.h:12
Distance functor for FLANN.
Definition: AppearanceModel.h:40
double pre_seed
initial value with which each bin of the joint histogram is pre-seeded to avoid numerical instabiliti...
Definition: LKLD.h:22
int n_bins
no.
Definition: LKLD.h:19
LKLDParams(const AMParams *am_params, int _n_sub_regions_x, int _n_sub_regions_y, int _spacing_x, int _spacing_y, int _n_bins, double _pre_seed, bool _partition_of_unity, bool _debug_mode)
value constructor
int spacing_x
spacing in pixels between adjacent sub regions
Definition: LKLD.h:13
const DistType * getDistFunc() override
Support for FLANN library.
Definition: LKLD.h:88
void updateDistFeat() override
computes a "distance" vector using the current image patch such that, when the distance vectors corre...
Definition: LKLD.h:93
Similarity function that indicates how well a candidate warped patch matches the template.
Definition: AppearanceModel.h:63
unsigned int getDistFeatSize() override
returns the size of the distance vector
Definition: LKLD.h:92
Definition: LKLD.h:41
bool partition_of_unity
decides whether the partition of unity constraint has to be strictly observed for border bins; if ena...
Definition: LKLD.h:25