-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAdaptive.h
More file actions
55 lines (44 loc) · 1.23 KB
/
Adaptive.h
File metadata and controls
55 lines (44 loc) · 1.23 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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#pragma once
#include "Processor.h"
class Adaptive : public Processor
{
public:
Adaptive() : ProcessorInst(Adaptive) { }
static Registrar<Adaptive> registrar;
void ProcessKeys(float fElapsedTime)
{
// Respond to user input
if (game->GetKey(olc::Key::DOWN).bHeld) fAdaptiveBias -= 0.1f * fElapsedTime;
if (game->GetKey(olc::Key::UP).bHeld) fAdaptiveBias += 0.1f * fElapsedTime;
if (fAdaptiveBias > 1.5f) fAdaptiveBias = 1.5f;
if (fAdaptiveBias < 0.5f) fAdaptiveBias = 0.5f;
}
void ProcessImage(float fElapsedTime, frame& input, frame& output)
{
float fRegionSum = 0.0f;
for (int i = 0; i < nFrameWidth; i++)
{
for (int j = 0; j < nFrameHeight; j++)
{
fRegionSum = 0;
for (int n = -2; n < +3; n++)
{
for (int m = -2; m < +3; m++)
{
fRegionSum += input.get(i + n, j + m);
}
}
fRegionSum /= 25.0f;
output.set(i, j, input.get(i, j) > (fRegionSum * fAdaptiveBias) ? 1.0f : 0.0f);
}
}
}
virtual void DrawUI(int x, int y, int stepy)
{
game->DrawString(x, y, "Change adaptive threshold bias with arrow UP and DOWN");
game->DrawString(x, y + stepy, "Current value = " + std::to_string(fAdaptiveBias));
}
private:
float fAdaptiveBias = 1.1f;
};
RegistrarInst(Adaptive);