MTF
SAD.h
1 #ifndef MTF_SAD_H
2 #define MTF_SAD_H
3 
4 #include "AppearanceModel.h"
5 
6 _MTF_BEGIN_NAMESPACE
7 
8 struct SADDist : AMDist{
9  typedef bool is_kdtree_distance;
10  typedef double ElementType;
11  typedef double ResultType;
12  SADDist(const string &_name) : AMDist(_name){}
13  double operator()(const double* a, const double* b,
14  size_t size, double worst_dist = -1) const override;
15  double accum_dist(const double& a, const double& b, int) const{
16  return fabs(a - b);
17  }
18 };
19 
24 class SAD : public AppearanceModel{
25 
26 public:
27  typedef AMParams ParamType;
28  typedef SADDist DistType;
29 
30  SAD(const AMParams *am_params = nullptr,
31  const int _n_channels = 1);
32  void initializeSimilarity() override;
33 
34  double getLikelihood() const override;
35  //-----------------------------------------------------------------------------------//
36  //-------------------------------update functions------------------------------------//
37  //-----------------------------------------------------------------------------------//
38  void updateSimilarity(bool prereq_only = true) override;
39 
43  const DistType* getDistFunc() override{
44  return new DistType(name);
45  }
46  void updateDistFeat(double* feat_addr) override{
47  for(size_t pix = 0; pix < feat_size; ++pix) {
48  *feat_addr++ = It(pix);
49  }
50  }
51  void initializeDistFeat() override{}
52  void updateDistFeat() override{}
53  const double* getDistFeat() override{ return It.data(); }
54  unsigned int getDistFeatSize() override{ return feat_size; }
55 
56 protected:
57  double likelihood_alpha;
58  unsigned int feat_size;
59 };
60 
61 _MTF_END_NAMESPACE
62 
63 #endif
Definition: SAD.h:8
void updateDistFeat() override
computes a "distance" vector using the current image patch such that, when the distance vectors corre...
Definition: SAD.h:52
double operator()(const double *a, const double *b, size_t size, double worst_dist=-1) const override
computes the distance / dissimilarity between two patches where each is codified or represented by a ...
Definition: AMParams.h:12
Distance functor for FLANN.
Definition: AppearanceModel.h:40
const DistType * getDistFunc() override
Support for FLANN library.
Definition: SAD.h:43
unsigned int getDistFeatSize() override
returns the size of the distance vector
Definition: SAD.h:54
void initializeDistFeat() override
to be called once during initialization if any of the distance feature functionality is to be used ...
Definition: SAD.h:51
Similarity function that indicates how well a candidate warped patch matches the template.
Definition: AppearanceModel.h:63
void updateDistFeat(double *feat_addr) override
overloaded version to write the distance feature directly to a row (or column) of a matrix storing th...
Definition: SAD.h:46
Sum of Absolute Differences or L1 norm of raw pixel values This is not differentiable so the derivati...
Definition: SAD.h:24