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"
138 template <
class DestImageIterator,
class DestAccessor>
140 DestImageIterator destLowerRight, DestAccessor da,
141 double orientation,
double centerFrequency,
142 double angularSigma,
double radialSigma)
144 int w = int(destLowerRight.x - destUpperLeft.x);
145 int h = int(destLowerRight.y - destUpperLeft.y);
147 double squaredSum = 0.0;
151 double radialSigma2 = radialSigma*radialSigma;
152 double angularSigma2 = angularSigma*angularSigma;
154 double wscale = w % 1 ?
157 double hscale = h % 1 ?
161 int dcX= (w+1)/2, dcY= (h+1)/2;
164 for (
int y=0; y<h; y++, destUpperLeft.y++ )
166 typename DestImageIterator::row_iterator dix = destUpperLeft.rowIterator();
168 v = hscale * ((h - (y - dcY))%h - dcY);
169 for (
int x=0; x<w; x++, dix++ )
171 u= wscale*((x - dcX + w)%w - dcX);
173 double uu = cosTheta*u + sinTheta*v - centerFrequency;
174 double vv = -sinTheta*u + cosTheta*v;
177 gabor =
VIGRA_CSTD::exp(-0.5*(uu*uu / radialSigma2 + vv*vv / angularSigma2));
178 squaredSum += gabor * gabor;
179 da.set( gabor, dix );
182 destUpperLeft.y -= h;
185 double dcValue = da(destUpperLeft);
186 squaredSum -= dcValue * dcValue;
187 da.set( 0.0, destUpperLeft );
191 for (
int y=0; y<h; y++, destUpperLeft.y++ )
193 typename DestImageIterator::row_iterator dix = destUpperLeft.rowIterator();
195 for (
int x=0; x<w; x++, dix++ )
197 da.set( da(dix) / factor, dix );
202 template <
class DestImageIterator,
class DestAccessor>
204 createGaborFilter(triple<DestImageIterator, DestImageIterator, DestAccessor> dest,
205 double orientation,
double centerFrequency,
206 double angularSigma,
double radialSigma)
209 orientation, centerFrequency,
210 angularSigma, radialSigma);
213 template <
class T,
class S>
216 double orientation,
double centerFrequency,
217 double angularSigma,
double radialSigma)
220 orientation, centerFrequency,
221 angularSigma, radialSigma);
247 return centerFrequency / sfactor;
318 template <
class ImageType,
319 class Alloc =
typename ImageType::allocator_type::template rebind<ImageType>::other >
324 int scaleCount_, directionCount_;
325 double maxCenterFrequency_;
330 for(
int direction= 0; direction<directionCount_; direction++)
331 for(
int scale= 0; scale<scaleCount_; scale++)
334 double centerFrequency =
335 maxCenterFrequency_ / VIGRA_CSTD::pow(2.0, (
double)scale);
337 angle, centerFrequency,
344 enum { stdFilterSize= 128, stdDirectionCount= 6, stdScaleCount= 4 };
357 Alloc
const & alloc = Alloc())
373 Alloc
const & alloc = Alloc())
375 Size2D(width, height > 0 ? height : width), alloc),
402 ImageType
const &
getFilter(
int direction,
int scale)
const
404 return this->images_[
filterIndex(direction, scale)];
418 {
return scaleCount_; }
423 {
return directionCount_; }
430 this->
resize(directionCount * scaleCount);
442 {
return maxCenterFrequency_; }
458 #endif // VIGRA_GABORFILTER_HXX
Fundamental class template for arrays of equal-sized images.
Definition: imagecontainer.hxx:72
linalg::TemporaryMatrix< T > sin(MultiArrayView< 2, T, C > const &v)
virtual void resizeImages(const Diff2D &newSize)
Definition: gaborfilter.hxx:409
linalg::TemporaryMatrix< T > exp(MultiArrayView< 2, T, C > const &v)
double radialGaborSigma(double centerFrequency)
Calculate sensible radial sigma for given parameters.
Definition: gaborfilter.hxx:244
Two dimensional difference vector.
Definition: diff2d.hxx:185
int scaleCount() const
Definition: gaborfilter.hxx:417
double maxCenterFrequency()
Definition: gaborfilter.hxx:441
double angularGaborSigma(int directionCount, double centerFrequency)
Calculate sensible angular sigma for given parameters.
Definition: gaborfilter.hxx:287
void setMaxCenterFrequency(double maxCenterFrequency)
Definition: gaborfilter.hxx:447
Two dimensional size object.
Definition: diff2d.hxx:482
void setDirectionScaleCounts(int directionCount, int scaleCount)
Definition: gaborfilter.hxx:428
int directionCount() const
Definition: gaborfilter.hxx:422
int filterIndex(int direction, int scale) const
Definition: gaborfilter.hxx:391
size_type size() const
Definition: imagecontainer.hxx:228
doxygen_overloaded_function(template<...> void separableConvolveBlockwise) template< unsigned int N
Separated convolution on ChunkedArrays.
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:370
linalg::TemporaryMatrix< T > log(MultiArrayView< 2, T, C > const &v)
ImageType const & getFilter(int direction, int scale) const
Definition: gaborfilter.hxx:402
Family of gabor filters of different scale and direction.
Definition: gaborfilter.hxx:320
void resize(size_type newSize)
Definition: imagecontainer.hxx:310
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:418
GaborFilterFamily(const Diff2D &size, int directionCount=stdDirectionCount, int scaleCount=stdScaleCount, double maxCenterFrequency=3.0/8.0, Alloc const &alloc=Alloc())
Definition: gaborfilter.hxx:354
SquareRootTraits< FixedPoint< IntBits, FracBits > >::SquareRootResult sqrt(FixedPoint< IntBits, FracBits > v)
square root.
Definition: fixedpoint.hxx:616