MTF
LSCV.h
1 #ifndef MTF_LSCV_H
2 #define MTF_LSCV_H
3 
4 #include "SSDBase.h"
5 
6 _MTF_BEGIN_NAMESPACE
7 
9 
11  int n_sub_regions_x, n_sub_regions_y;
13  int spacing_x, spacing_y;
14  // use affine or linear mapping instead of the standard one
15  bool affine_mapping;
16  // update the template only once per frame, i.e. when new_frame is set to true
17  bool once_per_frame;
18 
20  int n_bins;
23  double pre_seed;
24 
29 
30  // show the locations of the subregions
31  bool show_subregions;
32 
36 
38  LSCVParams(const AMParams *am_params,
39  int _sub_regions_x, int _sub_regions_y,
40  int _spacing_x, int _spacing_y,
41  bool _affine_mapping, bool _once_per_frame,
42  int _n_bins, double _pre_seed, bool _weighted_mapping,
43  bool _show_subregions, bool _approx_dist_feat);
45  LSCVParams(const LSCVParams *params = nullptr);
46 };
47 
49  typedef double ElementType;
50  typedef double ResultType;
51  LSCVDist(const string &_name, const bool _approx_dist_feat,
52  const int _n_bins, const int _n_sub_regions_x, const int _n_sub_regions_y,
53  const int _n_sub_regions, const unsigned int _n_pix,
54  const unsigned int _resx, const unsigned int _resy,
55  const MatrixX2i *_sub_region_x, const MatrixX2i *_sub_region_y,
56  const MatrixXd *_sub_region_wts, const MatrixXi *_subregion_idx,
57  const ColPivHouseholderQR<MatrixX2d> *_intensity_vals_dec);
58  double operator()(const double* a, const double* b,
59  size_t size, double worst_dist = -1) const override;
60 private:
61  const bool approx_dist_feat;
62  const unsigned int n_pix, resx, resy;
63  const int n_bins, n_sub_regions_x, n_sub_regions_y, n_sub_regions;
64  const MatrixX2i *sub_region_x, *sub_region_y;
65  const MatrixXd *sub_region_wts;
66  const MatrixXi *subregion_idx;
67  const ColPivHouseholderQR<MatrixX2d> *intensity_vals_dec;
68 };
69 
71 class LSCV : public SSDBase{
72 
73 public:
74 
75  typedef LSCVParams ParamType;
76  typedef LSCVDist DistType;
77 
78  LSCV(const ParamType *lscv_params = nullptr, int _n_channels=1);
79 
80  void initializePixVals(const Matrix2Xd& init_pts) override;
81  void updatePixVals(const Matrix2Xd& curr_pts) override;
82 
83  void updateSimilarity(bool prereq_only = true) override;
84 
85  const DistType* getDistFunc() override{
86  return new DistType(name, params.approx_dist_feat, n_pix, resx, resy,
87  params.n_bins, params.n_sub_regions_x, params.n_sub_regions_y,
88  n_sub_regions, &sub_region_x, &sub_region_y, &sub_region_wts,
89  &_subregion_idx, &intensity_vals_dec);
90  }
91 
92 protected:
93 
94  ParamType params;
95  VectorXd I0_orig;
96 
97  double hist_pre_seed;
98 
99  VectorXd intensity_map;
100 
101  int n_sub_regions;
102  int sub_region_size_x, sub_region_size_y;
103  int intensity_range;
104 
105  // let A = err_vec_size = n_bins*n_bins and N = n_pix = no. of pixels
107  MatrixXd curr_joint_hist;
108  VectorXd init_hist, curr_hist;
109 
110  MatrixXdMr init_patch, curr_patch;
111  MatrixX2i sub_region_x, sub_region_y;
112  MatrixX2d sub_region_centers;
113  VectorXd I0_mapped;
114  MatrixX2d intensity_vals;
115  ColPivHouseholderQR<MatrixX2d> intensity_vals_dec;
116  MatrixXd sub_region_wts;
117 
118  // only used internally to increase speed by offlining as many computations as possible;
119  MatrixX2i _std_bspl_ids;
120  MatrixX2i _init_bspl_ids;
121  MatrixX2i _curr_bspl_ids;
122  EigImgMat _init_img;
123  MatrixXi _subregion_idx;//used for indexing the sub region locations
124  MatrixXi _pts_idx;//used for indexing the pixel locations in the flattened patch
125 
126  cv::Mat patch_img;
127  cv::Mat patch_img_uchar;
128  char *patch_win_name;
129  int sub_region_id;
130  char *log_fname;
131 
132  void showSubRegions(const EigImgT& img, const Matrix2Xd& pts);
133 };
134 
135 _MTF_END_NAMESPACE
136 
137 #endif
int n_sub_regions_x
no. of sub regions in horizontal and vertical directions
Definition: LSCV.h:11
int resx
horizontal and vertical sampling resolutions
Definition: ImageBase.h:23
Locally adaptive Sum of Conditional Variance.
Definition: LSCV.h:71
Definition: SSDBase.h:45
bool approx_dist_feat
decides whether logging data will be printed for debugging purposes; only matters if logging option i...
Definition: LSCV.h:35
Definition: LSCV.h:8
Definition: LSCV.h:48
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
LSCVParams(const AMParams *am_params, int _sub_regions_x, int _sub_regions_y, int _spacing_x, int _spacing_y, bool _affine_mapping, bool _once_per_frame, int _n_bins, double _pre_seed, bool _weighted_mapping, bool _show_subregions, bool _approx_dist_feat)
value constructor
int n_bins
no. of bins in the histograms
Definition: LSCV.h:20
bool weighted_mapping
enable this to map each intensity to the weighted average of the two entries of the intensity map cor...
Definition: LSCV.h:28
int spacing_x
spacing in pixels between adjacent sub regions
Definition: LSCV.h:13
MatrixXd curr_joint_hist
n_bins x n_bins joint histograms;
Definition: LSCV.h:107
double pre_seed
initial value with which each bin of the joint histogram is pre-seeded to avoid numerical instabiliti...
Definition: LSCV.h:23