-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathconvmatfactory.cpp
72 lines (62 loc) · 1.54 KB
/
convmatfactory.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#include "convmatfactory.h"
#include <thread>
#include <chrono>
#include <queue>
#include <cstdlib>
#include <cmath>
using namespace MatAlg;
// Formula:
//https://www.geeksforgeeks.org/gaussian-filter-generation-c/
ConvMatFactory::ConvMatFactory()
{
}
double ConvMatFactory::gaussKernelFormula(const double x, const double y)
{
double sigma = 1.0;
double firstPart = 1/(2*M_PI*pow(sigma, 2));
double secondPart = exp(-(pow(x, 2) + pow(y, 2))/(2*pow(sigma, 2)));
return firstPart*secondPart;
}
Matrix<double> ConvMatFactory::gaussBlurMatrix(const uint column, const uint row)
{
Matrix<double> mat(row, column, 0.0);
int centerX = row/2;
int centerY = column/2;
for(int x = 0; x < int(row); x++)
{
for(int y = 0; y < int(column); y++)
{
double value = gaussKernelFormula(x-centerX, y-centerY);
mat[x][y] = value;
}
}
return mat;
}
MatAlg::Matrix<double> ConvMatFactory::blurMatrix(const uint column, const uint row)
{
return Matrix<double>(row, column, 1.0);
}
Matrix<double> ConvMatFactory::edgeDetectMatrix()
{
return {{0, 1, 0},
{1, -4, 1},
{0, 1, 0}};
}
Matrix<double> ConvMatFactory::edgeEnhanceMatrix()
{
return {{0, 0, 0},
{-1, 1, 0},
{0, 0, 0}};
}
MatAlg::Matrix<double> ConvMatFactory::sharpenMatrix()
{
return {{0, -1, 0},
{-1, 5, -1},
{0, -1, 0}};
}
MatAlg::Matrix<double> ConvMatFactory::embossMatrix()
{
return {{-2, -1, 0},
{-1, 1, 1},
{0, 1, 2}};
}