-
Notifications
You must be signed in to change notification settings - Fork 0
/
multichannelkernel.cpp
85 lines (62 loc) · 2.43 KB
/
multichannelkernel.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
73
74
75
76
#include "multichannelkernel.h"
MultiChannelKernel::MultiChannelKernel()
{
redKernel = nullptr;
greenKernel = nullptr;
blueKernel = nullptr;
redKernelCoefficient = 1;
greenKernelCoefficient = 1;
blueKernelCoefficient = 1;
}
MultiChannelKernel::~MultiChannelKernel()
{
// delete []redKernel;
// delete []greenKernel;
// delete []blueKernel;
}
MultiChannelKernel::MultiChannelKernel(double *redKernel, double *greenKernel, double *blueKernel)
{
this->redKernel = redKernel;
this->greenKernel = greenKernel;
this->blueKernel = blueKernel;
}
void MultiChannelKernel::setMultiChannelKernel(double *redKernel, double *greenKernel, double *blueKernel)
{
this->redKernel = redKernel;
this->greenKernel = greenKernel;
this->blueKernel = blueKernel;
}
void MultiChannelKernel::setKernelCoefficients(double redKernelCoefficient, double greenKernelCoefficient, double blueKernelCoefficient)
{
this->redKernelCoefficient = redKernelCoefficient;
this->greenKernelCoefficient = greenKernelCoefficient;
this->blueKernelCoefficient = blueKernelCoefficient;
}
BYTE* MultiChannelKernel::convolution(BYTE *inputImg, unsigned int width, unsigned height)
{
unsigned int center;
BYTE *result = new BYTE[(width)*(height)*3]{0};
int red=0,green=0,blue=0;
for (unsigned int i = 0; i < 3*(height-kernelSize+1); i+=3)
{
for (unsigned int j = 0; j < 3*(width-kernelSize+1); j+=3)
{
for(unsigned int k = 0; k< kernelSize; k++)
{
for(unsigned int h = 0; h< kernelSize; h++)
{
red += inputImg[(i * width + j) + (3 * k * width +(3*h))] * redKernel[k * kernelSize +h];
green += inputImg[(i * width + j) + (3 * k * width +(3*h)) + 1] * greenKernel[k * kernelSize +h];
blue += inputImg[(i * width + j) + (3 * k * width +(3*h)) + 2] * blueKernel[k * kernelSize +h];
if(k==kernelSize/2 && h==kernelSize/2)
center = (i * width + j) + (3*k * width +(3*h));
}
}
result[center] = redKernelCoefficient * red;
result[center + 1] = greenKernelCoefficient * green;
result[center + 2] = blueKernelCoefficient * blue;
red=0; green=0; blue=0;
}
}
return result;
}