PICCANTE  0.4
The hottest HDR imaging library!
filter_local_extrema.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_LOCAL_EXTREMA_HPP
19 #define PIC_FILTERING_FILTER_LOCAL_EXTREMA_HPP
20 
21 #include "../filtering/filter.hpp"
22 
23 namespace pic {
24 
29 {
30 protected:
31 
38  void ProcessBBox(Image *dst, ImageVec src, BBox *box)
39  {
40  Image *img = src[0];
41 
42  int channels = dst->channels;
43 
44  for(int j = box->y0; j < box->y1; j++) {
45  for(int i = box->x0; i < box->x1; i++) {
46  float *dst_data = (*dst)(i, j);
47 
48  float *img_data = (*img)(i, j);
49 
50  float val = 0.0f;
51 
52  for(int c = 0; c < channels; c++) {
53  val += img_data[c];
54  }
55 
56  int counter_higher = 0;
57  int counter_lower = 0;
58  for(int k = -halfKernelSize; k <= halfKernelSize; k++) {
59  for(int l = -halfKernelSize; l <= halfKernelSize; l++) {
60  if(l == k) {
61  continue;
62  }
63 
64  float *img_data_lk = (*img)(i + l, j + k);
65 
66  //accumulation
67  float val_lk = 0.0f;
68  for(int c = 0; c < channels; c++) {
69  val_lk += img_data_lk[c];
70  }
71 
72  if(val_lk >= val) {
73  counter_higher++;
74  }
75 
76  if(val_lk <= val) {
77  counter_lower++;
78  }
79  }
80  }
81 
82  if(counter_higher < kernelSize) {
83  dst_data[0] = 1.0f;
84  } else {
85  if(counter_lower < kernelSize) {
86  dst_data[0] = -1.0f;
87  } else {
88  dst_data[0] = 0.0f;
89  }
90  }
91  }
92  }
93  }
94 
96 
97 public:
98 
103  {
104  if(kernelSize < 2) {
105  kernelSize = 3;
106  }
107 
108  if((kernelSize % 2) == 0) {
109  kernelSize++;
110  }
111 
112  this->kernelSize = kernelSize;
113  this->halfKernelSize = kernelSize >> 1;
114  }
115 
124  void OutputSize(ImageVec imgIn, int &width, int &height, int &channels, int &frames)
125  {
126  width = imgIn[0]->width;
127  height = imgIn[0]->height;
128  channels = 1;
129  frames = imgIn[0]->frames;
130  }
131 
139  static Image *execute(Image *img, Image *imgOut, int kernelSize = 3)
140  {
142  return flt.Process(Single(img), imgOut);
143  }
144 };
145 
146 } // end namespace pic
147 
148 #endif /* PIC_FILTERING_FILTER_LOCAL_EXTREMA_HPP */
149 
int kernelSize
Definition: filter_local_extrema.hpp:95
The BBox class manages the creation of bounding boxes for images.
Definition: bbox.hpp:29
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
void ProcessBBox(Image *dst, ImageVec src, BBox *box)
ProcessBBox.
Definition: filter_local_extrema.hpp:38
virtual Image * Process(ImageVec imgIn, Image *imgOut)
Process.
Definition: filter.hpp:390
The FilterLocalExtrema class.
Definition: filter_local_extrema.hpp:28
int y0
Definition: bbox.hpp:32
int halfKernelSize
Definition: filter_local_extrema.hpp:95
static Image * execute(Image *img, Image *imgOut, int kernelSize=3)
execute
Definition: filter_local_extrema.hpp:139
The Image class stores an image as buffer of float.
Definition: image.hpp:60
void OutputSize(ImageVec imgIn, int &width, int &height, int &channels, int &frames)
OutputSize.
Definition: filter_local_extrema.hpp:124
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
FilterLocalExtrema(int kernelSize=3)
FilterLocalExtrema.
Definition: filter_local_extrema.hpp:102