App

- Main Page
- Related Pages
- Namespaces
- Classes
- Files

- File List
- File Members

TGSharpen.hpp
Go to the documentation of this file.
1
2 namespace app {
3 template <typename TPIXEL, typename TCHANNEL> class TGSharpen;
4 }
5
6 #ifndef TGSHARPEN_HPP_
7 #define TGSHARPEN_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 // Pravděpodobně je separable... ale jistý to není...
21
22 template <typename TPIXEL, typename TCHANNEL>
23 class TGSharpen : public TLinearFilter<TPIXEL, TCHANNEL> {
24 public:
25 TGSharpen(double sigma, double force) {
26
27 if (sigma <=0.34) {
28 this->initOk = 1; // Aplikace filtru neprobehne, ale inicializace je OK - filtr nema zadny efekt
29 return; }
30 this->kernelHCenter = 3 * sigma;
31 this->kernelWidth = 2 * this->kernelHCenter + 1;
32 this->kernelWCenter = 3 * sigma;
33 this->kernelHeight = 2 * this->kernelWCenter + 1;
34
35 force = (force + 1) / (1.0000001 - force);
36
37 this->kernel = (double *) malloc(this->kernelWidth * this->kernelHeight * sizeof(double));
38 if (this->kernel == NULL) { return; }
39
40 double sig2 = sigma * sigma;
41 double k1 = 2 * sig2;
42 double k2 = 1 / k1;
43 double k3 = force * -k2 / (0.3141592654e1 * sig2 * sig2);
44
45 int x = 0;
46 int y = 0;
47 double r2 = 0;
48 double sum = 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 = this->kernelWCenter - j;
55 y = this->kernelHCenter - i;
56 r2 = x * x + y * y;
57 tmp = k3 * exp(-k2 * (r2));
58 sum += tmp;
59 this->kernel[j + this->kernelWidth * i] = tmp;
60 }
61 }
62
63 sum -= this->kernel[this->kernelWCenter + this->kernelWidth * this->kernelHCenter];
64 this->kernel[this->kernelWCenter + this->kernelWidth * this->kernelHCenter] = -sum + 1;
65 this->initOk = 1;
66 }
67
68 virtual ~TGSharpen();
69 };
70
71 } /* namespace app */
72 #endif /* TGSHARPEN_HPP_ */