PICCANTE  0.4
The hottest HDR imaging library!
filter_downsampler_2d.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_DOWNSAMPLER_2D_HPP
19 #define PIC_FILTERING_FILTER_DOWNSAMPLER_2D_HPP
20 
21 #include "../util/std_util.hpp"
22 #include "../filtering/filter_npasses.hpp"
23 #include "../filtering/filter_sampler_1d.hpp"
24 #include "../image_samplers/image_sampler_nearest.hpp"
25 #include "../image_samplers/image_sampler_gaussian.hpp"
26 
27 namespace pic {
28 
33 {
34 protected:
37 
38  bool swh;
39  float scale[2];
40  int width, height;
41 
45  void allocate()
46  {
47  for(int i = 0; i < 2; i++) {
48  if(isg[i] == NULL) {
49  isg[i] = new ImageSamplerGaussian();
50  }
51 
52  if(flt[i] == NULL) {
53  flt[i] = new FilterSampler1D(scale[i], i, isg[i]);
54  } else {
55  flt[i]->update(scale[i], i, isg[i]);
56  }
57 
58  insertFilter(flt[i]);
59  }
60  }
61 
62 public:
63 
69  FilterDownSampler2D(float scaleX, float scaleY);
70 
77 
79 
83  void release();
84 
90  void PreProcess(ImageVec imgIn, Image *imgOut);
91 
100  static Image *execute(Image *imgIn, Image *imgOut, int width,
101  int height)
102  {
104  return flt.Process(Single(imgIn), imgOut);
105  }
106 
115  static Image *execute(Image *imgIn, Image *imgOut, float scaleX,
116  float scaleY)
117  {
118  FilterDownSampler2D flt(scaleX, scaleY);
119  return flt.Process(Single(imgIn), imgOut);
120  }
121 
129  static Image *execute(Image *imgIn, Image *imgOut, float scaleXY)
130  {
131  FilterDownSampler2D flt(scaleXY, scaleXY);
132  return flt.Process(Single(imgIn), imgOut);
133  }
134 };
135 
137 {
138  for(int i = 0; i < 2; i++) {
139  this->isg[i] = NULL;
140  this->flt[i] = NULL;
141  this->scale[i] = 1.0f;
142  }
143 
144  if(scaleX > 0.0f) {
145  this->scale[0] = scaleX;
146  this->scale[1] = scaleY > 0.0f ? scaleY : scaleX;
147  }
148 
149  width = -1;
150  height = -1;
151 
152  allocate();
153 
154  swh = true;
155 }
156 
158 {
159  for(int i = 0; i < 2; i++) {
160  this->isg[i] = NULL;
161  this->flt[i] = NULL;
162  this->scale[i] = 1.0f;
163  }
164 
165  if(width > 0) {
166  this->width = width;
167  }
168 
169  if(height > 0) {
170  this->height = height;
171  }
172 
173  allocate();
174 
175  swh = (width < 1 || height < 1);
176 }
177 
179 {
180  release();
181 }
182 
184 {
185  for (int i = 0; i < 2; i++) {
186  flt[i] = delete_s(flt[i]);
187  isg[i] = delete_s(isg[i]);
188  }
189 }
190 
192  Image *imgOut)
193 {
194  if(!swh) {
195  scale[0] = float(width) / imgIn[0]->widthf;
196  scale[1] = float(height) / imgIn[0]->heightf;
197  }
198 
199  for(int i = 0; i < 2; i++) {
200  isg[i]->update(1.0f / (5.0f * scale[i]), i);
201  flt[i]->update(scale[i], i, isg[i]);
202  }
203 
204 }
205 
206 } // end namespace pic
207 
208 #endif /* PIC_FILTERING_FILTER_DOWNSAMPLER_2D_HPP */
209 
The FilterSampler1D class.
Definition: filter_sampler_1d.hpp:36
void update(float scale, int direction, ImageSampler *isb)
update
Definition: filter_sampler_1d.hpp:154
void release()
release
Definition: filter_downsampler_2d.hpp:183
T * delete_s(T *data)
delete_s
Definition: std_util.hpp:123
std::vector< Image * > ImageVec
ImageVec an std::vector of pic::Image.
Definition: image_vec.hpp:29
void insertFilter(Filter *flt, bool asSingle=false)
insertFilter
Definition: filter_radial_basis_function.hpp:246
static Image * execute(Image *imgIn, Image *imgOut, float scaleXY)
execute
Definition: filter_downsampler_2d.hpp:129
int width
Definition: filter_downsampler_2d.hpp:40
FilterDownSampler2D(float scaleX, float scaleY)
FilterDownSampler2D.
Definition: filter_downsampler_2d.hpp:136
ImageSamplerGaussian * isg[2]
Definition: filter_downsampler_2d.hpp:35
virtual Image * Process(ImageVec imgIn, Image *imgOut)
Process.
Definition: filter.hpp:390
The FilterDownSampler2D class.
Definition: filter_downsampler_2d.hpp:32
~FilterDownSampler2D()
Definition: filter_downsampler_2d.hpp:178
void PreProcess(ImageVec imgIn, Image *imgOut)
PreProcess.
Definition: filter_downsampler_2d.hpp:191
static Image * execute(Image *imgIn, Image *imgOut, int width, int height)
execute
Definition: filter_downsampler_2d.hpp:100
FilterSampler1D * flt[2]
Definition: filter_downsampler_2d.hpp:36
The ImageSamplerGaussian class.
Definition: image_sampler_gaussian.hpp:29
#define PIC_INLINE
Definition: base.hpp:33
int height
Definition: filter_downsampler_2d.hpp:40
The Image class stores an image as buffer of float.
Definition: image.hpp:60
static Image * execute(Image *imgIn, Image *imgOut, float scaleX, float scaleY)
execute
Definition: filter_downsampler_2d.hpp:115
float scale[2]
Definition: filter_downsampler_2d.hpp:39
virtual void f(FilterFData *data)
f
Definition: filter_radial_basis_function.hpp:69
bool swh
Definition: filter_downsampler_2d.hpp:38
PIC_INLINE ImageVec Single(Image *img)
Single creates an std::vector which contains img; this is for filters input.
Definition: image_vec.hpp:36
Definition: bilateral_separation.hpp:25
void update(float sigma, unsigned int direction)
update
Definition: image_sampler_gaussian.hpp:58
void allocate()
allocate
Definition: filter_downsampler_2d.hpp:45
The FilterNPasses class.
Definition: filter_npasses.hpp:30