-
void FFTGabor::GaborTransform(int * lpDIBBits, LONG lWidth, LONG lHeight, int Orientation, int Frequency, FFTGaborResult * result)
-
{
-
LONG i;
-
LONG j;
-
-
complex<double> *TD = new complex<double>[complexWidth * complexHeight];
-
complex<double> *FD = new complex<double>[complexWidth * complexHeight];
-
-
// 行
-
for(i = 0; i < lHeight; i++)
-
{
-
// 列
-
for(j = 0; j < lWidth; j++)
-
{
-
// 给时域赋值
-
TD[j + complexWidth * i] = complex<double>(lpDIBBits[j+lWidth * i], 0);
-
}
-
}
-
::FFT2(TD,complexWidth , complexHeight);
-
-
//::IFFT2(TD,256,256);
-
//在频域执行卷积
-
double scale = 1.0 / (complexWidth * complexHeight);
-
-
for( i=0; i<complexWidth * complexHeight; i++)
-
FD[i] = TD[i] * KernelFFT2[Orientation * 4 + Frequency][i] ; // * scale;
-
-
IFFT2(FD,complexWidth , complexHeight);
-
-
//计算均值、方差及结果
-
//计算均值并找出tmpMag中的最大最小值,以便调整到0~255,用于显示输出。
-
double min, max;
-
double Sum=0, Avg=0, Deta=0;
-
double tmpModulus=0;
-
double * tmpMag = new double[lWidth*lHeight] ;// [128][128] ;
-
int x ,y;
-
tmpModulus = sqrt(FD[(GaborHeight/2)*complexWidth+(GaborWidth/2)].real() *
-
FD[(GaborHeight/2)*complexWidth+(GaborWidth/2)].real() +
-
FD[(GaborHeight/2)*complexWidth+(GaborWidth/2)].imag() *
-
FD[(GaborHeight/2)*complexWidth+(GaborWidth/2)].imag());
-
min = max = tmpModulus;
-
for( y=(GaborHeight/2); y<(GaborHeight/2)+lHeight; y++){
-
for( x=(GaborWidth/2); x<(GaborWidth/2)+lWidth; x++)
-
{
-
tmpModulus = sqrt(FD[y*complexWidth+x].real() * FD[y*complexWidth+x].real() +
-
FD[y*complexWidth+x].imag() * FD[y*complexWidth+x].imag());
-
-
if(min>tmpModulus)
-
min = tmpModulus;
-
if(max<tmpModulus)
-
max = tmpModulus;
-
-
Sum += tmpModulus;
-
tmpMag[(y-(GaborHeight/2))* lWidth + (x-(GaborWidth/2))] = tmpModulus;
-
}
-
}
-
Avg = Sum / (lHeight * lWidth);
-
//计算方差
-
for( y=0; y < lHeight; y++){
-
for( x=0; x < lWidth; x++)
-
Deta += (tmpMag[y* lWidth + x] - Avg)*(tmpMag[y* lWidth + x] - Avg);
-
}
-
Deta = Deta / (lHeight * lWidth);
-
-
//计算magShow以及均值
-
scale = 255.0/(max-min);
-
-
for( y=0; y < lHeight; y++){
-
for( x=0; x < lWidth; x++)
-
{
-
result->magShow[y * lWidth + x] = (int)(scale*(tmpMag[y* lWidth + x]-min));
-
}
-
}
-
result->Avg = Avg;
-
result->Deta = Deta;
-
-
delete[] tmpMag;
-
-
delete[] FD;
-
delete[] TD;
-
}
-
-
void FFTGabor::intTocomplex(complex<double> * TD,int * lpDIBBits,LONG lWidth, LONG lHeight)
-
{
-
LONG i;
-
LONG j;
-
-
// complex<double> *TD = new complex<double>[complexWidth * complexHeight];
-
-
// 行
-
for(i = 0; i < lHeight; i++)
-
{
-
// 列
-
for(j = 0; j < lWidth; j++)
-
{
-
// 给时域赋值
-
TD[j + complexWidth * i] = complex<double>(lpDIBBits[j+lWidth * i], 0);
-
}
-
}
-
::FFT2(TD,complexWidth , complexHeight);
-
-
}
-
void FFTGabor::GaborTransform(complex<double> *TD, LONG lWidth, LONG lHeight, double * TransformResult)
-
{
-
// 循环变量
-
LONG i;
-
// LONG j;
-
int Orientation, Frequency ;
-
// 分配内存
-
complex<double> *FD = new complex<double>[complexWidth * complexHeight];
-
-
double scale = 1.0 / (complexWidth * complexHeight);
-
double Sum=0, Avg=0, Deta=0;
-
double tmpModulus=0;
-
double * tmpMag = new double[lWidth*lHeight] ;// [128][128] ;
-
int x ,y;
-
-
for( Orientation=0; Orientation<8; Orientation++){
-
for( Frequency=0; Frequency<4; Frequency++)
-
{
-
//在频域执行卷积
-
for( i=0; i<complexWidth * complexHeight; i++)
-
FD[i] = TD[i] * KernelFFT2[Orientation * 4 + Frequency][i] ; // * scale;
-
-
IFFT2(FD,complexWidth , complexHeight);
-
-
//计算均值、方差及结果
-
Sum=0, Avg=0, Deta=0;
-
-
for( y=(GaborHeight/2); y<(GaborHeight/2)+lHeight; y++){
-
for( x=(GaborWidth/2); x<(GaborWidth/2)+lWidth; x++)
-
{
-
tmpModulus = sqrt(FD[y*complexWidth+x].real() * FD[y*complexWidth+x].real() +
-
FD[y*complexWidth+x].imag() * FD[y*complexWidth+x].imag());
-
-
Sum += tmpModulus;
-
tmpMag[(y-(GaborHeight/2)) * lWidth + (x-(GaborWidth/2))] = tmpModulus;
-
}
-
}
-
Avg = Sum / (lHeight * lWidth);
-
//计算方差
-
for( y=0; y < lHeight; y++){
-
for( x=0; x < lWidth; x++)
-
Deta += (tmpMag[y* lWidth + x] - Avg)*(tmpMag[y* lWidth + x] - Avg);
-
}
-
Deta = Deta / (lHeight * lWidth);
-
-
-
TransformResult[(Orientation * 4 + Frequency)*2] = Avg;
-
TransformResult[(Orientation * 4 + Frequency)*2+1] = Deta;
-
}
-
}
-
-
delete[] tmpMag;
-
delete[] FD;
-
}
-
-
void FFTGabor::GaborTransform(complex<double> *TD, LONG lWidth, LONG lHeight, int Orientation, int Frequency, FFTGaborResult * result)
-
{
-
LONG i;
-
// LONG j;
-
-
complex<double> *FD = new complex<double>[complexWidth * complexHeight];
-
-
-
//在频域执行卷积
-
double scale = 1.0 / (complexWidth * complexHeight);
-
-
for( i=0; i<complexWidth * complexHeight; i++)
-
FD[i] = TD[i] * KernelFFT2[Orientation * 4 + Frequency][i] ; // * scale;
-
-
IFFT2(FD,complexWidth , complexHeight);
-
-
//计算均值、方差及结果
-
//计算均值并找出tmpMag中的最大最小值,以便调整到0~255,用于显示输出。
-
double min, max;
-
double Sum=0, Avg=0, Deta=0;
-
double tmpModulus=0;
-
double * tmpMag = new double[lWidth*lHeight] ;// [128][128] ;
-
int x ,y;
-
tmpModulus = sqrt(FD[(GaborHeight/2)*complexWidth+(GaborWidth/2)].real() *
-
FD[(GaborHeight/2)*complexWidth+(GaborWidth/2)].real() +
-
FD[(GaborHeight/2)*complexWidth+(GaborWidth/2)].imag() *
-
FD[(GaborHeight/2)*complexWidth+(GaborWidth/2)].imag());
-
min = max = tmpModulus;
-
for( y=(GaborHeight/2); y<(GaborHeight/2)+lHeight; y++){
-
for( x=(GaborWidth/2); x<(GaborWidth/2)+lWidth; x++)
-
{
-
tmpModulus = sqrt(FD[y*complexWidth+x].real() * FD[y*complexWidth+x].real() +
-
FD[y*complexWidth+x].imag() * FD[y*complexWidth+x].imag());
-
-
if(min>tmpModulus)
-
min = tmpModulus;
-
if(max<tmpModulus)
-
max = tmpModulus;
-
-
Sum += tmpModulus;
-
tmpMag[(y-(GaborHeight/2))* lWidth + (x-(GaborWidth/2))] = tmpModulus;
-
}
-
}
-
Avg = Sum / (lHeight * lWidth);
-
//计算方差
-
for( y=0; y < lHeight; y++){
-
for( x=0; x < lWidth; x++)
-
Deta += (tmpMag[y* lWidth + x] - Avg)*(tmpMag[y* lWidth + x] - Avg);
-
}
-
Deta = Deta / (lHeight * lWidth);
-
-
//计算magShow以及均值
-
scale = 255.0/(max-min);
-
-
for( y=0; y < lHeight; y++){
-
for( x=0; x < lWidth; x++)
-
{
-
result->magShow[y * lWidth + x] = (int)(scale*(tmpMag[y* lWidth + x]-min));
-
}
-
}
-
result->Avg = Avg;
-
result->Deta = Deta;
-
-
delete[] tmpMag;
-
-
delete[] FD;
-
}
字符分割源代码(效果还可以)
原文:http://blog.csdn.net/u012374012/article/details/42833635