PICCANTE  0.4
The hottest HDR imaging library!
image_sampler_bilinear.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_BILINEAR_HPP
19 #define PIC_IMAGE_SAMPLERS_IMAGE_SAMPLER_BILINEAR_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  x = CLAMPi(x, 0.0f, 1.0f);
45  y = CLAMPi(y, 0.0f, 1.0f);
46 
47  //Coordiantes in [0,width-1]x[0,height-1]
48  x *= img->width1f;
49  y *= img->height1f;
50  SampleImageUC(img, x, y, vOut);
51  }
52 
60  void SampleImageUC(Image *img, float x, float y, float *vOut)
61  {
62  float xx, yy, dx, dy;
63  int ind0, ind1, ind2, ind3;
64 
65  //Coordinates without fractions
66  xx = floorf(x);
67  yy = floorf(y);
68 
69  //Interpolation values
70  dx = (x - xx);
71  dy = (y - yy);
72 
73  //Integer coordinates
74  int ix = int(xx);
75  int iy = int(yy);
76  int ix1 = CLAMP(ix + 1, img->width);
77  int iy1 = CLAMP(iy + 1, img->height);
78 
79  //Bilinear interpolation indicies
80  int t0 = iy * img->width;
81  int t1 = iy1 * img->width;
82 
83  ind0 = (ix + t0) * img->channels;
84  ind1 = (ix1 + t0) * img->channels;
85  ind2 = (ix + t1) * img->channels;
86  ind3 = (ix1 + t1) * img->channels;
87 
88  for(int i = 0; i < img->channels; i++) {
89  vOut[i] = Bilinear<float>(img->data[ind0 + i],
90  img->data[ind1 + i],
91  img->data[ind2 + i],
92  img->data[ind3 + i],
93  dx, dy);
94  }
95  }
96 
105  void SampleImage(Image *img, float x, float y, float t, float *vOut)
106  {
107  /* float tmp = y;
108  y = t;
109  t = tmp;*/
110 
111  x = CLAMPi(x, 0.0f, 1.0f);
112  y = CLAMPi(y, 0.0f, 1.0f);
113  t = CLAMPi(t, 0.0f, 1.0f);
114 
115  x *= img->width1f;
116  y *= img->height1f;
117  t *= img->frames1f;
118 
119  float pOut2x = floorf(x);
120  float pOut2y = floorf(y);
121  float pOut2z = floorf(t);
122 
123  float deltax = x - pOut2x;
124  float deltay = y - pOut2y;
125  float deltaz = t - pOut2z;
126 
127  //Integer coordinates
128  int ix = int(pOut2x);
129  int iy = int(pOut2y);
130  int iz = int(pOut2z);
131 
132  int ix1 = (ix + 1) % img->width;
133  int iy1 = (iy + 1) % img->height;
134  int iz1 = (iz + 1) % img->frames;
135 
136  float val[2];
137 
138  for(int i = 0; i < img->channels; i++) {
139  val[0] = Bilinear<float>(
140  *((*img)(ix, iy, iz) + i),
141  *((*img)(ix1, iy, iz) + i),
142  *((*img)(ix, iy, iz1) + i),
143  *((*img)(ix1, iy, iz1) + i),
144  deltax, deltaz);
145 
146  val[1] = Bilinear<float>(
147  *((*img)(ix, iy1, iz) + i),
148  *((*img)(ix1, iy1, iz) + i),
149  *((*img)(ix, iy1, iz1) + i),
150  *((*img)(ix1, iy1, iz1) + i),
151  deltax, deltaz);
152 
153  vOut[i] = val[0] + deltay * (val[1] - val[0]);
154  }
155  }
156 };
157 
158 } // end namespace pic
159 
160 #endif /* PIC_IMAGE_SAMPLERS_IMAGE_SAMPLER_BILINEAR_HPP */
161 
float * data
data is the main buffer where pixel values are stored.
Definition: image.hpp:91
int channels
Definition: image.hpp:80
void SampleImageUC(Image *img, float x, float y, float *vOut)
SampleImageUC samples an image in unnormalized coordinates [0,width-1]x[0,height-1].
Definition: image_sampler_bilinear.hpp:60
The ImageSampler class.
Definition: image_sampler.hpp:29
int frames
Definition: image.hpp:80
float height1f
Definition: image.hpp:84
void SampleImage(Image *img, float x, float y, float *vOut)
SampleImage samples an image in normalized coordiantes (0,1).
Definition: image_sampler_bilinear.hpp:42
The Image class stores an image as buffer of float.
Definition: image.hpp:60
#define CLAMPi(x, a, b)
Definition: math.hpp:81
Definition: bilateral_separation.hpp:25
#define CLAMP(x, a)
Definition: math.hpp:77
int width
Definition: image.hpp:80
void SampleImage(Image *img, float x, float y, float t, float *vOut)
SampleImage samples an image in uniform coordiantes.
Definition: image_sampler_bilinear.hpp:105
The ImageSamplerBilinear class.
Definition: image_sampler_bilinear.hpp:28
int height
Definition: image.hpp:80
float frames1f
Definition: image.hpp:84
ImageSamplerBilinear()
Definition: image_sampler_bilinear.hpp:31
float width1f
Definition: image.hpp:84