MTF
SCV.h
1 #ifndef MTF_SCV_H
2 #define MTF_SCV_H
3 
4 #include "SSDBase.h"
5 
6 _MTF_BEGIN_NAMESPACE
7 
8 struct SCVParams : AMParams{
9 
10  enum class HistType{ Dirac, Bilinear, BSpline };
11  static const char* toString(HistType _hist_type);
16  HistType hist_type;
22  int n_bins;
28  double pre_seed;
29  // enable this to map each intensity to the weighted average of the two entries of the intensity map corresponding
30  // to the floor and ceil of that intensity; if disabled it will be mapped to the entry corresponding to its floor
31  // leading to some information loss due to the fractional part that was discarded
32  bool weighted_mapping;
33  // enable this to automatically update the initial pixel gradient and hessian using the latest intensity map
34  // whenever the current pixel gradient is updated assuming that the current pixel values and thus the intensity map must
35  // have changed since the last time the initial pixel gradient was computed;
36  bool mapped_gradient;
37  // decides if true SCV will be computed between the distance features; if it is turned off
38  // then the joint distribution will be
39  // computed from the two arguments to the distance functor itself after which the
40  // first argument will be mapped according to the expectation formula; note that
41  // using a KD tree index with this turned off will not produce the desired results because
42  // in that case this AM is no longer KD Tree compatible
43  bool approx_dist_feat;
46  bool debug_mode;
47 
49  SCVParams(const AMParams *am_params,
50  HistType _hist_type, int _n_bins, double _pre_seed,
51  bool _partition_of_unity, bool _weighted_mapping,
52  bool _mapped_gradient, bool _approx_dist_feat,
53  bool _debug_mode);
55  SCVParams(const SCVParams *params = nullptr);
56 };
57 
59  typedef double ElementType;
60  typedef double ResultType;
61  SCVDist(const string &_name, const unsigned int _patch_size,
62  const int _n_bins, const bool _approx_dist_feat);
63  double operator()(const double* a, const double* b,
64  size_t size, double worst_dist = -1) const override;
65 private:
66  const unsigned int patch_size;
67  const int n_bins;
68  const bool approx_dist_feat;
69 };
70 
72 class SCV : public SSDBase{
73 public:
74  typedef SCVParams ParamType;
75  typedef SCVDist DistType;
76  typedef SCVParams::HistType HistType;
77 
78  SCV(const ParamType *scv_params = nullptr, const int _n_channels = 1);
79  void initializePixVals(const Matrix2Xd& init_pts) override;
80  void initializePixGrad(const Matrix2Xd &init_pts) override;
81  void initializePixGrad(const Matrix8Xd &warped_offset_pts) override;
82 
83  void updatePixGrad(const Matrix2Xd &curr_pts) override;
84  void updatePixGrad(const Matrix8Xd &warped_offset_pts) override;
85 
86  void updateSimilarity(bool prereq_only = true) override;
87 
88  void updatePixHess(const Matrix2Xd &curr_pts) override;
89  using AppearanceModel::updatePixHess;
90  const DistType* getDistFunc() override{
91  return new DistType(name, patch_size, params.n_bins, params.approx_dist_feat);
92  }
93 
94 protected:
95 
96  ParamType params;
97 
98  cv::Mat init_img_cv;
99  EigImgT init_img;
100  VectorXd I0_orig;
101  Matrix2Xd init_pts;
102  Matrix8Xd init_warped_offset_pts;
103 
104  double hist_pre_seed;
105 
106  VectorXd intensity_map;
107 
108  // let A = err_vec_size = n_bins*n_bins and N = n_pix = no. of pixels
110  MatrixXd curr_joint_hist;
111  VectorXd init_hist, curr_hist;
112  MatrixXd init_hist_mat, curr_hist_mat;
113 
114 private:
115  // only used internally to increase speed by offlining as many computations as possible;
116  MatrixX2i _std_bspl_ids;
117  MatrixX2i _init_bspl_ids;
118  MatrixX2i _curr_bspl_ids;
119  EigImgMat _init_img;
120 };
121 
122 _MTF_END_NAMESPACE
123 
124 #endif
Definition: SSDBase.h:45
Sum of Conditional Variance.
Definition: SCV.h:72
double pre_seed
initial value with which each bin of the joint histogram is pre-seeded to avoid numerical instabiliti...
Definition: SCV.h:28
int n_bins
no.
Definition: SCV.h:22
bool debug_mode
decides whether logging data will be printed for debugging purposes; only matters if logging option i...
Definition: SCV.h:46
Definition: AMParams.h:12
base class for appearance models that use the negative sum of squared differences ("SSD") or L2 norm ...
Definition: SSDBase.h:16
Definition: SCV.h:8
Definition: SCV.h:58
bool partition_of_unity
decides whether the partition of unity constraint has to be strictly observed for border bins; if ena...
Definition: SCV.h:25
HistType hist_type
method used for computing the joint histogram: Dirac: Dirac delta function that uses nearest neighbor...
Definition: SCV.h:16
MatrixXd curr_joint_hist
n_bins x n_bins joint histograms;
Definition: SCV.h:110
SCVParams(const AMParams *am_params, HistType _hist_type, int _n_bins, double _pre_seed, bool _partition_of_unity, bool _weighted_mapping, bool _mapped_gradient, bool _approx_dist_feat, bool _debug_mode)
value constructor