PICCANTE  0.4
The hottest HDR imaging library!
image_sampler_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_IMAGE_SAMPLERS_IMAGE_SAMPLER_GAUSSIAN_HPP
19 #define PIC_IMAGE_SAMPLERS_IMAGE_SAMPLER_GAUSSIAN_HPP
20 
21 #include "../image_samplers/image_sampler.hpp"
22 #include "../util/precomputed_gaussian.hpp"
23 
24 namespace pic {
25 
30 {
31 protected:
33 
34 public:
39  {
40  pg = NULL;
41  }
42 
48  ImageSamplerGaussian(float sigma, unsigned int direction)
49  {
50  update(sigma, direction);
51  }
52 
58  void update(float sigma, unsigned int direction)
59  {
60  if(pg != NULL) {
61  delete pg;
62  pg = NULL;
63  }
64 
65  pg = new PrecomputedGaussian(sigma);
66 
67  SetDirection(direction);
68  }
69 
77  void SampleImage(Image *img, float x, float y, float *vOut)
78  {
79  for(int k = 0; k < img->channels; k++) {
80  vOut[k] = 0.0f;
81  }
82 
83  int ix = int(x * img->widthf);
84  int iy = int(y * img->heightf);
85 
86  for(int i = 0; i < pg->kernelSize ; i++) {
87  int ex = CLAMP(ix + i * dirs[0], img->width);
88  int ey = CLAMP(iy + i * dirs[1], img->height);
89 
90  int ind = (ey * img->width + ex) * img->channels;
91 
92  for(int k = 0; k < img->channels; k++) {
93  vOut[k] += img->data[ind] * pg->coeff[i];
94  ind++;
95  }
96  }
97  }
98 };
99 
100 } // end namespace pic
101 
102 #endif /* PIC_IMAGE_SAMPLERS_IMAGE_SAMPLER_GAUSSIAN_HPP */
103 
PrecomputedGaussian * pg
Definition: image_sampler_gaussian.hpp:32
float * data
data is the main buffer where pixel values are stored.
Definition: image.hpp:91
int channels
Definition: image.hpp:80
The ImageSampler class.
Definition: image_sampler.hpp:29
float heightf
Definition: image.hpp:84
ImageSamplerGaussian()
ImageSamplerGaussian.
Definition: image_sampler_gaussian.hpp:38
float * coeff
Definition: precomputed_gaussian.hpp:67
The ImageSamplerGaussian class.
Definition: image_sampler_gaussian.hpp:29
float widthf
Definition: image.hpp:84
ImageSamplerGaussian(float sigma, unsigned int direction)
ImageSamplerGaussian.
Definition: image_sampler_gaussian.hpp:48
The Image class stores an image as buffer of float.
Definition: image.hpp:60
The PrecomputedGaussian class.
Definition: precomputed_gaussian.hpp:30
int kernelSize
Definition: precomputed_gaussian.hpp:66
Definition: bilateral_separation.hpp:25
void update(float sigma, unsigned int direction)
update
Definition: image_sampler_gaussian.hpp:58
#define CLAMP(x, a)
Definition: math.hpp:77
int width
Definition: image.hpp:80
int height
Definition: image.hpp:80
void SampleImage(Image *img, float x, float y, float *vOut)
SampleImage samples an image in uniform coordiantes.
Definition: image_sampler_gaussian.hpp:77
void SetDirection(unsigned int direction)
Definition: display.hpp:43
int dirs[3]
Definition: display.hpp:32