Hugintrunk  0.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
WaveFilter.h
Go to the documentation of this file.
1 /*
2 * Copyright (C) 2007-2008 Anael Orlinski
3 *
4 * This file is part of Panomatic.
5 *
6 * Panomatic is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * Panomatic is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with Panomatic; if not, write to the Free Software
18 * <http://www.gnu.org/licenses/>.
19 */
20 
21 #ifndef __lfeat_wavefilter_h
22 #define __lfeat_wavefilter_h
23 
24 namespace lfeat
25 {
26 
27 class Image;
28 
30 {
31 public:
32  WaveFilter(double iBaseSize, Image& iImage);
33 
34  double getWx(unsigned int x, unsigned int y);
35  double getWy(unsigned int x, unsigned int y);
36 
37  bool checkBounds(int x, int y) const;
38 
39  double getSum(unsigned int x, unsigned int y, int scale);
40  double getWx(unsigned int x, unsigned int y, int scale);
41  double getWy(unsigned int x, unsigned int y, int scale);
42 
43  bool checkBounds(int x, int y, int scale) const;
44 
45 private:
46 
47  // orig image info
48  double** _ii;
49  unsigned int _im_width;
50  unsigned int _im_height;
51 
52  // internal values
53  int _wave_1;
54 
55 };
56 
57 inline WaveFilter::WaveFilter(double iBaseSize, Image& iImage)
58 {
59  _ii = iImage.getIntegralImage();
60  _im_width = iImage.getWidth();
61  _im_height = iImage.getHeight();
62 
63  _wave_1 = (int)iBaseSize;
64 }
65 
66 #define CALC_INTEGRAL_SURFACE(II, STARTX, ENDX, STARTY, ENDY) \
67  (II[ENDY+1][ENDX+1] + II[STARTY][STARTX] - II[ENDY+1][STARTX] - II[STARTY][ENDX+1])
68 
69 inline double WaveFilter::getWx(unsigned int x, unsigned int y)
70 {
71  return - CALC_INTEGRAL_SURFACE(_ii, x - _wave_1, x, y - _wave_1, y + _wave_1 )
72  + CALC_INTEGRAL_SURFACE(_ii, x, x + _wave_1, y - _wave_1, y + _wave_1 );
73 }
74 
75 inline double WaveFilter::getWy(unsigned int x, unsigned int y)
76 {
77  return + CALC_INTEGRAL_SURFACE(_ii,x - _wave_1, x + _wave_1, y - _wave_1, y )
78  - CALC_INTEGRAL_SURFACE(_ii,x - _wave_1, x + _wave_1, y, y + _wave_1 );
79 }
80 
81 inline bool WaveFilter::checkBounds(int x, int y) const
82 {
83  return ( x > _wave_1 && x + _wave_1 < (int)_im_width - 1
84  && y > _wave_1 && y + _wave_1 < (int)_im_height - 1);
85 }
86 
87 // versions without precomputed width
88 inline double WaveFilter::getSum(unsigned int x, unsigned int y, int s)
89 {
90  return CALC_INTEGRAL_SURFACE(_ii, x - s, x + s, y - s, y + s );
91 }
92 
93 inline double WaveFilter::getWx(unsigned int x, unsigned int y, int _wave_1)
94 {
95  return - CALC_INTEGRAL_SURFACE(_ii, x - _wave_1, x, y - _wave_1, y + _wave_1 )
96  + CALC_INTEGRAL_SURFACE(_ii, x, x + _wave_1, y - _wave_1, y + _wave_1 );
97 }
98 
99 inline double WaveFilter::getWy(unsigned int x, unsigned int y, int _wave_1)
100 {
101  return + CALC_INTEGRAL_SURFACE(_ii,x - _wave_1, x + _wave_1, y - _wave_1, y )
102  - CALC_INTEGRAL_SURFACE(_ii,x - _wave_1, x + _wave_1, y, y + _wave_1 );
103 }
104 
105 inline bool WaveFilter::checkBounds(int x, int y, int _wave_1) const
106 {
107  return ( x > _wave_1 && x + _wave_1 < (int)_im_width - 1
108  && y > _wave_1 && y + _wave_1 < (int)_im_height - 1);
109 }
110 
111 } // namespace lfeat
112 
113 #endif //__lfeat_wavefilter_h
bool checkBounds(int x, int y) const
Definition: WaveFilter.h:81
unsigned int getWidth()
Definition: Image.h:54
unsigned int getHeight()
Definition: Image.h:58
WaveFilter(double iBaseSize, Image &iImage)
Definition: WaveFilter.h:57
double ** getIntegralImage()
Definition: Image.h:50
double getWy(unsigned int x, unsigned int y)
Definition: WaveFilter.h:75
double getWx(unsigned int x, unsigned int y)
Definition: WaveFilter.h:69
double ** _ii
Definition: WaveFilter.h:48
double getSum(unsigned int x, unsigned int y, int scale)
Definition: WaveFilter.h:88
unsigned int _im_width
Definition: WaveFilter.h:49
unsigned int _im_height
Definition: WaveFilter.h:50
#define CALC_INTEGRAL_SURFACE(II, STARTX, ENDX, STARTY, ENDY)
Definition: WaveFilter.h:66