forked from rlk/envtools
-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathSummedAreaTableRegion.cpp
86 lines (64 loc) · 2.13 KB
/
SummedAreaTableRegion.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
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
/* -*-c++-*- */
#include "SummedAreaTableRegion"
#include "SummedAreaTable"
/**
* A subregion in a SummedAreaTable.
*/
double SatRegion::getRegionWeight() const
{
double f00 = _sat->I1(_x,_y);
double f10 = _sat->I1(_x+_w,_y);
double f01 = _sat->I1(_x,_y+_h);
double f11 = _sat->I1(_x+_w,_y+_h);
return _sum * (f00 + f10 + f01 + f11) * 0.25;
}
double SatRegion::getCornerDeviation() const
{
const Vec2d c = centroid();
const double fav = _sat->I1(c[0],c[1]);
double f00fav = _sat->I1(_x,_y) - fav;
double f10fav = _sat->I1(_x+ _w,_y) - fav;
double f01fav = _sat->I1(_x,_y+_h) - fav;
double f11fav = _sat->I1(_x+ _w,_y+_h) - fav;
f00fav *= f00fav;
f10fav *= f10fav;
f01fav *= f01fav;
f11fav *= f11fav;
return 0.5 * sqrt(f00fav + f10fav + f01fav + f11fav);
}
void SatRegion::create(const int x, const int y, const uint w, const uint h, const SummedAreaTable* sat)
{
_x = x; _y = y; _w = w; _h = h; _sat = sat;
_sum = _sat->sum(x, y,
x+(w-1), y,
x+(w-1), y+(h-1),
x, y+(h-1));
_r = _sat->sumR(x, y,
x+(w-1), y,
x+(w-1), y+(h-1),
x, y+(h-1));
_g = _sat->sumG(x, y,
x+(w-1), y,
x+(w-1), y+(h-1),
x, y+(h-1));
_b = _sat->sumB(x, y,
x+(w-1), y,
x+(w-1), y+(h-1),
x, y+(h-1));
_sum2 = _sat->sum2(x, y,
x+(w-1), y,
x+(w-1), y+(h-1),
x, y+(h-1));
_sum3 = _sat->sum3(x, y,
x+(w-1), y,
x+(w-1), y+(h-1),
x, y+(h-1));
_sum4 = _sat->sum4(x, y,
x+(w-1), y,
x+(w-1), y+(h-1),
x, y+(h-1));
_sum5 = _sat->sum5(x, y,
x+(w-1), y,
x+(w-1), y+(h-1),
x, y+(h-1));
}