BoxFilter.h
Go to the documentation of this file.
00001 /*
00002 * This file is part of Parallel SURF, which implements the SURF algorithm
00003 * using multi-threading.
00004 *
00005 * Copyright (C) 2010 David Gossow
00006 *
00007 * It is based on the SURF implementation included in Pan-o-matic 0.9.4, 
00008 * written by Anael Orlinski.
00009 * 
00010 * Parallel SURF is free software; you can redistribute it and/or modify
00011 * it under the terms of the GNU General Public License as published by
00012 * the Free Software Foundation; either version 3 of the License, or
00013 * (at your option) any later version.
00014 * 
00015 * Parallel SURF is distributed in the hope that it will be useful,
00016 * but WITHOUT ANY WARRANTY; without even the implied warranty of
00017 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00018 * GNU General Public License for more details.
00019 * 
00020 * You should have received a copy of the GNU General Public License
00021 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
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         // orig image info
00047         double**        _ii;
00048         unsigned int    _im_width;
00049         unsigned int    _im_height;
00050 
00051         int _basesize;
00052 
00053         // precomp values for det
00054         double _sqCorrectFactor;
00055 
00056 
00057         // the relative values of rectangle position for the first derivatives on x
00058         int _lxy_d2;
00059 
00060         // new ones
00061         int _lxx_x_mid;
00062         int _lxx_x_right;
00063         int _lxx_y_bottom;
00064 
00065         // stored Y
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); // convert to integer
00086 
00087 
00088         // precomputed values for det
00089         double aCorrectFactor = 9.0 / (iBaseSize * iBaseSize);
00090         _sqCorrectFactor = aCorrectFactor * aCorrectFactor;
00091 
00092         // the values for lxy are all positive. will negate in the getDxy
00093         _lxy_d2 = ((int)(iBaseSize * 3) - 1) / 2 - 1;
00094 
00095         // new ones
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         // calculates the Lyy convolution a point x,y with filter base size, using integral image
00113         // use the values of Lxx, but rotate them.
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         // calculates the Lxy convolution a point x,y with filter base size, using integral image
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 } // namespace parallelsurf
00160 
00161 #endif //__parallelsurf_boxfilter_h


or_libs
Author(s): raphael
autogenerated on Mon Oct 6 2014 02:53:18