App

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

- File List
- File Members

TGaussianBlur.hpp
Go to the documentation of this file.
1
6 namespace app {
7 template <typename TPIXEL, typename TCHANNEL> class TGaussianBlur;
8 }
9
10 #ifndef TGAUSSIANBLUR_HPP_
11 #define TGAUSSIANBLUR_HPP_
12
13 #include <cstdlib>
14 #include <cmath>
15 #include <cstring>
16
17 #include "TFilter.hpp"
18 #include "TSeparableFilter.hpp"
19
20 #include "../typedefs.hpp"
21 #include "../bitmaps/TBitmap.hpp"
22
23 namespace app {
24
26
30 template <typename TPIXEL, typename TCHANNEL>
31 class TGaussianBlur : public TSeparableFilter<TPIXEL, TCHANNEL> {
32
33 public:
35
44 TGaussianBlur(double xSigma = 0.35, double ySigma = 0.35) {
45
46 if (xSigma < 0 || ySigma < 0) { return; }
47 xSigma = (xSigma < 0.1) ? 0.1 : xSigma;
48 ySigma = (ySigma < 0.1) ? 0.1 : ySigma;
49
50 this->xKernelCenter = 3 * xSigma; // Muze byt 0
51 this->xKernelWidth = 2 * this->xKernelCenter + 1; // minim. 1
52 this->xKernel = (double *) malloc(this->xKernelWidth * sizeof(double));
53 if (this->xKernel == NULL) { return; }
54 double xSigma2 = xSigma * xSigma;
55 double r = 0;
56 double factor = 0;
57 for (int i = 0; i < this->xKernelWidth; ++i) {
58 r = this->xKernelCenter - i;
59 this->xKernel[i] = exp(-0.5 * (r * r) / xSigma2);
60 factor += this->xKernel[i];
61 }
62 for (int i = 0; i < this->xKernelWidth; ++i) {
63 this->xKernel[i] /= factor;
64 }
65
66 this->yKernelCenter = 3 * ySigma;
67 this->yKernelWidth = 2 * this->yKernelCenter + 1;
68 this->yKernel = (double *) malloc(this->yKernelWidth * sizeof(double));
69 if (this->yKernel == NULL) { free(this->xKernel); this->xKernel = NULL; return; }
70 double ySigma2 = ySigma * ySigma;
71 factor = 0;
72 for (int i = 0; i < this->yKernelWidth; ++i) {
73 r = this->yKernelCenter - i;
74 this->yKernel[i] = exp(-0.5 * (r * r) / ySigma2);
75 factor += this->yKernel[i];
76 }
77 for (int i = 0; i < this->yKernelWidth; ++i) {
78 this->yKernel[i] /= factor;
79 }
80 }
81
83 virtual ~TGaussianBlur();
84 };
85
86 } /* namespace app */
87 #endif /* TGAUSSIANBLUR_HPP_ */