www.pudn.com > GPUVision_5-13-05-2.zip > GaborFilter.h
#ifndef _GABORFILTER_H
#define _GABORFILTER_H
#include "ConvolutionFilter.h"
class GaborFilter : public GenericFilter {
public:
GaborFilter(float frequency, float angle, int width, bool isCos);
~GaborFilter();
virtual void applyFilter(GPUVision *image1);
virtual void applyFilter(GPUVision *image1, GPUVision *image2);
void reset(float frequency, float angle, int width, bool isCos);
static void Gabor(double sigma, double thetad, int width, bool isCos, float* data) {
double theta = (PI*thetad)/180.0;
double w = (2*sigma)+.5;
double x, y,ePow;
int position = 0;
double xRot, yRot, x2Rot, y2Rot;
double sigma2 = 2.*sigma*sigma;
double step = (4.*sigma)/(double)width;
double tot = 0;
int innerCount, outerCount;
for(outerCount = 0, x = -w; outerCount < width/*x <=w*/; x+=step, outerCount++) {
for(innerCount = 0, y = -w; innerCount < width/*y <=w*/; y+=step, position++, innerCount++) {
xRot = x*cos(theta) + y*sin(theta);
yRot = y*cos(theta) - x*sin(theta);
x2Rot = xRot*xRot;
y2Rot = yRot*yRot;
ePow = pow(E, -(x2Rot+y2Rot)/(sigma2));
if(isCos) {
data[position] = cos(xRot)*ePow;
// cosGabor[position] = (cosGabor[position]+1)*.5; // this line is just so I can see it clearly
} else {
data[position] = sin(xRot)*ePow;
// sinGabor[position] = (sinGabor[position]+1)*.5; // this line is just so I can see it clearly
}
tot += data[position];
}
}
if(tot != 0) {
float minusVal = tot/(2*width*width);
tot = 0;
for(int i = 0; i < width*width; i++) {
data[i] -= minusVal;
tot += data[position];
}
}
if(tot != 0) {
bool whoops = true;
}
}
static void Gabor4(double sigma, double thetad, int width, bool isCos, float* data) {
double theta = (PI*thetad)/180.0;
double w = (2*sigma)+.5;
double x, y,ePow;
int position = 0;
double xRot, yRot, x2Rot, y2Rot;
double sigma2 = 2.*sigma*sigma;
double step = (4.*sigma)/(double)width;
double tot = 0;
int innerCount, outerCount;
for(outerCount = 0, x = -w; outerCount < width/*x <=w*/; x+=step, outerCount++) {
for(innerCount = 0, y = -w; innerCount < width/*y <=w*/; y+=step, position++, innerCount++) {
xRot = x*cos(theta) + y*sin(theta);
yRot = y*cos(theta) - x*sin(theta);
x2Rot = xRot*xRot;
y2Rot = yRot*yRot;
ePow = pow(E, -(x2Rot+y2Rot)/(sigma2));
if(isCos) {
data[4*position] = cos(xRot)*ePow/2.; // /2. so we go around -.5 to .5
data[4*position+1] = data[4*position];
data[4*position+2] = data[4*position];
data[4*position+3] = 1;
// cosGabor[position] = (cosGabor[position]+1)*.5; // this line is just so I can see it clearly
} else {
data[4*position] = sin(xRot)*ePow/2.;
data[4*position+1] = data[4*position];
data[4*position+2] = data[4*position];
data[4*position+3] = 1;
// sinGabor[position] = (sinGabor[position]+1)*.5; // this line is just so I can see it clearly
}
tot += data[position];
}
}
if(tot != 0) {
float minusVal = tot/(2*width*width);
tot = 0;
for(int i = 0; i < width*width; i++) {
data[4*i] -= minusVal;
data[4*i+1] -= minusVal;
data[4*i+2] -= minusVal;
tot += data[position];
}
}
if(tot != 0) {
bool whoops = true;
}
}
private:
// ConvolutionFilter *_convFilter;
// float* _data;
// unsigned int _iwidth;
// void _Gabor(float sigma, float thetad, int width, bool isCos, float* data);
};
#endif