-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathedge_filter.cpp
More file actions
36 lines (33 loc) · 993 Bytes
/
Copy pathedge_filter.cpp
File metadata and controls
36 lines (33 loc) · 993 Bytes
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 "edge_filter.hpp"
#include "grayscale_filter.hpp"
static Matrix<double> EdgeMatrix() {
Matrix<double> res(3, 3);
for (size_t i = 0; i < 3; ++i) {
for (size_t j = 0; j < 3; ++j) {
if (i == 1 && j == 1) {
res[{i, j}] = 4;
} else if ((i + j) % 2 == 0) {
res[{i, j}] = 0;
} else {
res[{i, j}] = -1;
}
}
}
return res;
}
EdgeFilter::EdgeFilter(double threshold) : MatrixFilter(EdgeMatrix()), threshold_(threshold) {
}
Picture EdgeFilter::operator()(const Picture& pic) const {
Picture res = GrayscaleFilter()(pic);
res = MatrixFilter::operator()(res);
for (size_t i = 0; i < pic.Height(); ++i) {
for (size_t j = 0; j < pic.Width(); ++j) {
if (res[{i, j}] > Pixel(threshold_)) {
res[{i, j}] = Pixel(1);
} else {
res[{i, j}] = Pixel(0);
}
}
}
return res;
}