PICCANTE  0.4
The hottest HDR imaging library!
filter_down_pp.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_DOWN_PP_HPP
19 #define PIC_FILTERING_FILTER_DOWN_PP_HPP
20 
21 #include "../util/array.hpp"
22 
23 #include "../filtering/filter.hpp"
24 
25 namespace pic {
26 
30 class FilterDownPP: public Filter
31 {
32 protected:
39  void ProcessBBox(Image *dst, ImageVec src, BBox *box)
40  {
41  int channels = src[0]->channels;
42 
43  for(int i2 = box->y0; i2 < box->y1; i2++) {
44  int i = i2 << 1;
45 
46  for(int j2 = box->x0; j2 < box->x1; j2++) {
47  int j = j2 << 1;
48 
49  float *tmp[4];
50  tmp[0] = (*src[0])(j , i);
51  tmp[1] = (*src[0])(j + 1, i);
52  tmp[2] = (*src[0])(j , i + 1);
53  tmp[3] = (*src[0])(j + 1, i + 1);
54 
55  int counter = 0;
56  float *out = (*dst)(j2, i2);
57 
58  Arrayf::assign(0.0f, out, channels);
59 
60  for(int k = 0; k < 4; k++) {
61  if(Arrayf::distanceSq(tmp[k], value, channels) > threshold) {
62  counter++;
63 
64  for(int l = 0; l < channels; l++) {
65  out[l] += tmp[k][l];
66  }
67  }
68  }
69 
70  if(counter > 0) {
71  float counter_f = float(counter);
72  Arrayf::div(out, channels, counter_f);
73  } else {
74  Arrayf::assign(value, channels, out);
75  }
76  }
77  }
78  }
79 
80  float *value, threshold;
81 
82 public:
83 
89  FilterDownPP(float *value, float threshold) : Filter()
90  {
92  }
93 
95  {
96  }
97 
103  void update(float *value, float threshold)
104  {
105  this->value = value;
106 
107  if(value == NULL) {
108  printf("ERROR in FilterDownPP");
109  }
110 
111  this->threshold = (threshold > 0.0f) ? threshold : 1e-4f;
112  }
113 
122  void OutputSize(ImageVec imgIn, int &width, int &height, int &channels, int &frames)
123  {
124  if(imgIn.size() == 1) {
125  width = imgIn[0]->width >> 1;
126  height = imgIn[0]->height >> 1;
127  } else {
128  width = imgIn[1]->width;
129  height = imgIn[1]->height;
130 
131  }
132 
133  channels = imgIn[0]->channels;
134  frames = imgIn[0]->frames;
135  }
136 };
137 
138 } // end namespace pic
139 
140 #endif /* PIC_FILTERING_FILTER_DOWN_PP_HPP */
141 
The BBox class manages the creation of bounding boxes for images.
Definition: bbox.hpp:29
~FilterDownPP()
Definition: filter_down_pp.hpp:94
float threshold
Definition: filter_down_pp.hpp:80
std::vector< Image * > ImageVec
ImageVec an std::vector of pic::Image.
Definition: image_vec.hpp:29
int x0
Definition: bbox.hpp:32
void OutputSize(ImageVec imgIn, int &width, int &height, int &channels, int &frames)
OutputSize.
Definition: filter_down_pp.hpp:122
The Filter class.
Definition: filter.hpp:50
FilterDownPP(float *value, float threshold)
FilterDownPP.
Definition: filter_down_pp.hpp:89
float * value
Definition: filter_down_pp.hpp:80
static T distanceSq(T *data0, T *data1, int n)
distanceSq
Definition: array.hpp:195
int y0
Definition: bbox.hpp:32
void update(float *value, float threshold)
update
Definition: filter_down_pp.hpp:103
The FilterDownPP class.
Definition: filter_down_pp.hpp:30
void ProcessBBox(Image *dst, ImageVec src, BBox *box)
ProcessBBox.
Definition: filter_down_pp.hpp:39
The Image class stores an image as buffer of float.
Definition: image.hpp:60
static void div(T *data, int size, T value)
div
Definition: array.hpp:353
virtual void f(FilterFData *data)
f
Definition: filter_radial_basis_function.hpp:69
Definition: bilateral_separation.hpp:25
static T * assign(T *data, int size, T *ret)
assign
Definition: array.hpp:464