PICCANTE  0.4
The hottest HDR imaging library!
filter_med.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_HPP
19 #define PIC_FILTERING_FILTER_MED_HPP
20 
21 #include "../filtering/filter.hpp"
22 
23 namespace pic {
24 
28 class FilterMed: public Filter
29 {
30 protected:
32 
39  void ProcessBBox(Image *dst, ImageVec src, BBox *box)
40  {
41  Image *in = src[0];
42  float *values = new float[areaKernel * in->channels];
43 
44  for(int j = box->y0; j < box->y1; j++) {
45  for(int i = box->x0; i < box->x1; i++) {
46 
47  int c = 0;
48  for(int k = -halfSize; k <= halfSize; k++) {
49  for(int l = -halfSize; l <= halfSize; l++) {
50 
51  float *color = (*in)(i + l, j + k);
52 
53  for(int ch = 0; ch < in->channels; ch++) {
54  values[areaKernel * ch + c] = color[ch];
55  }
56 
57  c++;
58  }
59  }
60 
61  float *out = (*dst) (i, j);
62 
63  for(int ch = 0; ch < in->channels; ch++) {
64  float *tmp_v_ch = &values[areaKernel * ch];
65  std::sort(tmp_v_ch, tmp_v_ch + areaKernel);
66 
67  out[ch] = tmp_v_ch[midValue];
68  }
69  }
70  }
71 
72  delete[] values;
73  }
74 
75 public:
80  FilterMed(int size) : Filter()
81  {
82  update(size);
83  }
84 
89  void update(int size)
90  {
91  this->halfSize = checkHalfSize(size);
92  size = (halfSize << 1) + 1;
93  this->areaKernel = size * size;
94  this->midValue = areaKernel >> 1;
95  }
96 
104  static Image *execute(Image *imgIn, Image *imgOut, int size)
105  {
106  FilterMed filter(size);
107  return filter.Process(Single(imgIn), imgOut);
108  }
109 };
110 
111 } // end namespace pic
112 
113 #endif /* PIC_FILTERING_FILTER_MED_HPP */
114 
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
int halfSize
Definition: filter_med.hpp:31
virtual Image * Process(ImageVec imgIn, Image *imgOut)
Process.
Definition: filter.hpp:390
int midValue
Definition: filter_med.hpp:31
void update(int size)
update
Definition: filter_med.hpp:89
int y0
Definition: bbox.hpp:32
void ProcessBBox(Image *dst, ImageVec src, BBox *box)
ProcessBBox.
Definition: filter_med.hpp:39
FilterMed(int size)
FilterMed.
Definition: filter_med.hpp:80
The Image class stores an image as buffer of float.
Definition: image.hpp:60
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
static Image * execute(Image *imgIn, Image *imgOut, int size)
execute
Definition: filter_med.hpp:104
int areaKernel
Definition: filter_med.hpp:31
The FilterMed class.
Definition: filter_med.hpp:28