-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy patherosionCPU.cpp
33 lines (30 loc) · 1.06 KB
/
erosionCPU.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
#include <math.h>
#include <limits>
#define imax(a,b) (a > b) ? a : b;
#define imin(a,b) (a < b) ? a : b;
void erosionCPU(int * src, int * dst, int width, int height, int radio) {
int * tmp = new int[width * height];
for (int i = 0; i < height; i++) {
for (int j = 0; j < width; j++) {
int start_j = imax(0, j - radio);
int end_j = imin(width - 1, j + radio);
int value = std::numeric_limits<int>::max();
for (int jj = start_j; jj <= end_j; jj++) {
value = imin(src[i * width + jj], value);
}
tmp[i * width + j] = value;
}
}
for (int i = 0; i < height; i++) {
for (int j = 0; j < width; j++) {
int start_i = imax(0, i - radio);
int end_i = imin(height - 1, i + radio);
int value = std::numeric_limits<int>::max();
for (int ii = start_i; ii <= end_i; ii++) {
value = imin(tmp[ii * width + j], value);
}
dst[i * width + j] = value;
}
}
delete[](tmp);
}