37 #ifndef VIGRA_GABORFILTER_HXX
38 #define VIGRA_GABORFILTER_HXX
40 #include "imagecontainer.hxx"
42 #include "stdimage.hxx"
43 #include "copyimage.hxx"
44 #include "transformimage.hxx"
45 #include "combineimages.hxx"
46 #include "utilities.hxx"
116 template <
class DestImageIterator,
class DestAccessor>
118 DestImageIterator destLowerRight, DestAccessor da,
119 double orientation,
double centerFrequency,
120 double angularSigma,
double radialSigma)
122 int w = int(destLowerRight.x - destUpperLeft.x);
123 int h = int(destLowerRight.y - destUpperLeft.y);
125 double squaredSum = 0.0;
129 double radialSigma2 = radialSigma*radialSigma;
130 double angularSigma2 = angularSigma*angularSigma;
132 double wscale = w % 1 ?
135 double hscale = h % 1 ?
139 int dcX= (w+1)/2, dcY= (h+1)/2;
142 for (
int y=0; y<h; y++, destUpperLeft.y++ )
144 typename DestImageIterator::row_iterator dix = destUpperLeft.rowIterator();
146 v = hscale * ((h - (y - dcY))%h - dcY);
147 for (
int x=0; x<w; x++, dix++ )
149 u= wscale*((x - dcX + w)%w - dcX);
151 double uu = cosTheta*u + sinTheta*v - centerFrequency;
152 double vv = -sinTheta*u + cosTheta*v;
155 gabor =
VIGRA_CSTD::exp(-0.5*(uu*uu / radialSigma2 + vv*vv / angularSigma2));
156 squaredSum += gabor * gabor;
157 da.set( gabor, dix );
160 destUpperLeft.y -= h;
163 double dcValue = da(destUpperLeft);
164 squaredSum -= dcValue * dcValue;
165 da.set( 0.0, destUpperLeft );
169 for (
int y=0; y<h; y++, destUpperLeft.y++ )
171 typename DestImageIterator::row_iterator dix = destUpperLeft.rowIterator();
173 for (
int x=0; x<w; x++, dix++ )
175 da.set( da(dix) / factor, dix );
180 template <
class DestImageIterator,
class DestAccessor>
184 double orientation,
double centerFrequency,
185 double angularSigma,
double radialSigma)
188 orientation, centerFrequency,
189 angularSigma, radialSigma);
215 return centerFrequency / sfactor;
287 template <
class ImageType,
288 class Alloc =
typename ImageType::allocator_type::template rebind<ImageType>::other >
293 int scaleCount_, directionCount_;
294 double maxCenterFrequency_;
299 for(
int direction= 0; direction<directionCount_; direction++)
300 for(
int scale= 0; scale<scaleCount_; scale++)
303 double centerFrequency =
304 maxCenterFrequency_ / VIGRA_CSTD::pow(2.0, (
double)scale);
306 angle, centerFrequency,
313 enum { stdFilterSize= 128, stdDirectionCount= 6, stdScaleCount= 4 };
326 Alloc
const & alloc = Alloc())
342 Alloc
const & alloc = Alloc())
344 Size2D(width, height > 0 ? height : width), alloc),
371 ImageType
const &
getFilter(
int direction,
int scale)
const
373 return this->images_[
filterIndex(direction, scale)];
387 {
return scaleCount_; }
392 {
return directionCount_; }
399 this->
resize(directionCount * scaleCount);
411 {
return maxCenterFrequency_; }
427 #endif // VIGRA_GABORFILTER_HXX