PICCANTE  0.4
The hottest HDR imaging library!
compute_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_ALGORITHMS_COMPUTE_DIVERGENCE_HPP
19 #define PIC_ALGORITHMS_COMPUTE_DIVERGENCE_HPP
20 
21 #include "../base.hpp"
22 
23 #include "../util/std_util.hpp"
24 
25 #include "../filtering/filter_conv_1d.hpp"
26 
27 namespace pic {
28 
36 {
37 protected:
39  float kernelGrad[3];
40  float kernelDiv[3];
42 
43 public:
44 
49  {
50  kernelGrad[0] = -0.5f;
51  kernelGrad[1] = 0.0f;
52  kernelGrad[2] = 0.5f;
53 
54  kernelDiv[0] = -1.0f;
55  kernelDiv[1] = 1.0f;
56  kernelDiv[2] = 0.0f;
57 
58  img_dx = NULL;
59  img_dy = NULL;
60  }
61 
63  {
66  }
67 
74  Image *Process(Image *imgIn, Image *imgOut)
75  {
76  if(imgIn == NULL) {
77  return imgOut;
78  }
79 
80  if(imgOut == NULL) {
81  imgOut = imgIn->clone();
82  } else {
83  if(!imgOut->isSimilarType(imgIn)) {
84  imgOut = imgIn->allocateSimilarOne();
85  }
86  }
87 
88  //compute gradient dx
89  flt.update(kernelGrad, 3, true);
90  img_dx = flt.Process(Single(imgIn), img_dx);
91 
92  //compute gradient dy
93  flt.update(kernelGrad, 3, false);
94  img_dy = flt.Process(Single(imgIn), img_dy);
95 
96  //compute the divergence using backward differences
97  flt.update(kernelDiv, 3, true);
98  imgOut = flt.Process(Single(img_dx), imgOut);
99 
100  flt.update(kernelDiv, 3, false);
101  auto img_dy2 = flt.Process(Single(img_dy), img_dx);
102 
103  *imgOut += *img_dy2;
104 
105  return imgOut;
106  }
107 
114  static Image *execute(Image *imgIn, Image *imgOut)
115  {
116  DivergenceOperator divOp;
117  return divOp.Process(imgIn, imgOut);
118  }
119 };
120 
121 } // end namespace pic
122 
123 #endif /* PIC_ALGORITHMS_COMPUTE_DIVERGENCE_HPP */
124 
DivergenceOperator()
DivergenceOperator.
Definition: compute_divergence.hpp:48
T * delete_s(T *data)
delete_s
Definition: std_util.hpp:123
bool isSimilarType(const Image *img)
isSimilarType checks if the current image is similar to img; i.e. if they have the same width...
FilterConv1D flt
Definition: compute_divergence.hpp:38
void update(float *data, int kernelSize, int direction)
update
Definition: filter_conv_1d.hpp:160
virtual Image * Process(ImageVec imgIn, Image *imgOut)
Process.
Definition: filter.hpp:390
Image * img_dx
Definition: compute_divergence.hpp:41
Image * img_dy
Definition: compute_divergence.hpp:41
Image * Process(Image *imgIn, Image *imgOut)
Process.
Definition: compute_divergence.hpp:74
The FilterConv1D class.
Definition: filter_conv_1d.hpp:32
float kernelGrad[3]
Definition: compute_divergence.hpp:39
The Image class stores an image as buffer of float.
Definition: image.hpp:60
Image * clone() const
Clone creates a deep copy of the calling instance.
Image * allocateSimilarOne()
allocateSimilarOne creates an Image with similar size of the calling instance.
~DivergenceOperator()
Definition: compute_divergence.hpp:62
PIC_INLINE ImageVec Single(Image *img)
Single creates an std::vector which contains img; this is for filters input.
Definition: image_vec.hpp:36
float kernelDiv[3]
Definition: compute_divergence.hpp:40
Definition: bilateral_separation.hpp:25
static Image * execute(Image *imgIn, Image *imgOut)
execute
Definition: compute_divergence.hpp:114
DivergenceOperator calculates divergence of the gradient of an image.
Definition: compute_divergence.hpp:35