Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #ifndef __parallelsurf_boxfilter_h
00025 #define __parallelsurf_boxfilter_h
00026
00027 #include "MathStuff.h"
00028
00029 namespace parallelsurf {
00030
00031 class Image;
00032
00033 class BoxFilter
00034 {
00035 public:
00036 BoxFilter(double iBaseSize, Image& iImage);
00037
00038 void setY(unsigned int y);
00039 double getDxxWithX(unsigned int x) const;
00040 double getDyyWithX(unsigned int x) const;
00041 double getDxyWithX(unsigned int x) const;
00042 double getDetWithX(unsigned int x) const;
00043
00044 bool checkBounds(int x, int y) const;
00045
00046
00047 double** _ii;
00048 unsigned int _im_width;
00049 unsigned int _im_height;
00050
00051 int _basesize;
00052
00053
00054 double _sqCorrectFactor;
00055
00056
00057
00058 int _lxy_d2;
00059
00060
00061 int _lxx_x_mid;
00062 int _lxx_x_right;
00063 int _lxx_y_bottom;
00064
00065
00066
00067 unsigned int _y_minus_lxx_y_bottom;
00068 unsigned int _y_plus_lxx_y_bottom;
00069 unsigned int _y_minus_lxx_x_right;
00070 unsigned int _y_plus_lxx_x_right;
00071 unsigned int _y_minus_lxx_x_mid;
00072 unsigned int _y_plus_lxx_x_mid;
00073 unsigned int _y_minus_lxy_d2;
00074 unsigned int _y_plus_lxy_d2;
00075 unsigned int _y;
00076
00077 };
00078
00079 inline BoxFilter::BoxFilter(double iBaseSize, Image& iImage)
00080 {
00081 _ii = iImage.getIntegralImage();
00082 _im_width = iImage.getWidth();
00083 _im_height = iImage.getHeight();
00084
00085 _basesize = Math::Round(iBaseSize);
00086
00087
00088
00089 double aCorrectFactor = 9.0 / (iBaseSize * iBaseSize);
00090 _sqCorrectFactor = aCorrectFactor * aCorrectFactor;
00091
00092
00093 _lxy_d2 = ((int)(iBaseSize * 3) - 1) / 2 - 1;
00094
00095
00096 _lxx_x_mid = _basesize / 2;
00097 _lxx_x_right = _lxx_x_mid + _basesize;
00098 _lxx_y_bottom = _lxx_x_mid * 2;
00099 }
00100
00101 #define CALC_INTEGRAL_SURFACE(II, STARTX, ENDX, STARTY, ENDY) \
00102 (II[ENDY+1][ENDX+1] + II[STARTY][STARTX] - II[ENDY+1][STARTX] - II[STARTY][ENDX+1])
00103
00104 inline double BoxFilter::getDxxWithX(unsigned int x) const
00105 {
00106 return CALC_INTEGRAL_SURFACE(_ii,x - _lxx_x_right, x + _lxx_x_right, _y_minus_lxx_y_bottom, _y_plus_lxx_y_bottom)
00107 - 3.0 * CALC_INTEGRAL_SURFACE(_ii,x - _lxx_x_mid, x + _lxx_x_mid, _y_minus_lxx_y_bottom, _y_plus_lxx_y_bottom);
00108 }
00109
00110 inline double BoxFilter::getDyyWithX(unsigned int x) const
00111 {
00112
00113
00114 return CALC_INTEGRAL_SURFACE(_ii, x - _lxx_y_bottom, x + _lxx_y_bottom, _y_minus_lxx_x_right, _y_plus_lxx_x_right)
00115 - 3.0 * CALC_INTEGRAL_SURFACE(_ii, x - _lxx_y_bottom, x + _lxx_y_bottom, _y_minus_lxx_x_mid, _y_plus_lxx_x_mid);
00116 }
00117
00118 inline double BoxFilter::getDxyWithX(unsigned int x) const
00119 {
00120
00121
00122 return CALC_INTEGRAL_SURFACE(_ii, x, x + _lxy_d2, _y, _y_plus_lxy_d2)
00123 + CALC_INTEGRAL_SURFACE(_ii, x - _lxy_d2, x, _y_minus_lxy_d2, _y)
00124 - CALC_INTEGRAL_SURFACE(_ii, x, x + _lxy_d2, _y_minus_lxy_d2, _y)
00125 - CALC_INTEGRAL_SURFACE(_ii, x - _lxy_d2, x, _y, _y_plus_lxy_d2);
00126 }
00127
00128 #undef CALC_INTEGRAL_SURFACE
00129
00130 inline double BoxFilter::getDetWithX(unsigned int x) const
00131 {
00132 double aDxy = getDxyWithX(x) * 0.9 * 2 / 3.0;
00133 double aDxx = getDxxWithX(x);
00134 double aDyy = getDyyWithX(x);
00135
00136 return ((aDxx * aDyy) - (aDxy * aDxy)) * _sqCorrectFactor;
00137 }
00138
00139 inline void BoxFilter::setY(unsigned int y)
00140 {
00141 _y_minus_lxx_y_bottom = y - _lxx_y_bottom;
00142 _y_plus_lxx_y_bottom = y + _lxx_y_bottom;
00143 _y_minus_lxx_x_right = y - _lxx_x_right;
00144 _y_plus_lxx_x_right = y + _lxx_x_right;
00145 _y_minus_lxx_x_mid = y - _lxx_x_mid;
00146 _y_plus_lxx_x_mid = y + _lxx_x_mid;
00147 _y_minus_lxy_d2 = y - _lxy_d2;
00148 _y_plus_lxy_d2 = y + _lxy_d2;
00149 _y = y;
00150
00151 }
00152
00153 inline bool BoxFilter::checkBounds(int x, int y) const
00154 {
00155 return ( x > _lxx_x_right && x + _lxx_x_right < (int)_im_width - 1
00156 && y > _lxx_x_right && y + _lxx_x_right < (int)_im_height - 1);
00157 }
00158
00159 }
00160
00161 #endif //__parallelsurf_boxfilter_h