PICCANTE  0.4
The hottest HDR imaging library!
precomputed_gaussian.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_UTIL_PRECOMPUTED_GAUSSIAN_HPP
19 #define PIC_UTIL_PRECOMPUTED_GAUSSIAN_HPP
20 
21 namespace pic {
22 
23 #include <math.h>
24 
25 #include "../util/array.hpp"
26 
31 {
32 protected:
37  {
39  kernelSize = (halfKernelSize << 1) + 1;
40 
41  if(coeff != NULL) {
42  delete[] coeff;
43  coeff = NULL;
44  }
45 
46  coeff = new float[kernelSize];
47 
48  float sigma_sq_2 = (2.0f * sigma * sigma);
49 
50  float sum = 0.0f;
51  for(int i = 0; i < kernelSize; i++) {
52  int i_s = i - halfKernelSize;
53  i_s *= i_s;
54  coeff[i] = expf(-float(i_s) / sigma_sq_2);
55  sum += coeff[i];
56  }
57 
58  //normalize the kernel
59  if(sum > 0.0f) {
61  }
62  }
63 
64 public:
65  float sigma;
67  float *coeff;
68 
73  {
75  sigma = 0.0f;
76  coeff = NULL;
77  }
78 
84  {
85  coeff = NULL;
87  }
88 
90  {
91  if(coeff != NULL) {
92  delete[] coeff;
93  coeff = NULL;
94  }
95  }
96 
101  void calculateKernel(float sigma, int kernelSize = -1)
102  {
103  this->sigma = sigma;
104 
105  //the sigma for the size of the kernel
106  if(kernelSize < 3) {
107  this->kernelSize = PrecomputedGaussian::getKernelSize(sigma);
108  } else {
109  this->kernelSize = kernelSize;
110  }
111 
112  //precompute Gaussian coefficients
114  }
115 
121  static int getKernelSize(float sigma)
122  {
123  int kernelSize = int(ceilf(sigma * 5.0f));
124  return (kernelSize > 3) ? kernelSize : 3;
125  }
126 };
127 
128 } // end namespace pic
129 
130 #endif /* PIC_UTIL_PRECOMPUTED_GAUSSIAN_HPP */
131 
static int getKernelSize(float sigma)
KernelSize computes the size of a kernel in pixel give its sigma.
Definition: precomputed_gaussian.hpp:121
float * coeff
Definition: precomputed_gaussian.hpp:67
~PrecomputedGaussian()
Definition: precomputed_gaussian.hpp:89
PrecomputedGaussian()
PrecomputedGaussian.
Definition: precomputed_gaussian.hpp:72
PrecomputedGaussian(float sigma)
PrecomputedGaussian.
Definition: precomputed_gaussian.hpp:83
void calculateKernel(float sigma, int kernelSize=-1)
calculateKernel computes a Gaussian kernel of size sigma
Definition: precomputed_gaussian.hpp:101
static void div(T *data, int size, T value)
div
Definition: array.hpp:353
The PrecomputedGaussian class.
Definition: precomputed_gaussian.hpp:30
int halfKernelSize
Definition: precomputed_gaussian.hpp:66
int kernelSize
Definition: precomputed_gaussian.hpp:66
void precomputeCoefficients()
precomputeCoefficients precomputes a Gaussian kernel.
Definition: precomputed_gaussian.hpp:36
Definition: bilateral_separation.hpp:25
float sigma
Definition: precomputed_gaussian.hpp:65