這是找到的資訊不知是否有所幫助?(,但我看不懂 C ) void __fastcall TForm2::FourierT(){
order=0;
if (NewImage->Height==NewImage->Width){
int ffttemp=NewImage->Width;
while ((ffttemp=ffttemp>>1)>0)
order++;
}
if (NewImage->Height==pow(2,order)&&NewImage->Width==pow(2,order)){
TTime before=Now();
Graphics::TBitmap *bmpnow=new Graphics::TBitmap();
bmpnow->Assign(NewImage->Picture);
Byte *ptr;
ffttemp=new COMPLEX[bmpnow->Width];
fftimg=new COMPLEX*[bmpnow->Height];
double **spectrum=new double*[bmpnow->Height];
for (int i=0;iHeight;i ){
fftimg[i]=new COMPLEX[bmpnow->Width];
spectrum[i]=new double[bmpnow->Width];
}
double f_max=0,f_min=0;
//=================================================
for (int i=0;iHeight;i ){
ptr=(Byte*)bmpnow->ScanLine[i];
for (int j=0;jWidth;j ){
ffttemp[j].real=ptr[j*3];
ffttemp[j].imag = 0;
if((j%2)==0)
ffttemp[j].real = (double)(ffttemp[j].real);
else
ffttemp[j].real = (double)((-1)*ffttemp[j].real);
}
fft(ffttemp,order);
for(int j=0;jWidth;j ){
fftimg[i][j].real =ffttemp[j].real/bmpnow->Width;
fftimg[i][j].imag =ffttemp[j].imag/bmpnow->Width;
}
}
//==================================================
for(int i=0;iHeight;i ){
for(int j=0;jWidth;j ){
if((j%2)==0){
ffttemp[j].real = fftimg[j][i].real;
ffttemp[j].imag = fftimg[j][i].imag;
}
else{
ffttemp[j].real = -1*fftimg[j][i].real;
ffttemp[j].imag = -1*fftimg[j][i].imag;
}
}
fft(ffttemp,order);
for(int j=0;jWidth;j ){
fftimg[j][i].real = ffttemp[j].real;
fftimg[j][i].imag = ffttemp[j].imag;
}
}
//=================================================
for(int i=0;iHeight;i ){
for(int j=0;jWidth;j ){
spectrum[i][j]=(double)(sqrt(pow(fftimg[i][j].real,2) pow(fftimg[i][j].imag,2))) ;
f_max = (f_max > spectrum[i][j]) ? f_max : spectrum[i][j];
f_min = (f_min < spectrum[i][j]) ? f_min : spectrum[i][j];
}
}
f_max = log10(1 abs(f_max));
f_min = log10(1 abs(f_min));
int gray=0;
for(int i=0;iHeight;i ){
ptr = (Byte *)bmpnow->ScanLine[i];
for(int j=0;jWidth;j ){
gray=(unsigned char)(255*( log10(1. spectrum[i][j]) - f_min)/(f_max-f_min));
ptr[j*3]=gray;
ptr[j*3 1]=gray;
ptr[j*3 2]=gray;
}
}
TTime after=Now();
NewImage->Picture->Assign(bmpnow);
Form1->StatusBar1->Panels->Items[1]->Text="共花費 "
(after-before).FormatString("s")
" Seconds";
------
我也在努力學習中,若有錯謬請見諒。