App
TDoGSharpen.hpp
Go to the documentation of this file.
1 
2 namespace app {
3  template <typename TPIXEL, typename TCHANNEL> class TDoGSharpen;
4 }
5 
6 #ifndef TDOGSHARPEN_HPP_
7 #define TDOGSHARPEN_HPP_
8 
9 #include <cstdlib>
10 #include <cmath>
11 #include <cstring>
12 
13 #include "TFilter.hpp"
14 #include "TLinearFilter.hpp"
15 
16 #include "../typedefs.hpp"
17 #include "../bitmaps/TBitmap.hpp"
18 
19 namespace app {
20 
21 template <typename TPIXEL, typename TCHANNEL>
22 class TDoGSharpen : public TLinearFilter<TPIXEL, TCHANNEL> {
23 public:
24  TDoGSharpen(double sigma, double k, double force, int area) {
25 
26  if (sigma <=0.34) {
27  this->initOk = 1; // Aplikace filtru neprobehne, ale inicializace je OK - filtr nema zadny efekt
28  return; }
29  this->kernelHCenter = 3 * k * sigma;
30  this->kernelWidth = 2 * this->kernelHCenter + 1;
31  this->kernelWCenter = 3 * k * sigma;
32  this->kernelHeight = 2 * this->kernelWCenter + 1;
33 
34  force = (force + 1) / (1.0000001 - force);
35 
36  this->kernel = (double *) malloc(this->kernelWidth * this->kernelHeight * sizeof(double));
37  if (this->kernel == NULL) { return; }
38 
39  double k2 = k * k;
40  double t1 = 1 / (sigma * sigma * 2);
41  double t2 = t1 / k2;
42  double t3 = force * t2 / 0.3141592654e1;
43 
44  int x = 0;
45  int y = 0;
46  double r2 = 0;
47  double posSum = 0;
48  double negSum = 0;
49  double tmp = 0;
50 
51  // Inicializace koeficientu
52  for (int i = 0; i < this->kernelHeight; i++) {
53  for (int j = 0; j < this->kernelWidth; j++) {
54  x = j - this->kernelWCenter;
55  y = i - this->kernelHCenter;
56  r2 = x * x + y * y;
57  tmp = t3 * (exp(-t1 * (r2)) * k2 - exp(-t2 * r2));
58  if (tmp >= 0) { posSum += tmp; } else { negSum += tmp; }
59  this->kernel[j + this->kernelWidth * i] = tmp;
60  }
61  }
62 
63  double normDelta = (area) ? -(posSum + negSum - 1) / posSum : -(posSum + negSum) / posSum;
64  double * ptr = this->kernel;
65  double * ptrEnd = this->kernel + this->kernelWidth * this->kernelHeight;
66  while (ptr < ptrEnd) {
67  if (*ptr >= 0) {
68  *ptr += *ptr * normDelta;
69  }
70  ptr++;
71  }
72 
73  // Přičtení jedničky k střednímu, aby nebyla jen detekce hran
74  if (!area) { this->kernel[this->kernelWCenter + this->kernelWidth * this->kernelHCenter] += 1; }
75 
76  this->initOk = 1;
77  }
78 
79  virtual ~TDoGSharpen();
80 };
81 
82 } /* namespace app */
83 #endif /* TDOGSHARPEN_HPP_ */