Hugintrunk  0.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
BoxFilter.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_boxfilter_h
22 #define __lfeat_boxfilter_h
23 
24 #include "MathStuff.h"
25 #include "hugin_math/hugin_math.h"
26 
27 namespace lfeat
28 {
29 
30 class Image;
31 
32 class BoxFilter
33 {
34 public:
35  BoxFilter(double iBaseSize, Image& iImage);
36 
37  void setY(unsigned int y);
38  double getDxxWithX(unsigned int x) const;
39  double getDyyWithX(unsigned int x) const;
40  double getDxyWithX(unsigned int x) const;
41  double getDetWithX(unsigned int x) const;
42 
43  bool checkBounds(int x, int y) const;
44 
45  // orig image info
46  double** _ii;
47  unsigned int _im_width;
48  unsigned int _im_height;
49 
50  int _basesize;
51 
52  // precomp values for det
54 
55 
56  // the relative values of rectangle position for the first derivatives on x
57  int _lxy_d2;
58 
59  // new ones
63 
64  // stored Y
65 
66  unsigned int _y_minus_lxx_y_bottom;
67  unsigned int _y_plus_lxx_y_bottom;
68  unsigned int _y_minus_lxx_x_right;
69  unsigned int _y_plus_lxx_x_right;
70  unsigned int _y_minus_lxx_x_mid;
71  unsigned int _y_plus_lxx_x_mid;
72  unsigned int _y_minus_lxy_d2;
73  unsigned int _y_plus_lxy_d2;
74  unsigned int _y;
75 
76 };
77 
78 inline BoxFilter::BoxFilter(double iBaseSize, Image& iImage)
79 {
80  _ii = iImage.getIntegralImage();
81  _im_width = iImage.getWidth();
82  _im_height = iImage.getHeight();
83 
84  _basesize = hugin_utils::roundi(iBaseSize); // convert to integer
85 
86 
87  // precomputed values for det
88  double aCorrectFactor = 9.0 / (iBaseSize * iBaseSize);
89  _sqCorrectFactor = aCorrectFactor * aCorrectFactor;
90 
91  // the values for lxy are all positive. will negate in the getDxy
92  _lxy_d2 = ((int)(iBaseSize * 3) - 1) / 2 - 1;
93 
94  // new ones
95  _lxx_x_mid = _basesize / 2;
98  setY(0);
99 
100 }
101 
102 #define CALC_INTEGRAL_SURFACE(II, STARTX, ENDX, STARTY, ENDY) \
103  (II[ENDY+1][ENDX+1] + II[STARTY][STARTX] - II[ENDY+1][STARTX] - II[STARTY][ENDX+1])
104 
105 inline double BoxFilter::getDxxWithX(unsigned int x) const
106 {
109 }
110 
111 inline double BoxFilter::getDyyWithX(unsigned int x) const
112 {
113  // calculates the Lyy convolution a point x,y with filter base size, using integral image
114  // use the values of Lxx, but rotate them.
117 
118 }
119 
120 inline double BoxFilter::getDxyWithX(unsigned int x) const
121 {
122  // calculates the Lxy convolution a point x,y with filter base size, using integral image
123 
128 }
129 
130 #undef CALC_INTEGRAL_SURFACE
131 
132 inline double BoxFilter::getDetWithX(unsigned int x) const
133 {
134  double aDxy = getDxyWithX(x) * 0.9 * 2 / 3.0;
135  double aDxx = getDxxWithX(x);
136  double aDyy = getDyyWithX(x);
137 
138  return ((aDxx * aDyy) - (aDxy * aDxy)) * _sqCorrectFactor;
139 }
140 
141 inline void BoxFilter::setY(unsigned int y)
142 {
149  _y_minus_lxy_d2 = y - _lxy_d2;
150  _y_plus_lxy_d2 = y + _lxy_d2;
151  _y = y;
152 
153 }
154 
155 inline bool BoxFilter::checkBounds(int x, int y) const
156 {
157  return ( x > _lxx_x_right && x + _lxx_x_right < (int)_im_width - 1
158  && y > _lxx_x_right && y + _lxx_x_right < (int)_im_height - 1);
159 }
160 
161 } // namespace lfeat
162 
163 #endif //__lfeat_boxfilter_h
unsigned int _y_minus_lxx_y_bottom
Definition: BoxFilter.h:66
unsigned int _y_plus_lxx_x_right
Definition: BoxFilter.h:69
int roundi(T x)
Definition: hugin_math.h:73
BoxFilter(double iBaseSize, Image &iImage)
Definition: BoxFilter.h:78
unsigned int getWidth()
Definition: Image.h:54
misc math function &amp; classes used by other parts of the program
#define CALC_INTEGRAL_SURFACE(II, STARTX, ENDX, STARTY, ENDY)
Definition: BoxFilter.h:102
double getDyyWithX(unsigned int x) const
Definition: BoxFilter.h:111
unsigned int _y_minus_lxy_d2
Definition: BoxFilter.h:72
unsigned int getHeight()
Definition: Image.h:58
unsigned int _im_width
Definition: BoxFilter.h:47
double getDetWithX(unsigned int x) const
Definition: BoxFilter.h:132
bool checkBounds(int x, int y) const
Definition: BoxFilter.h:155
double ** _ii
Definition: BoxFilter.h:46
void setY(unsigned int y)
Definition: BoxFilter.h:141
double getDxyWithX(unsigned int x) const
Definition: BoxFilter.h:120
double ** getIntegralImage()
Definition: Image.h:50
unsigned int _y_plus_lxx_x_mid
Definition: BoxFilter.h:71
double getDxxWithX(unsigned int x) const
Definition: BoxFilter.h:105
unsigned int _y_minus_lxx_x_mid
Definition: BoxFilter.h:70
unsigned int _y_minus_lxx_x_right
Definition: BoxFilter.h:68
unsigned int _y
Definition: BoxFilter.h:74
unsigned int _y_plus_lxy_d2
Definition: BoxFilter.h:73
double _sqCorrectFactor
Definition: BoxFilter.h:53
unsigned int _y_plus_lxx_y_bottom
Definition: BoxFilter.h:67
unsigned int _im_height
Definition: BoxFilter.h:48