PICCANTE  0.4
The hottest HDR imaging library!
filter_sampler_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_SAMPLER_2D_HPP
19 #define PIC_FILTERING_FILTER_SAMPLER_2D_HPP
20 
21 #include "../filtering/filter.hpp"
22 #include "../image_samplers/image_sampler_bilinear.hpp"
23 #include "../image_samplers/image_sampler_bsplines.hpp"
24 #include "../image_samplers/image_sampler_gaussian.hpp"
25 #include "../image_samplers/image_sampler_nearest.hpp"
26 
27 namespace pic {
28 
32 class FilterSampler2D: public Filter
33 {
34 protected:
37  float scaleX, scaleY;
38  int width, height;
39  bool swh;
40 
47  void ProcessBBox(Image *dst, ImageVec src, BBox *box);
48 
49 public:
50 
55  {
56  scaleX = -1.0f;
57  scaleY = -1.0f;
58  width = -1;
59  height = -1;
60  isb = NULL;
61  }
62 
69 
77 
85 
94  void OutputSize(ImageVec imgIn, int &width, int &height, int &channels, int &frames)
95  {
96  if(imgIn.empty()) {
97  width = -2;
98  height = -2;
99  channels = -2;
100  frames = -2;
101  return;
102  }
103 
104  if(imgIn.size() == 1) {
105  if(swh) {
106  width = int(imgIn[0]->widthf * scaleX);
107  height = int(imgIn[0]->heightf * scaleY);
108  } else {
109  width = this->width;
110  height = this->height;
111  }
112  } else {
113  width = imgIn[1]->width;
114  height = imgIn[1]->height;
115  }
116 
117  channels = imgIn[0]->channels;
118  frames = imgIn[0]->frames;
119  }
120 
127  void update(int width, int height, ImageSampler *isb)
128  {
129  this->width = width;
130  this->height = height;
131 
132  this->swh = false;
133 
134  if(isb == NULL) {
135  this->isb = new ImageSamplerNearest();
136  } else {
137  this->isb = isb;
138  }
139  }
140 
149  static Image *execute(Image *imgIn, Image *imgOut, float scale,
150  ImageSampler *isb = NULL)
151  {
152  FilterSampler2D filter(scale, isb);
153  return filter.Process(Single(imgIn), imgOut);
154  }
155 
165  static Image *execute(Image *imgIn, Image *imgOut, float scaleX,
166  float scaleY, ImageSampler *isb = NULL)
167  {
168  FilterSampler2D filter(scaleX, scaleY, isb);
169  return filter.Process(Single(imgIn), imgOut);
170  }
171 
181  static Image *execute(Image *imgIn, Image *imgOut, int width,
182  int height, ImageSampler *isb = NULL)
183  {
184  FilterSampler2D filter(width, height, isb);
185  return filter.Process(Single(imgIn), imgOut);
186  }
187 
188 };
189 
191  ImageSampler *isb = NULL): Filter()
192 {
193  this->scale = scale;
194  this->scaleX = scale;
195  this->scaleY = scale;
196 
197  this->swh = true;
198 
199  if(isb == NULL) {
200  this->isb = new ImageSamplerNearest();
201  } else {
202  this->isb = isb;
203  }
204 }
205 
206 PIC_INLINE FilterSampler2D::FilterSampler2D(float scaleX, float scaleY,
207  ImageSampler *isb = NULL): Filter()
208 {
209  this->scaleX = scaleX;
210  this->scaleY = scaleY;
211 
212  this->swh = true;
213 
214  if(isb == NULL) {
215  this->isb = &isb_default;
216  } else {
217  this->isb = isb;
218  }
219 }
220 
222  ImageSampler *isb = NULL): Filter()
223 {
224  update(width, height, isb);
225 }
226 
228  BBox *box)
229 {
230  float height1f = float(box->height - 1);
231  float width1f = float(box->width - 1);
232 
233  for(int j = box->y0; j < box->y1; j++) {
234  float y = float(j) / height1f;
235 
236  for(int i = box->x0; i < box->x1; i++) {
237 
238  float x = float(i) / width1f;
239 
240  float *tmp_dst = (*dst)(i, j);
241 
242  isb->SampleImage(src[0], x, y, tmp_dst);
243  }
244  }
245 }
246 
247 } // end namespace pic
248 
249 #endif /* PIC_FILTERING_FILTER_SAMPLER_2D_HPP */
250 
The FilterSampler2D class.
Definition: filter_sampler_2d.hpp:32
The BBox class manages the creation of bounding boxes for images.
Definition: bbox.hpp:29
void ProcessBBox(Image *dst, ImageVec src, BBox *box)
ProcessBBox.
Definition: filter_sampler_2d.hpp:227
ImageSamplerNearest isb_default
Definition: filter_sampler_2d.hpp:35
std::vector< Image * > ImageVec
ImageVec an std::vector of pic::Image.
Definition: image_vec.hpp:29
int x0
Definition: bbox.hpp:32
ImageSampler * isb
Definition: filter_sampler_2d.hpp:36
The ImageSampler class.
Definition: image_sampler.hpp:29
The Filter class.
Definition: filter.hpp:50
static Image * execute(Image *imgIn, Image *imgOut, float scaleX, float scaleY, ImageSampler *isb=NULL)
execute
Definition: filter_sampler_2d.hpp:165
virtual Image * Process(ImageVec imgIn, Image *imgOut)
Process.
Definition: filter.hpp:390
void update(int width, int height, ImageSampler *isb)
update
Definition: filter_sampler_2d.hpp:127
FilterSampler2D()
FilterSample2D.
Definition: filter_sampler_2d.hpp:54
float scale
Definition: filter_radial_basis_function.hpp:53
bool swh
Definition: filter_sampler_2d.hpp:39
int y0
Definition: bbox.hpp:32
int width
Definition: filter_sampler_2d.hpp:38
int height
Definition: filter_sampler_2d.hpp:38
#define PIC_INLINE
Definition: base.hpp:33
static Image * execute(Image *imgIn, Image *imgOut, float scale, ImageSampler *isb=NULL)
execute
Definition: filter_sampler_2d.hpp:149
The Image class stores an image as buffer of float.
Definition: image.hpp:60
float scaleY
Definition: filter_sampler_2d.hpp:37
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
virtual void SampleImage(Image *img, float x, float y, float *vOut)
SampleImage samples an image in uniform coordiantes.
Definition: image_sampler.hpp:57
int width
Definition: bbox.hpp:33
static Image * execute(Image *imgIn, Image *imgOut, int width, int height, ImageSampler *isb=NULL)
execute
Definition: filter_sampler_2d.hpp:181
int height
Definition: bbox.hpp:33
void OutputSize(ImageVec imgIn, int &width, int &height, int &channels, int &frames)
OutputSize.
Definition: filter_sampler_2d.hpp:94
The ImageSamplerNearest class.
Definition: image_sampler_nearest.hpp:28
float scaleX
Definition: filter_sampler_2d.hpp:37