PICCANTE  0.4
The hottest HDR imaging library!
filter_divergence.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_DIVERGENCE_HPP
19 #define PIC_FILTERING_FILTER_DIVERGENCE_HPP
20 
21 #include "../filtering/filter.hpp"
22 
23 namespace pic {
24 
28 class FilterDivergence: public Filter
29 {
30 protected:
31 
38  void ProcessBBox(Image *dst, ImageVec src, BBox *box);
39 
40 public:
45  {
46 
47  }
48 
55  static Image *execute(Image *imgIn, Image *imgOut)
56  {
57  FilterDivergence filter;
58  return filter.Process(Single(imgIn), imgOut);
59  }
60 };
61 
63 {
64  int width = dst->width;
65  int height = dst->height;
66 
67  float *data = src[0]->data;
68  float gradX, gradY;
69 
70  int channels = src[0]->channels;
71  int c, ci, cj, ci1, cj1, tmpc, ind;
72 
73  for(int j = box->y0; j < box->y1; j++) {
74  ind = j * width;
75 
76  for(int i = box->x0; i < box->x1; i++) {
77  c = (ind + i) * channels;
78  //Positions
79  ci = CLAMP(i + 1, width);
80  cj = CLAMP(j + 1, height);
81  ci1 = CLAMP(i - 1, width);
82  cj1 = CLAMP(j - 1, height);
83 
84  //Grad X
85  tmpc = (ind + ci) * channels;
86  gradX = data[tmpc];
87 
88  tmpc = (ind + ci1) * channels;
89  gradX -= data[tmpc];
90 
91  //Grad Y
92  tmpc = (cj * width + i) * channels;
93  gradY = data[tmpc];
94 
95  tmpc = (cj1 * width + i) * channels;
96  gradY -= data[tmpc];
97 
98  //Divergence
99  dst->data[c] = (gradX + gradY) * 0.5f;
100  }
101  }
102 }
103 
104 } // end namespace pic
105 
106 #endif /* PIC_FILTERING_FILTER_DIVERGENCE_HPP */
107 
The BBox class manages the creation of bounding boxes for images.
Definition: bbox.hpp:29
float * data
data is the main buffer where pixel values are stored.
Definition: image.hpp:91
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
FilterDivergence()
FilterDivergence.
Definition: filter_divergence.hpp:44
int y0
Definition: bbox.hpp:32
void ProcessBBox(Image *dst, ImageVec src, BBox *box)
ProcessBBox.
Definition: filter_divergence.hpp:62
#define PIC_INLINE
Definition: base.hpp:33
The Image class stores an image as buffer of float.
Definition: image.hpp:60
virtual void f(FilterFData *data)
f
Definition: filter_radial_basis_function.hpp:69
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
#define CLAMP(x, a)
Definition: math.hpp:77
static Image * execute(Image *imgIn, Image *imgOut)
execute
Definition: filter_divergence.hpp:55
int width
Definition: image.hpp:80
int height
Definition: image.hpp:80
The FilterDivergence class.
Definition: filter_divergence.hpp:28