PICCANTE  0.4
The hottest HDR imaging library!
image_sampler_bsplines.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_BSPLINES_HPP
19 #define PIC_IMAGE_SAMPLERS_IMAGE_SAMPLER_BSPLINES_HPP
20 
21 #include "../image_samplers/image_sampler.hpp"
22 
23 namespace pic {
24 
29 {
30 public:
32  {
33  }
34 
42  void SampleImage(Image *img, float x, float y, float *vOut)
43  {
44  //TODO: there's a reason for this, but I don't know it now
45  // x = CLAMPi(x, 0.0f, 1.0f);
46  // y = CLAMPi(y, 0.0f, 1.0f);
47 
48  float xx, yy, dx, dy;
49 
50  //Coordiantes in [0,width-1]x[0,height-1]
51  x *= img->width1f;
52  y *= img->height1f;
53 
54  //Coordinates without fractions
55  xx = floorf(x);
56  yy = floorf(y);
57 
58  //Interpolation values
59  dx = (x - xx);
60  dy = (y - yy);
61 
62  //Integer coordinates
63  int ix = int(xx);
64  int iy = int(yy);
65 
66  for(int k = 0; k < img->channels; k++) {
67  vOut[k] = 0.0f;
68  }
69 
70  //BSplines interpolation
71  float rx, ry;
72  int ey, ex;
73  for(int j = -1; j < 3; j++) {
74  ry = Rx(float(j) - dy);
75  ey = CLAMP(iy + j, img->height);
76 
77  for(int i = -1; i < 3; i++) {
78  rx = Rx(float(i) - dx) * ry;
79  ex = CLAMP(ix + i, img->width);
80  int ind = (ey * img->width + ex) * img->channels;
81 
82  for(int k = 0; k < img->channels; k++) {
83  vOut[k] += img->data[ind + k] * rx;
84  }
85  }
86  }
87  }
88 };
89 
90 } // end namespace pic
91 
92 #endif /* PIC_IMAGE_SAMPLERS_IMAGE_SAMPLER_BSPLINES_HPP */
93 
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
void SampleImage(Image *img, float x, float y, float *vOut)
SampleImage samples an image in uniform coordiantes.
Definition: image_sampler_bsplines.hpp:42
float Rx(float x)
Rx evaluates B-spline (cubic).
Definition: image_sampler.hpp:80
The ImageSamplerBSplines class.
Definition: image_sampler_bsplines.hpp:28
float height1f
Definition: image.hpp:84
The Image class stores an image as buffer of float.
Definition: image.hpp:60
Definition: bilateral_separation.hpp:25
#define CLAMP(x, a)
Definition: math.hpp:77
ImageSamplerBSplines()
Definition: image_sampler_bsplines.hpp:31
int width
Definition: image.hpp:80
int height
Definition: image.hpp:80
float width1f
Definition: image.hpp:84