WaveFilter.h

Go to the documentation of this file.
00001 /*
00002 * Copyright (C) 2007-2008 Anael Orlinski
00003 *
00004 * This file is part of Panomatic.
00005 *
00006 * Panomatic is free software; you can redistribute it and/or modify
00007 * it under the terms of the GNU General Public License as published by
00008 * the Free Software Foundation; either version 2 of the License, or
00009 * (at your option) any later version.
00010 *
00011 * Panomatic is distributed in the hope that it will be useful,
00012 * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014 * GNU General Public License for more details.
00015 *
00016 * You should have received a copy of the GNU General Public License
00017 * along with Panomatic; if not, write to the Free Software
00018 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00019 */
00020 
00021 #ifndef __lfeat_wavefilter_h
00022 #define __lfeat_wavefilter_h
00023 
00024 namespace lfeat
00025 {
00026 
00027 class Image;
00028 
00029 class WaveFilter
00030 {
00031 public:
00032     WaveFilter(double iBaseSize, Image& iImage);
00033 
00034     double getWx(unsigned int x, unsigned int y);
00035     double getWy(unsigned int x, unsigned int y);
00036 
00037     bool checkBounds(int x, int y) const;
00038 
00039     double getSum(unsigned int x, unsigned int y, int scale);
00040     double getWx(unsigned int x, unsigned int y, int scale);
00041     double getWy(unsigned int x, unsigned int y, int scale);
00042 
00043     bool checkBounds(int x, int y, int scale) const;
00044 
00045 private:
00046 
00047     // orig image info
00048     double**            _ii;
00049     unsigned int        _im_width;
00050     unsigned int        _im_height;
00051 
00052     // internal values
00053     int _wave_1;
00054 
00055 };
00056 
00057 inline WaveFilter::WaveFilter(double iBaseSize, Image& iImage)
00058 {
00059     _ii = iImage.getIntegralImage();
00060     _im_width = iImage.getWidth();
00061     _im_height = iImage.getHeight();
00062 
00063     _wave_1 = (int)iBaseSize;
00064 }
00065 
00066 #define CALC_INTEGRAL_SURFACE(II, STARTX, ENDX, STARTY, ENDY) \
00067     (II[ENDY+1][ENDX+1] + II[STARTY][STARTX] - II[ENDY+1][STARTX] - II[STARTY][ENDX+1])
00068 
00069 inline double WaveFilter::getWx(unsigned int x, unsigned int y)
00070 {
00071     return      -       CALC_INTEGRAL_SURFACE(_ii, x - _wave_1, x,                              y - _wave_1,    y + _wave_1     )
00072             +   CALC_INTEGRAL_SURFACE(_ii,      x,                              x + _wave_1,    y - _wave_1,    y + _wave_1     );
00073 }
00074 
00075 inline double WaveFilter::getWy(unsigned int x, unsigned int y)
00076 {
00077     return      +       CALC_INTEGRAL_SURFACE(_ii,x - _wave_1,  x + _wave_1,    y - _wave_1,    y                       )
00078             -   CALC_INTEGRAL_SURFACE(_ii,x - _wave_1,  x + _wave_1,    y,                              y + _wave_1     );
00079 }
00080 
00081 inline bool WaveFilter::checkBounds(int x, int y) const
00082 {
00083     return (    x > _wave_1 && x + _wave_1 < (int)_im_width - 1
00084                 &&      y > _wave_1 && y + _wave_1 < (int)_im_height - 1);
00085 }
00086 
00087 // versions without precomputed width
00088 inline double WaveFilter::getSum(unsigned int x, unsigned int y, int s)
00089 {
00090     return      CALC_INTEGRAL_SURFACE(_ii, x - s, x + s, y - s, y + s );
00091 }
00092 
00093 inline double WaveFilter::getWx(unsigned int x, unsigned int y, int _wave_1)
00094 {
00095     return      -       CALC_INTEGRAL_SURFACE(_ii, x - _wave_1, x,                              y - _wave_1,    y + _wave_1     )
00096             +   CALC_INTEGRAL_SURFACE(_ii,      x,                              x + _wave_1,    y - _wave_1,    y + _wave_1     );
00097 }
00098 
00099 inline double WaveFilter::getWy(unsigned int x, unsigned int y, int _wave_1)
00100 {
00101     return      +       CALC_INTEGRAL_SURFACE(_ii,x - _wave_1,  x + _wave_1,    y - _wave_1,    y                       )
00102             -   CALC_INTEGRAL_SURFACE(_ii,x - _wave_1,  x + _wave_1,    y,                              y + _wave_1     );
00103 }
00104 
00105 inline bool WaveFilter::checkBounds(int x, int y, int _wave_1) const
00106 {
00107     return (    x > _wave_1 && x + _wave_1 < (int)_im_width - 1
00108                 &&      y > _wave_1 && y + _wave_1 < (int)_im_height - 1);
00109 }
00110 
00111 } // namespace lfeat
00112 
00113 #endif //__lfeat_wavefilter_h

Generated on 24 Oct 2014 for Hugintrunk by  doxygen 1.4.7