-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patherror_region.pde
56 lines (51 loc) · 1.14 KB
/
error_region.pde
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
/**
*
* @author Thomas Lindemeier
* @date 28.10.2012
*
*/
class ErrorRegion
{
int x0, y0, w, h;
float ae;
ErrorRegion(int px, int py, int pw, int ph, float pae) {
x0 = px;
y0 = py;
w = pw;
h = ph;
ae = pae;
}
PVector computeSeedPoint(final PImage distance) {
PVector seed = new PVector();
float errorMax = 0;
float error;
int index;
for (int x = x0; x < x0+w; x++)
for (int y = y0; y < y0+h; y++) {
index = x + y * distance.width;
if (index < distance.pixels.length) {
error = red(distance.pixels[index]);
if (error > errorMax){
errorMax = error;
seed.x = x;
seed.y = y;
}
}
}
return seed;
}
void computeAverageDistance(final PImage distance) {
ae = 0;
int index;
int totalPixels = 0;
for (int x=x0; x<x0+w; x++)
for (int y=y0; y<y0+h; y++) {
index = x + y * distance.width;
if (index < distance.pixels.length) {
ae += red(distance.pixels[index]);
totalPixels++;
}
}
ae /= totalPixels;
}
}