PICCANTE  0.4
The hottest HDR imaging library!
filter_med_vec.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_MED_VEC_HPP
19 #define PIC_FILTERING_FILTER_MED_VEC_HPP
20 
21 #include "../filtering/filter.hpp"
22 #include "../util/array.hpp"
23 
24 namespace pic {
25 
29 class FilterMedVec: public Filter
30 {
31 protected:
33 
40  void ProcessBBox(Image *dst, ImageVec src, BBox *box)
41  {
42  Image *in = src[0];
43  float *values = new float[areaKernel * in->channels];
44 
45  for(int j = box->y0; j < box->y1; j++) {
46  for(int i = box->x0; i < box->x1; i++) {
47 
48  int c = 0;
49  for(int k = -halfSize; k <= halfSize; k++) {
50  for(int l = -halfSize; l <= halfSize; l++) {
51 
52  float *color = (*in)(i + l, j + k);
53 
54  for(int ch = 0; ch < in->channels; ch++) {
55  values[c * in->channels + ch] = color[ch];
56  }
57 
58  c++;
59  }
60  }
61 
62  //compute distances
63  int best = -1;
64  float distBest = FLT_MAX;
65 
66  for(int k = 0; k < areaKernel; k++) {
67  int index_k = k * in->channels;
68  float dist = 0.0f;
69 
70  for(int l = 0; l < areaKernel; l++) {
71  int index_l = l * in->channels;
72  float d_sq = Arrayf::distanceSq(&values[index_k], &values[index_l], in->channels);
73  dist += sqrtf(d_sq);
74  }
75 
76  if(dist < distBest) {
77  distBest = dist;
78  best = k;
79  }
80  }
81 
82  float *out = (*dst) (i, j);
83 
84  int index = best * in->channels;
85 
86  for(int ch = 0; ch < in->channels; ch++) {
87  out[ch] = values[index + ch];
88  }
89  }
90  }
91 
92  delete[] values;
93  }
94 
95 public:
100  FilterMedVec(int size) : Filter()
101  {
102  update(size);
103  }
104 
109  void update(int size)
110  {
111  this->halfSize = checkHalfSize(size);
112 
113  int kernelSize = (halfSize << 1) + 1;
114  this->areaKernel = kernelSize * kernelSize;
115 
116  this->midValue = areaKernel >> 1;
117  }
118 
126  static Image *execute(Image *imgIn, Image *imgOut, int size)
127  {
128  FilterMedVec filter(size);
129  return filter.Process(Single(imgIn), imgOut);
130  }
131 };
132 
133 } // end namespace pic
134 
135 #endif /* PIC_FILTERING_FILTER_MED_VEC_HPP */
136 
The BBox class manages the creation of bounding boxes for images.
Definition: bbox.hpp:29
int checkHalfSize(int size)
checkHalfSize
Definition: filter_radial_basis_function.hpp:168
int channels
Definition: image.hpp:80
std::vector< Image * > ImageVec
ImageVec an std::vector of pic::Image.
Definition: image_vec.hpp:29
int x0
Definition: bbox.hpp:32
The Filter class.
Definition: filter.hpp:50
virtual Image * Process(ImageVec imgIn, Image *imgOut)
Process.
Definition: filter.hpp:390
void update(int size)
update
Definition: filter_med_vec.hpp:109
int midValue
Definition: filter_med_vec.hpp:32
static T distanceSq(T *data0, T *data1, int n)
distanceSq
Definition: array.hpp:195
int areaKernel
Definition: filter_med_vec.hpp:32
void ProcessBBox(Image *dst, ImageVec src, BBox *box)
ProcessBBox.
Definition: filter_med_vec.hpp:40
int y0
Definition: bbox.hpp:32
static Image * execute(Image *imgIn, Image *imgOut, int size)
execute
Definition: filter_med_vec.hpp:126
The Image class stores an image as buffer of float.
Definition: image.hpp:60
FilterMedVec(int size)
FilterMedVec.
Definition: filter_med_vec.hpp:100
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
The FilterMedVec class.
Definition: filter_med_vec.hpp:29
int halfSize
Definition: filter_med_vec.hpp:32