-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSobel.h
More file actions
50 lines (42 loc) · 957 Bytes
/
Sobel.h
File metadata and controls
50 lines (42 loc) · 957 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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#pragma once
#include "Processor.h"
class Sobel : public Processor
{
public:
Sobel() : ProcessorInst(Sobel) { }
static Registrar<Sobel> registrar;
void ProcessImage(float fElapsedTime, frame& input, frame& output)
{
for (int i = 0; i < nFrameWidth; i++)
{
for (int j = 0; j < nFrameHeight; j++)
{
float fKernelSumH = 0.0f;
float fKernelSumV = 0.0f;
for (int n = -1; n < +2; n++)
{
for (int m = -1; m < +2; m++)
{
fKernelSumH += input.get(i + n, j + m) * kernel_sobel_h[(m + 1) * 3 + (n + 1)];
fKernelSumV += input.get(i + n, j + m) * kernel_sobel_v[(m + 1) * 3 + (n + 1)];
}
}
output.set(i, j, fabs((fKernelSumH + fKernelSumV) / 2.0f));
}
}
}
private:
float kernel_sobel_v[9] =
{
-1.0f, 0.0f, +1.0f,
-2.0f, 0.0f, +2.0f,
-1.0f, 0.0f, +1.0f,
};
float kernel_sobel_h[9] =
{
-1.0f, -2.0f, -1.0f,
0.0f, 0.0f, 0.0f,
+1.0f, +2.0f, +1.0f,
};
};
RegistrarInst(Sobel);