PICCANTE  0.4
The hottest HDR imaging library!
poisson_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_POISSON_DESCRIPTOR_HPP
19 #define PIC_FEATURES_MATCHING_POISSON_DESCRIPTOR_HPP
20 
21 #include <random>
22 #include "../util/math.hpp"
23 #include "../image.hpp"
24 #include "../point_samplers/sampler_random.hpp"
25 
26 namespace pic {
27 
32 {
33 protected:
35  unsigned int subBlock;
36  std::mt19937 *m;
37 
39 
44  void generateSamples(unsigned int kernelSize)
45  {
47  nSamples = rs->samplesR.size() >> 1;
48  }
49 
58  unsigned int *getAux(Image *img, int x0, int y0, unsigned int *desc = NULL)
59  {
60  unsigned int bits = sizeof(unsigned int) * 8;
61  subBlock = (nSamples * (nSamples - 1)) / bits;
62 
63  if(desc == NULL) {
64  desc = new unsigned int[subBlock];
65  memset(desc, 0, sizeof(unsigned int) * subBlock);
66  }
67 
68  int x[2], y[2];
69 
70  int c = 0;
71  for(int i = 0; i < nSamples; i++) {
72  x[0] = rs->samplesR[(i << 1)];
73  x[1] = rs->samplesR[(i << 1) + 1];
74 
75  for(int j = 0; j < nSamples; j++) {
76  if(i == j) {
77  continue;
78  }
79 
80  y[0] = rs->samplesR[(j << 1)];
81  y[1] = rs->samplesR[(j << 1) + 1];
82 
83  float *p_x_val = (*img)(x0 + x[0], y0 + x[1]);
84  float *p_y_val = (*img)(x0 + y[0], y0 + y[1]);
85 
86  float p_x = 0.0f;
87  float p_y = 0.0f;
88 
89  for(int k = 0; k < img->channels; k++) {
90  p_x += p_x_val[k];
91  p_y += p_y_val[k];
92  }
93 
94  int p = c / bits;
95  int shift = c % bits;
96 
97  unsigned int ret = (p_x < p_y) ? 1 : 0;
98  desc[p] += (ret << shift);
99  c++;
100 
101  }
102 
103  }
104 
105  return desc;
106  }
107 
108 public:
109 
114  PoissonDescriptor(int kernelSize = 16, unsigned int seed = 1)
115  {
116  subBlock = 0;
117  m = new std::mt19937(seed);
118 
120  }
121 
123  {
124  release();
125  }
126 
130  void release()
131  {
132 
133  if(m != NULL) {
134  delete m;
135  m = NULL;
136  }
137  }
138 
147  unsigned int *get(Image *img, int x0, int y0, unsigned int *desc = NULL)
148  {
149  if(img == NULL) {
150  return NULL;
151  }
152 
153  if(!img->checkCoordinates(x0, y0)) {
154  return NULL;
155  }
156 
157  return getAux(img, x0, y0, desc);
158  }
159 
165  {
166  return subBlock;
167  }
168 
169 };
170 
171 } // end namespace pic
172 
173 #endif /* PIC_FEATURES_MATCHING_BRIEF_DESCRIPTOR_HPP */
174 
~PoissonDescriptor()
Definition: poisson_descriptor.hpp:122
int getDescriptorSize()
getDescriptorSize returns the descriptor size.
Definition: poisson_descriptor.hpp:164
int channels
Definition: image.hpp:80
RandomSampler< 2 > * rs
Definition: poisson_descriptor.hpp:38
void release()
release deallocates memory.
Definition: poisson_descriptor.hpp:130
void generateSamples(unsigned int kernelSize)
generateSamples
Definition: poisson_descriptor.hpp:44
int kernelSize
Definition: poisson_descriptor.hpp:34
unsigned int * getAux(Image *img, int x0, int y0, unsigned int *desc=NULL)
getAux computes a descriptor at position (x0,y0) with size n.
Definition: poisson_descriptor.hpp:58
std::vector< int > samplesR
Definition: display.hpp:53
std::mt19937 * m
Definition: poisson_descriptor.hpp:36
The PoissonDescriptor class.
Definition: poisson_descriptor.hpp:31
The Image class stores an image as buffer of float.
Definition: image.hpp:60
int nSamples
Definition: poisson_descriptor.hpp:34
Definition: point_samplers.hpp:51
unsigned int subBlock
Definition: poisson_descriptor.hpp:35
Definition: bilateral_separation.hpp:25
PoissonDescriptor(int kernelSize=16, unsigned int seed=1)
PoissonDescriptor.
Definition: poisson_descriptor.hpp:114
The RandomSampler class.
Definition: sampler_random.hpp:43