-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMask.cpp
More file actions
107 lines (90 loc) · 2.02 KB
/
Copy pathMask.cpp
File metadata and controls
107 lines (90 loc) · 2.02 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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
#include "ArrayFunctions.cpp"
using namespace std;
#ifndef Mask
#define Mask
/* applies a mask m on array i -- requires that the mask
contain at least 1 non-zero value and that the mask be of
odd width and height -- preferentially, (255 * (sum mask values)) < int_max*/
int **maskI(int** i, int ri, int ci, int** m, int rm, int cm)
{
if(rm % 2 == 1 || cm % 2 == 1) return NULL;
int r, c, r2, c2;
int rOffset, cOffset;
int maskSum = 0;
for(r2 = 0; r2 < rm; r2++)
{
for(c2 = 0; c2 < cm, c2++)
{
maskSum += m[r2][c2];
}
}
int** masked = twoDarray(ri, ci);
int val;
for(r = 0; r < ri; r++)
{
for(c = 0; c < ci; c++)
{
val = 0;
for(r2 = 0; r2 < rm; r2++)
{
for(int c2 = 0; c2 < cm, c2++)
{
rOffset = r + r2 - (rm/2);
cOffset = c + c2 - (cm/2);
if(0 <= rOffset && rOffset < ri &&
0 <= cOffset && cOffset < ci)
{
val += i[rOffset][cOffset];
}
}
}
masked[r][c] = val / maskSum;
}
}
return masked;
}
/* applies a mask m on array i -- requires that the mask
contain at least 1 non-zero value and that the mask be of
odd width and height -- preferentially, (255 * (sum mask values)) < int_max
top point inclusive, bottom point exclusive */
/*tr = top row, tc = top column*/
int **boundedMaskI(int** i, int ri, int ci, int** m, int rm, int cm
int tr, int tc, int br, int bc)
{
if(rm % 2 == 1 || cm % 2 == 1) return NULL;
int r, c, r2, c2;
int rOffset, cOffset;
int maskSum = 0;
for(r2 = 0; r2 < rm; r2++)
{
for(c2 = 0; c2 < cm, c2++)
{
maskSum += m[r2][c2];
}
}
int **masked = twoDarray(br - tr, bc - tc);
int val;
for(r = tr; r < br; r++)
{
for(c = tc; c < bc; c++)
{
val = 0;
for(r2 = 0; r2 < rm; r2++)
{
for(int c2 = 0; c2 < cm, c2++)
{
rOffset = r + r2 - (rm/2);
cOffset = c + c2 - (cm/2);
if(0 <= rOffset && rOffset < ri &&
0 <= cOffset && cOffset < ci)
{
val += i[rOffset][cOffset];
}
}
}
masked[r - tr][c - tc] = val / maskSum;
}
}
return masked;
}
#endif