-
Notifications
You must be signed in to change notification settings - Fork 0
/
imageToolsLesson4.cpp
46 lines (32 loc) · 1.02 KB
/
imageToolsLesson4.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#include "imageTools.h"
#include <iostream>
CImage ImageTools::gaussianFilter(CImage& image, int radius, bool high) {
CImage fourierImage = image.FourierTransformation(false);
Complex value;
double temp;
double real;
double imag;
int m = image.getHeight();
int n = image.getWidth();
for (int x = 0; x < m; x++) {
for (int y = 0; y < n; y++) {
double distance = pow(pow(x - m / 2, 2) + pow(y - n / 2, 2), 2);
temp = exp(-distance / (2 * pow(radius, 2)));
if (high) temp = 2 - temp;
value = fourierImage.getComplexPointValue(x, y);
real = value.real();
imag = value.imag();
value.real(real * temp);
value.imag(imag * temp);
fourierImage.setComplexPointValue(x, y, value);
}
}
CImage output = fourierImage.FourierTransformation(true);
return output;
}
CImage ImageTools::gaussianLowPassFilter(CImage& image, int radius) {
return gaussianFilter(image, radius, false);
}
CImage ImageTools::gaussianHighPassFilter(CImage& image, int radius) {
return gaussianFilter(image, radius, true);
}