-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathblur_improved.cpp
55 lines (41 loc) · 1.27 KB
/
blur_improved.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
#include "headers/blur_improved.h"
#include "headers/zeros_improved.h"
using namespace std;
vector < vector <float> > blur_improved(vector < vector < float> > &grid) {
static float GLOBAL_BLURRING = 0.12;
static float CENTER = 1.0 - GLOBAL_BLURRING;
static float CORNER = GLOBAL_BLURRING / 12.0;
static float ADJACENT = GLOBAL_BLURRING / 6.0;
static vector <int> DX = {-1, 0, 1};
static vector <int> DY = {-1, 0, 1};
static vector < vector <float> > GLOBAL_WINDOW = { {CORNER, ADJACENT, CORNER}, {ADJACENT, CENTER, ADJACENT}, {CORNER, ADJACENT, CORNER} };
vector < vector <float> > window;
vector < vector <float> > newGrid;
vector <float> row;
vector <float> newRow;
int height = grid.size();
int width = grid[0].size();
int i, j, ii, jj, new_i, new_j;
int dx, dy;
float multiplier;
float newVal;
// initialize new grid to zeros
newGrid = zeros_improved(height, width);
// original way
for (i=0; i< height; i++ ) {
for (j=0; j<width; j++ ) {
newVal = grid[i][j];
for (ii=0; ii<3; ii++) {
dy = DY[ii];
for (jj=0; jj<3; jj++) {
dx = DX[jj];
new_i = (i + dy + height) % height;
new_j = (j + dx + width) % width;
multiplier = GLOBAL_WINDOW[ii][jj];
newGrid[new_i][new_j] += newVal * multiplier;
}
}
}
}
return newGrid;
}