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"
47#include "multi_shape.hxx"
139template <
class DestImageIterator,
class DestAccessor>
141 DestImageIterator destLowerRight, DestAccessor da,
142 double orientation,
double centerFrequency,
143 double angularSigma,
double radialSigma)
145 int w = int(destLowerRight.x - destUpperLeft.x);
146 int h = int(destLowerRight.y - destUpperLeft.y);
148 double squaredSum = 0.0;
149 double cosTheta= VIGRA_CSTD::cos(orientation);
150 double sinTheta= VIGRA_CSTD::sin(orientation);
152 double radialSigma2 = radialSigma*radialSigma;
153 double angularSigma2 = angularSigma*angularSigma;
155 double wscale = w % 1 ?
158 double hscale = h % 1 ?
162 int dcX= (w+1)/2, dcY= (h+1)/2;
165 for (
int y=0; y<h; y++, destUpperLeft.y++ )
167 typename DestImageIterator::row_iterator dix = destUpperLeft.rowIterator();
169 v = hscale * ((h - (y - dcY))%h - dcY);
170 for (
int x=0; x<w; x++, dix++ )
172 u= wscale*((x - dcX + w)%w - dcX);
174 double uu = cosTheta*u + sinTheta*v - centerFrequency;
175 double vv = -sinTheta*u + cosTheta*v;
178 gabor = VIGRA_CSTD::exp(-0.5*(uu*uu / radialSigma2 + vv*vv / angularSigma2));
179 squaredSum += gabor * gabor;
180 da.set( gabor, dix );
183 destUpperLeft.y -= h;
186 double dcValue = da(destUpperLeft);
187 squaredSum -= dcValue * dcValue;
188 da.set( 0.0, destUpperLeft );
191 double factor = VIGRA_CSTD::sqrt(squaredSum);
192 for (
int y=0; y<h; y++, destUpperLeft.y++ )
194 typename DestImageIterator::row_iterator dix = destUpperLeft.rowIterator();
196 for (
int x=0; x<w; x++, dix++ )
198 da.set( da(dix) / factor, dix );
203template <
class DestImageIterator,
class DestAccessor>
205createGaborFilter(triple<DestImageIterator, DestImageIterator, DestAccessor> dest,
206 double orientation,
double centerFrequency,
207 double angularSigma,
double radialSigma)
210 orientation, centerFrequency,
211 angularSigma, radialSigma);
214template <
class T,
class S>
217 double orientation,
double centerFrequency,
218 double angularSigma,
double radialSigma)
221 orientation, centerFrequency,
222 angularSigma, radialSigma);
247 double sfactor = 3.0 * VIGRA_CSTD::sqrt(VIGRA_CSTD::log(4.0));
248 return centerFrequency / sfactor;
290 return VIGRA_CSTD::tan(M_PI/directionCount/2.0) * centerFrequency
291 * VIGRA_CSTD::sqrt(8.0 / (9 * VIGRA_CSTD::log(4.0)));
319template <
class ImageType,
320 class Alloc =
typename std::allocator_traits<typename ImageType::allocator_type>::template rebind_alloc<ImageType> >
325 int scaleCount_, directionCount_;
326 double maxCenterFrequency_;
331 for(
int direction= 0; direction<directionCount_; direction++)
332 for(
int scale= 0; scale<scaleCount_; scale++)
335 double centerFrequency =
336 maxCenterFrequency_ / VIGRA_CSTD::pow(2.0, (
double)scale);
338 angle, centerFrequency,
345 enum { stdFilterSize= 128, stdDirectionCount= 6, stdScaleCount= 4 };
358 Alloc
const & alloc = Alloc())
374 Alloc
const & alloc = Alloc())
376 Size2D(width, height > 0 ? height : width), alloc),
403 ImageType
const &
getFilter(
int direction,
int scale)
const
405 return this->images_[
filterIndex(direction, scale)];
419 {
return scaleCount_; }
424 {
return directionCount_; }
443 {
return maxCenterFrequency_; }
Two dimensional difference vector.
Definition diff2d.hxx:186
Family of gabor filters of different scale and direction.
Definition gaborfilter.hxx:323
int scaleCount() const
Definition gaborfilter.hxx:418
void setMaxCenterFrequency(double maxCenterFrequency)
Definition gaborfilter.hxx:448
double maxCenterFrequency()
Definition gaborfilter.hxx:442
GaborFilterFamily(const Diff2D &size, int directionCount=stdDirectionCount, int scaleCount=stdScaleCount, double maxCenterFrequency=3.0/8.0, Alloc const &alloc=Alloc())
Definition gaborfilter.hxx:355
virtual void resizeImages(const Diff2D &newSize)
Definition gaborfilter.hxx:410
ImageType const & getFilter(int direction, int scale) const
Definition gaborfilter.hxx:403
int filterIndex(int direction, int scale) const
Definition gaborfilter.hxx:392
void setDirectionScaleCounts(int directionCount, int scaleCount)
Definition gaborfilter.hxx:429
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:371
int directionCount() const
Definition gaborfilter.hxx:423
Fundamental class template for arrays of equal-sized images.
Definition imagecontainer.hxx:74
virtual void resizeImages(const Diff2D &newSize)
Definition imagecontainer.hxx:419
size_type size() const
Definition imagecontainer.hxx:229
void resize(size_type newSize)
Definition imagecontainer.hxx:311
Two dimensional size object.
Definition diff2d.hxx:483
void createGaborFilter(...)
Create a gabor filter in frequency space.
double angularGaborSigma(int directionCount, double centerFrequency)
Calculate sensible angular sigma for given parameters.
Definition gaborfilter.hxx:288
double radialGaborSigma(double centerFrequency)
Calculate sensible radial sigma for given parameters.
Definition gaborfilter.hxx:245