MTF
MI.h
1 #ifndef MTF_MI_H
2 #define MTF_MI_H
3 
4 #include "AppearanceModel.h"
5 
6 _MTF_BEGIN_NAMESPACE
7 
8 struct MIParams : AMParams{
14  int n_bins;
18  double pre_seed;
22  ImageBase *pix_mapper;
23 
24  bool debug_mode;
25 
28  MIParams(const AMParams *am_params,
29  int _n_bins, double _pre_seed,
30  bool _partition_of_unity,
31  ImageBase *_pix_mapper,
32  bool _debug_mode);
34  MIParams(const MIParams *params = nullptr);
35 };
36 
37 struct MIDist : AMDist{
38  typedef double ElementType;
39  typedef double ResultType;
40  MIDist(const string &_name, const int _n_bins,
41  const unsigned int _feat_size, const unsigned int _patch_size,
42  const double _hist_pre_seed, const double _pre_seed,
43  const MatrixX2i *_std_bspl_ids,
44  const double _log_hist_norm_mult);
45  double operator()(const double* a, const double* b,
46  size_t size, double worst_dist = -1) const override;
47 private:
48  const int n_bins;
49  const unsigned int feat_size;
50  const unsigned int patch_size;
51  const double pre_seed, hist_pre_seed;
52  const MatrixX2i *std_bspl_ids;
53  const double log_hist_norm_mult;
54 };
55 
56 class MI : public AppearanceModel{
57 public:
58 
59  typedef MIParams ParamType;
60  typedef MIDist DistType;
61 
62  MI(const ParamType *mi_params = nullptr, const int _n_channels = 1);
63 
64  double getLikelihood() const override;
65 
66  void initializePixVals(const Matrix2Xd& init_pts) override;
67  void initializeSimilarity() override;
68  void initializeGrad() override;
69  void initializeHess() override;
70 
71  void updatePixVals(const Matrix2Xd& curr_pts) override;
72  void updateSimilarity(bool prereq_only = true) override;
73  void updateInitGrad() override;
74  void updateCurrGrad() override;
75 
76  void cmptInitHessian(MatrixXd &hessian, const MatrixXd &curr_pix_jacobian) override;
77  void cmptCurrHessian(MatrixXd &hessian, const MatrixXd &curr_pix_jacobian) override;
78 
79  void cmptInitHessian(MatrixXd &init_hessian, const MatrixXd &init_pix_jacobian,
80  const MatrixXd &init_pix_hessian) override;
81  void cmptCurrHessian(MatrixXd &curr_hessian, const MatrixXd &curr_pix_jacobian,
82  const MatrixXd &curr_pix_hessian) override;
83 
84  void cmptSelfHessian(MatrixXd &self_hessian, const MatrixXd &curr_pix_jacobian) override;
85  void cmptSelfHessian(MatrixXd &self_hessian, const MatrixXd &curr_pix_jacobian,
86  const MatrixXd &curr_pix_hessian) override;
87 
88  //static const utils::BSpline3WithDiffPtr bSpline3_arr[4];
89 
90  //-----------------------------------functor support-----------------------------------//
91  const DistType* getDistFunc() override{
92  return new DistType(name, params.n_bins, feat_size,
93  patch_size, hist_pre_seed, params.pre_seed,
94  &std_bspl_ids, log_hist_norm_mult);
95  }
96  void initializeDistFeat() override{
97  feat_vec.resize(feat_size);
98  }
99  void updateDistFeat() override{
100  updateDistFeat(feat_vec.data());
101  }
102  const double* getDistFeat() override{ return feat_vec.data(); }
103  void updateDistFeat(double* feat_addr) override;
104  unsigned int getDistFeatSize() override{ return feat_size; }
105 
106 private:
107  ParamType params;
108 
109  char *log_fname;
110  char *time_fname;
111 
112  double max_similarity;
113 
115  double hist_pre_seed;
117  double hist_norm_mult;
118  unsigned int joint_hist_size;
119 
120  // let A = joint_hist_size = n_bins*n_bins and N = n_pix = no. of pixels
122  MatrixXd joint_hist;
123  VectorXd init_hist, curr_hist;
124  MatrixXd init_hist_mat, curr_hist_mat;
125 
127  MatrixXd init_joint_hist_grad, curr_joint_hist_grad;
129  MatrixXd init_hist_grad, curr_hist_grad;
130  MatrixXd init_hist_hess, curr_hist_hess;
131  MatrixXd init_grad_factor, curr_grad_factor;
132 
133  VectorXd init_hist_log, curr_hist_log;
134  MatrixXd joint_hist_log;
135 
136  MatrixXd self_joint_hist, self_joint_hist_log;
137  MatrixXd self_grad_factor;
138 
139  unsigned int feat_size;
140  VectorXd feat_vec;
141  double log_hist_norm_mult;
142 
143  // only used internally to increase speed by offlining as many computations as possible;
144  MatrixX2i std_bspl_ids;
145  MatrixX2i init_bspl_ids;
146  MatrixX2i curr_bspl_ids;
147  MatrixXi linear_idx;
148 
149  void cmptSelfHist();
150 };
151 
152 _MTF_END_NAMESPACE
153 
154 #endif
MIParams(const AMParams *am_params, int _n_bins, double _pre_seed, bool _partition_of_unity, ImageBase *_pix_mapper, bool _debug_mode)
decides whether logging data will be printed for debugging purposes;
unsigned int getDistFeatSize() override
returns the size of the distance vector
Definition: MI.h:104
void initializeDistFeat() override
to be called once during initialization if any of the distance feature functionality is to be used ...
Definition: MI.h:96
Definition: MI.h:37
double pre_seed
initial value with which each bin of the joint histogram is pre-seeded
Definition: MI.h:18
bool partition_of_unity
decides whether the partition of unity constraint has to be strictly observed for border bins; if ena...
Definition: MI.h:21
void updateDistFeat() override
computes a "distance" vector using the current image patch such that, when the distance vectors corre...
Definition: MI.h:99
Definition: AMParams.h:12
Definition: MI.h:56
Distance functor for FLANN.
Definition: AppearanceModel.h:40
Definition: ImageBase.h:51
int n_bins
no.
Definition: MI.h:14
Definition: MI.h:8
Similarity function that indicates how well a candidate warped patch matches the template.
Definition: AppearanceModel.h:63