PICCANTE  0.4
The hottest HDR imaging library!
lucid_descriptor.hpp
Go to the documentation of this file.
1 /*
2 
3 PICCANTE
4 The hottest HDR imaging library!
5 http://vcg.isti.cnr.it/piccante
6 
7 Copyright (C) 2014
8 Visual Computing Laboratory - ISTI CNR
9 http://vcg.isti.cnr.it
10 First author: Francesco Banterle
11 
12 This Source Code Form is subject to the terms of the Mozilla Public
13 License, v. 2.0. If a copy of the MPL was not distributed with this
14 file, You can obtain one at http://mozilla.org/MPL/2.0/.
15 
16 */
17 
18 #ifndef PIC_FEATURES_MATCHING_LUCID_DESCRIPTOR_HPP
19 #define PIC_FEATURES_MATCHING_LUCID_DESCRIPTOR_HPP
20 
21 #include "../util/math.hpp"
22 #include "../image.hpp"
23 
24 namespace pic {
25 
30 {
31 protected:
33  int area;
34 
35 public:
36 
42  {
43  if(patchSize < 2) {
44  patchSize = 31;
45  }
46 
47  this->patchSize = patchSize;
48  this->halfPatchSize = patchSize >> 1;
49 
50  int tmp = (halfPatchSize << 1 ) + 1;
51  area = tmp * tmp;
52  }
53 
63  unsigned int *get(Image *img, int x0, int y0, unsigned int *desc, unsigned int &nDesc)
64  {
65  if(img == NULL) {
66  return NULL;
67  }
68 
69  nDesc = area * img->channels;
70 
71  if(desc == NULL) {
72  desc = new unsigned int[nDesc];
73  }
74 
75  std::vector< std::pair<float, unsigned int> > data;
76 
77 
78  for(int k = 0; k < img->channels; k++) {
79  for(int i = -halfPatchSize; i <= halfPatchSize; i++) {
80  int y = y0 + i;
81 
82  for(int j = -halfPatchSize; j <= halfPatchSize; j++) {
83  int x = x0 + j;
84 
85  float *tmp_val = (*img)(x, y);
86 
87  float f = tmp_val[k];
88  int s = int(data.size());
89 
90  std::pair<float, int> pair = std::make_pair(f, s);
91  data.push_back(pair);
92  }
93  }
94  }
95 
96  std::sort(data.begin(), data.end());
97 
98  for(unsigned int i = 0; i < data.size(); i++) {
99  desc[i] = data[i].second;
100  }
101 
102  return desc;
103  }
104 
112  static unsigned int match(unsigned int *fv0, unsigned int *fv1, unsigned int nfv)
113  {
114  if((fv0 == NULL) && (fv1 == NULL)) {
115  return 0;
116  }
117 
118  unsigned int ret = 0;
119 
120  for(unsigned int i = 0; i < nfv; i++) {
121  ret += (fv0[i] == fv1[i]) ? 1 : 0;
122  }
123 
124  return ret;
125  }
126 };
127 
128 } // end namespace pic
129 
130 #endif /* PIC_FEATURES_MATCHING_LUCID_DESCRIPTOR_HPP */
131 
LUCIDDescriptor(int patchSize=31)
LUCIDDescriptor.
Definition: lucid_descriptor.hpp:41
int halfPatchSize
Definition: lucid_descriptor.hpp:32
int area
Definition: lucid_descriptor.hpp:33
int patchSize
Definition: lucid_descriptor.hpp:32
The LUCIDDescriptor class.
Definition: lucid_descriptor.hpp:29
The Image class stores an image as buffer of float.
Definition: image.hpp:60
Definition: bilateral_separation.hpp:25
static unsigned int match(unsigned int *fv0, unsigned int *fv1, unsigned int nfv)
match matches two descriptors. Note: higher scores means better matching.
Definition: lucid_descriptor.hpp:112