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
Fundamental class template for arrays of equal-sized images.
Definition: imagecontainer.hxx:73
linalg::TemporaryMatrix< T > sin(MultiArrayView< 2, T, C > const &v)
virtual void resizeImages(const Diff2D &newSize)
Definition: gaborfilter.hxx:378
linalg::TemporaryMatrix< T > exp(MultiArrayView< 2, T, C > const &v)
double radialGaborSigma(double centerFrequency)
Calculate sensible radial sigma for given parameters.
Definition: gaborfilter.hxx:212
Two dimensional difference vector.
Definition: diff2d.hxx:185
int scaleCount() const
Definition: gaborfilter.hxx:386
double maxCenterFrequency()
Definition: gaborfilter.hxx:410
double angularGaborSigma(int directionCount, double centerFrequency)
Calculate sensible angular sigma for given parameters.
Definition: gaborfilter.hxx:255
void setMaxCenterFrequency(double maxCenterFrequency)
Definition: gaborfilter.hxx:416
Two dimensional size object.
Definition: diff2d.hxx:482
void setDirectionScaleCounts(int directionCount, int scaleCount)
Definition: gaborfilter.hxx:397
int directionCount() const
Definition: gaborfilter.hxx:391
int filterIndex(int direction, int scale) const
Definition: gaborfilter.hxx:360
size_type size() const
Definition: imagecontainer.hxx:229
GaborFilterFamily(int width=stdFilterSize, int height=-1, int directionCount=stdDirectionCount, int scaleCount=stdScaleCount, double maxCenterFrequency=3.0/8.0, Alloc const &alloc=Alloc())
Definition: gaborfilter.hxx:339
linalg::TemporaryMatrix< T > log(MultiArrayView< 2, T, C > const &v)
ImageType const & getFilter(int direction, int scale) const
Definition: gaborfilter.hxx:371
Family of gabor filters of different scale and direction.
Definition: gaborfilter.hxx:289
void resize(size_type newSize)
Definition: imagecontainer.hxx:311
linalg::TemporaryMatrix< T > tan(MultiArrayView< 2, T, C > const &v)
void createGaborFilter(...)
Create a gabor filter in frequency space.
linalg::TemporaryMatrix< T > cos(MultiArrayView< 2, T, C > const &v)
virtual void resizeImages(const Diff2D &newSize)
Definition: imagecontainer.hxx:419
GaborFilterFamily(const Diff2D &size, int directionCount=stdDirectionCount, int scaleCount=stdScaleCount, double maxCenterFrequency=3.0/8.0, Alloc const &alloc=Alloc())
Definition: gaborfilter.hxx:323
SquareRootTraits< FixedPoint< IntBits, FracBits > >::SquareRootResult sqrt(FixedPoint< IntBits, FracBits > v)
square root.
Definition: fixedpoint.hxx:616