Added the images for test.
[pom.git] / integral_proba_view.h
1
2 //////////////////////////////////////////////////////////////////////////////////
3 // This program is free software: you can redistribute it and/or modify         //
4 // it under the terms of the version 3 of the GNU General Public License        //
5 // as published by the Free Software Foundation.                                //
6 //                                                                              //
7 // This program is distributed in the hope that it will be useful, but          //
8 // WITHOUT ANY WARRANTY; without even the implied warranty of                   //
9 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU             //
10 // General Public License for more details.                                     //
11 //                                                                              //
12 // You should have received a copy of the GNU General Public License            //
13 // along with this program. If not, see <http://www.gnu.org/licenses/>.         //
14 //                                                                              //
15 // Written by Francois Fleuret                                                  //
16 // (C) Ecole Polytechnique Federale de Lausanne                                 //
17 // Contact <pom@epfl.ch> for comments & bug reports                             //
18 //////////////////////////////////////////////////////////////////////////////////
19
20 #ifndef INTEGRAL_PROBA_VIEW_H
21 #define INTEGRAL_PROBA_VIEW_H
22
23 #include "proba_view.h"
24 #include "integral_array.h"
25
26 class IntegralProbaView : public IntegralArray<scalar_t> {
27 public:
28   IntegralProbaView(int view_width, int view_height) : IntegralArray<scalar_t>(view_width, view_height) {};
29
30   // Computes the integral image and returns the sum of all the
31   // original image pixels
32
33   inline scalar_t compute_sum(const ProbaView *m) {
34     scalar_t *p = content, *pm = m->content;
35     for(int x = 0; x < height; x++) *(p++) = 0;
36
37     register scalar_t st = 0;
38     register scalar_t sl;
39     for(register int y = 1; y < width; y++) {
40       sl = 0; *(p++) = sl;
41       for(register int x = 0; x < height - 1; x++) {
42         sl += *(pm++);
43         *p = sl + *(p - height);
44         p++;
45       }
46       st += sl;
47     }
48
49     return st;
50   }
51
52   // Computes the integral image and returns the sum of (2m-1)*b
53
54   inline scalar_t compute_sum(const ProbaView *m, const ProbaView *b) {
55     scalar_t *p = content, *pm = m->content, *pb = b->content;
56
57     for(int x = 0; x < height; x++) *(p++) = 0;
58
59     scalar_t st = 0;
60     register scalar_t sl;
61     for(int y = 1; y < width; y++) {
62       sl = 0; *(p++) = 0;
63       for(int x = 0; x < height - 1; x++) {
64         st -= *pb;
65         sl += *(pm++) * *(pb++);
66         *p = sl + *(p - height);
67         p++;
68       }
69       st += 2 * sl;
70     }
71
72     return st;
73   }
74 };
75 #endif