[bf78f2]: src / libpanomatic / localfeatures / BoxFilter.h  Maximize  Restore  History

Download this file

162 lines (123 with data), 4.8 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
/*
* Copyright (C) 2007-2008 Anael Orlinski
*
* This file is part of Panomatic.
*
* Panomatic is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* Panomatic is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Panomatic; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef __lfeat_boxfilter_h
#define __lfeat_boxfilter_h
#include "MathStuff.h"
namespace lfeat {
class Image;
class BoxFilter
{
public:
BoxFilter(double iBaseSize, Image& iImage);
void setY(unsigned int y);
double getDxxWithX(unsigned int x) const;
double getDyyWithX(unsigned int x) const;
double getDxyWithX(unsigned int x) const;
double getDetWithX(unsigned int x) const;
bool checkBounds(int x, int y) const;
// orig image info
double** _ii;
unsigned int _im_width;
unsigned int _im_height;
int _basesize;
// precomp values for det
double _sqCorrectFactor;
// the relative values of rectangle position for the first derivatives on x
int _lxy_d2;
// new ones
int _lxx_x_mid;
int _lxx_x_right;
int _lxx_y_bottom;
// stored Y
unsigned int _y_minus_lxx_y_bottom;
unsigned int _y_plus_lxx_y_bottom;
unsigned int _y_minus_lxx_x_right;
unsigned int _y_plus_lxx_x_right;
unsigned int _y_minus_lxx_x_mid;
unsigned int _y_plus_lxx_x_mid;
unsigned int _y_minus_lxy_d2;
unsigned int _y_plus_lxy_d2;
unsigned int _y;
};
inline BoxFilter::BoxFilter(double iBaseSize, Image& iImage)
{
_ii = iImage.getIntegralImage();
_im_width = iImage.getWidth();
_im_height = iImage.getHeight();
_basesize = Math::Round(iBaseSize); // convert to integer
// precomputed values for det
double aCorrectFactor = 9.0 / (iBaseSize * iBaseSize);
_sqCorrectFactor = aCorrectFactor * aCorrectFactor;
// the values for lxy are all positive. will negate in the getDxy
_lxy_d2 = ((int)(iBaseSize * 3) - 1) / 2 - 1;
// new ones
_lxx_x_mid = _basesize / 2;
_lxx_x_right = _lxx_x_mid + _basesize;
_lxx_y_bottom = _lxx_x_mid * 2;
}
#define CALC_INTEGRAL_SURFACE(II, STARTX, ENDX, STARTY, ENDY) \
(II[ENDY+1][ENDX+1] + II[STARTY][STARTX] - II[ENDY+1][STARTX] - II[STARTY][ENDX+1])
inline double BoxFilter::getDxxWithX(unsigned int x) const
{
return CALC_INTEGRAL_SURFACE(_ii,x - _lxx_x_right, x + _lxx_x_right, _y_minus_lxx_y_bottom, _y_plus_lxx_y_bottom)
- 3.0 * CALC_INTEGRAL_SURFACE(_ii,x - _lxx_x_mid, x + _lxx_x_mid, _y_minus_lxx_y_bottom, _y_plus_lxx_y_bottom);
}
inline double BoxFilter::getDyyWithX(unsigned int x) const
{
// calculates the Lyy convolution a point x,y with filter base size, using integral image
// use the values of Lxx, but rotate them.
return CALC_INTEGRAL_SURFACE(_ii, x - _lxx_y_bottom, x + _lxx_y_bottom, _y_minus_lxx_x_right, _y_plus_lxx_x_right)
- 3.0 * CALC_INTEGRAL_SURFACE(_ii, x - _lxx_y_bottom, x + _lxx_y_bottom, _y_minus_lxx_x_mid, _y_plus_lxx_x_mid);
}
inline double BoxFilter::getDxyWithX(unsigned int x) const
{
// calculates the Lxy convolution a point x,y with filter base size, using integral image
return CALC_INTEGRAL_SURFACE(_ii, x, x + _lxy_d2, _y, _y_plus_lxy_d2)
+ CALC_INTEGRAL_SURFACE(_ii, x - _lxy_d2, x, _y_minus_lxy_d2, _y)
- CALC_INTEGRAL_SURFACE(_ii, x, x + _lxy_d2, _y_minus_lxy_d2, _y)
- CALC_INTEGRAL_SURFACE(_ii, x - _lxy_d2, x, _y, _y_plus_lxy_d2);
}
#undef CALC_INTEGRAL_SURFACE
inline double BoxFilter::getDetWithX(unsigned int x) const
{
double aDxy = getDxyWithX(x) * 0.9 * 2 / 3.0;
double aDxx = getDxxWithX(x);
double aDyy = getDyyWithX(x);
return ((aDxx * aDyy) - (aDxy * aDxy)) * _sqCorrectFactor;
}
inline void BoxFilter::setY(unsigned int y)
{
_y_minus_lxx_y_bottom = y - _lxx_y_bottom;
_y_plus_lxx_y_bottom = y + _lxx_y_bottom;
_y_minus_lxx_x_right = y - _lxx_x_right;
_y_plus_lxx_x_right = y + _lxx_x_right;
_y_minus_lxx_x_mid = y - _lxx_x_mid;
_y_plus_lxx_x_mid = y + _lxx_x_mid;
_y_minus_lxy_d2 = y - _lxy_d2;
_y_plus_lxy_d2 = y + _lxy_d2;
_y = y;
}
inline bool BoxFilter::checkBounds(int x, int y) const
{
return ( x > _lxx_x_right && x + _lxx_x_right < (int)_im_width - 1
&& y > _lxx_x_right && y + _lxx_x_right < (int)_im_height - 1);
}
} // namespace lfeat
#endif //__lfeat_boxfilter_h

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:





No, thanks