PICCANTE  0.4
The hottest HDR imaging library!
filter_guided.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_FILTERING_FILTER_GUIDED_HPP
19 #define PIC_FILTERING_FILTER_GUIDED_HPP
20 
21 #include "../filtering/filter.hpp"
22 
23 #include "../util/array.hpp"
24 
25 #include "../util/matrix_3_x_3.hpp"
26 
27 #include "../filtering/filter_guided_a_b.hpp"
28 
29 #include "../util/math.hpp"
30 
31 namespace pic {
32 
36 class FilterGuided: public Filter
37 {
38 protected:
39 
40  int radius;
43 
45 
53  void Process1Channel(Image *I, Image *p, Image *q, BBox *box);
54 
62  void Process3Channel(Image *I, Image *p, Image *q, BBox *box);
63 
70  void ProcessBBox(Image *dst, ImageVec src, BBox *box);
71 
72 public:
73 
78  {
79  update(5, 0.01f);
80  }
81 
88  {
90  }
91 
97  void update(int radius, float e_regularization);
98 
105  Image *Process(ImageVec imgIn, Image *imgOut);
106 
116  static Image *execute(Image *imgIn, Image *guide, Image *imgOut,
117  int radius, float e_regularization)
118  {
120  return filter.Process(Double(imgIn, guide), imgOut);
121  }
122 };
123 
124 PIC_INLINE void FilterGuided::update(int radius, float e_regularization)
125 {
126  img_a_b = NULL;
127 
128  this->radius = radius;
129  this->e_regularization = e_regularization;
130  nPixels = float(radius * radius * 4);
131 
133 }
134 
136  BBox *box)
137 {
138  float *a_b_mean = new float[img_a_b->channels];
139 
140  for(int j = box->y0; j < box->y1; j++) {
141  for(int i = box->x0; i < box->x1; i++) {
142  float *tmpQ = (*q)(i, j);
143  float *tmpI = (*I)(i, j);
144 
145  BBox tmpBox(i - radius, i + radius, j - radius, j + radius);
146  img_a_b->getMeanVal(&tmpBox, a_b_mean);
147 
148  for(int c = 0; c < p->channels; c++) {
149  int index = c << 1;
150  float a = a_b_mean[index];
151  float b = a_b_mean[index + 1];
152  tmpQ[c] = a * tmpI[0] + b;
153  }
154  }
155  }
156 
157  delete[] a_b_mean;
158 }
159 
161  Image *q, BBox *box)
162 {
163  float *a_b_mean = new float[img_a_b->channels];
164 
165  int shift = I->channels + 1;
166 
167  for(int j = box->y0; j < box->y1; j++) {
168  for(int i = box->x0; i < box->x1; i++) {
169  float *tmpQ = (*q)(i, j);
170  float *tmpI = (*I)(i, j);
171 
172  BBox tmpBox(i - radius, i + radius, j - radius, j + radius);
173  img_a_b->getMeanVal(&tmpBox, a_b_mean);
174 
175  for(int c = 0; c < p->channels; c++) {
176 
177  int index = c * shift;
178  float *a = &a_b_mean[index];
179  float b = a_b_mean[index + I->channels];
180 
181  float a_dot_I = Array<float>::dot(a, tmpI, I->channels);
182 
183  tmpQ[c] = a_dot_I + b;
184  }
185 
186  }
187  }
188  delete[] a_b_mean;
189 }
190 
192  BBox *box)
193 {
194  Image *I, *p;
195 
196  if(src.size() == 2) {
197  p = src[0];
198 
199  if(src[1] != NULL) {
200  I = src[1];
201  } else {
202  I = src[0];
203  }
204  } else {
205  I = src[0];
206  p = src[0];
207  }
208 
209  if(I->channels == 3) {
210  Process3Channel(I, p, dst, box);
211  } else {
212  Process1Channel(I, p, dst, box);
213  }
214 }
215 
217 {
218  if(!checkInput(imgIn)) {
219  return imgOut;
220  }
221 
222  imgOut = setupAux(imgIn, imgOut);
223 
224  if(imgOut == NULL) {
225  return imgOut;
226  }
227 
228  img_a_b = flt.Process(imgIn, img_a_b);
229 
230  return ProcessP(imgIn, imgOut);
231 }
232 
233 } // end namespace pic
234 
235 #endif /* PIC_FILTERING_FILTER_GUIDED_HPP */
236 
The BBox class manages the creation of bounding boxes for images.
Definition: bbox.hpp:29
int channels
Definition: image.hpp:80
int radius
Definition: filter_guided.hpp:40
std::vector< Image * > ImageVec
ImageVec an std::vector of pic::Image.
Definition: image_vec.hpp:29
int x0
Definition: bbox.hpp:32
float * getMeanVal(BBox *box, float *ret)
getMeanVal computes the mean for the current Image.
The Filter class.
Definition: filter.hpp:50
float nPixels
Definition: filter_guided.hpp:41
virtual Image * Process(ImageVec imgIn, Image *imgOut)
Process.
Definition: filter.hpp:390
Image * ProcessP(ImageVec imgIn, Image *imgOut)
ProcessP.
Definition: filter.hpp:353
float e_regularization
Definition: filter_guided.hpp:41
int y0
Definition: bbox.hpp:32
void ProcessBBox(Image *dst, ImageVec src, BBox *box)
ProcessBBox.
Definition: filter_guided.hpp:191
FilterGuidedAB flt
Definition: filter_guided.hpp:44
FilterGuided()
FilterGuided.
Definition: filter_guided.hpp:77
The FilterGuided class.
Definition: filter_guided.hpp:36
PIC_INLINE ImageVec Double(Image *img1, Image *img2)
Double creates an std::vector which contains img1 and img2; this is for filters input.
Definition: image_vec.hpp:49
void update(int radius, float e_regularization)
update
Definition: filter_guided.hpp:124
#define PIC_INLINE
Definition: base.hpp:33
The FilterGuidedAB class.
Definition: filter_guided_a_b.hpp:34
void update(int radius, float e_regularization)
update
Definition: filter_guided_a_b.hpp:165
static T dot(T *data0, T *data1, int n)
dot
Definition: array.hpp:281
The Image class stores an image as buffer of float.
Definition: image.hpp:60
static Image * execute(Image *imgIn, Image *guide, Image *imgOut, int radius, float e_regularization)
execute
Definition: filter_guided.hpp:116
virtual void f(FilterFData *data)
f
Definition: filter_radial_basis_function.hpp:69
Definition: bilateral_separation.hpp:25
Image * Process(ImageVec imgIn, Image *imgOut)
FilterGuided::Process.
Definition: filter_guided.hpp:216
void Process3Channel(Image *I, Image *p, Image *q, BBox *box)
Process3Channel.
Definition: filter_guided.hpp:160
virtual Image * setupAux(ImageVec imgIn, Image *imgOut)
setupAux
Definition: filter.hpp:288
Image * img_a_b
Definition: filter_guided.hpp:42
bool checkInput(ImageVec &imgIn)
checkInput
Definition: filter.hpp:385
FilterGuided(int radius, float e_regularization)
FilterGuided.
Definition: filter_guided.hpp:87
void Process1Channel(Image *I, Image *p, Image *q, BBox *box)
Process1Channel.
Definition: filter_guided.hpp:135