-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSharpening.cpp
More file actions
36 lines (35 loc) · 1.51 KB
/
Sharpening.cpp
File metadata and controls
36 lines (35 loc) · 1.51 KB
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
#include "Sharpening.h"
void Sharpening::Do(Image& image) {
std::vector<std::vector<Color>> matrix = image.GetMatrix();
const int foo = 5;
for (int i = 0; i < image.GetHeight(); ++i) {
for (int j = 0; j < image.GetWidth(); ++j) {
int p_y_min = i - 1;
int p_x_min = j - 1;
int p_x_max = j + 1;
int p_y_max = i + 1;
if (j == 0) {
p_x_min = j;
}
if (j == image.GetWidth() - 1) {
p_x_max = j;
}
if (i == 0) {
p_y_min = i;
}
if (i == image.GetHeight() - 1) {
p_y_max = i;
}
matrix[i][j].r = Min(
1, Max(0, (-image.GetColor(j, p_y_min).r - image.GetColor(j, p_y_max).r - image.GetColor(p_x_min, i).r -
image.GetColor(p_x_max, i).r + foo * image.GetColor(j, i).r)));
matrix[i][j].g = Min(
1, Max(0, (-image.GetColor(j, p_y_min).g - image.GetColor(j, p_y_max).g - image.GetColor(p_x_min, i).g -
image.GetColor(p_x_max, i).g + foo * image.GetColor(j, i).g)));
matrix[i][j].b = Min(
1, Max(0, (-image.GetColor(j, p_y_min).b - image.GetColor(j, p_y_max).b - image.GetColor(p_x_min, i).b -
image.GetColor(p_x_max, i).b + foo * image.GetColor(j, i).b)));
}
}
image.SetMatrix(matrix);
}