傅里叶的代码我是直接学习网上的,程序可以执行但是没有任何效果
调试的时候感觉是源图像数据没传进去或者结果数据没传出来。但是不知道怎么弄了。
void CTest1View::OnBmpFft(complex<double> *pData2,complex<double> *pData,int nLevel,int Width,int Height)   //快速傅里叶变换
{
// TODO: Add your command handler code here
CTest1Doc *pDoc=GetDocument();
 CString bmpFilename=m_sOutFile;
CBmpFile bmpfile;
bmpfile.Load4File(bmpFilename);     Width=bmpfile.m_Cols; //高宽
    Height=bmpfile.m_Rows;
    LONG LineBytes=bmpfile.m_PxlBytes;//4的整数倍转换 行数byte值    pData2=bmpfile.m_pBmpInfo;//感觉是不是要有这两句?可是加上就会报错cannot convert from 'unsigned char *' to 'class std::complex<double>
pData=bmpfile.m_pBmpInfo;  //
memcpy(pData,pData2,Height*LineBytes);//把源图像的data2赋值给新图像的pData
//因为低通滤波是邻域运算,所以运算的结果应该不断赋给一个新的空
//数组,保证新算出的数组值不会影响后续计算
     memset(pData,0,Height*LineBytes);//下面是fft变换 网上copy的
double dTmp1,dTmp2;
int transWidth,transHeight; dTmp1=log(Width)/log(2);
dTmp2=ceil(dTmp1);
dTmp2=pow(2,dTmp1);
transWidth=(int)dTmp2;
dTmp1=log(Height)/log(2);
dTmp2=ceil(dTmp1);
dTmp2=pow(2,dTmp2);
transHeight=(int)dTmp2; pData2=new complex<double>[transWidth*transHeight];
    int nXLev,nYLev; //x y方向上的迭代次数
nXLev=(int)(log(Width)/log(2)+0.5);
nYLev=(int)(log(Height)/log(2)+0.5); //x方向的fft
for(int j=0;j<transHeight;j++)
{
FastFFT(&pData2[transWidth*j],&pData[transWidth*j],nXLev);
}
//转置
for(j=0;j<Height;j++) 
{
for(int i=0;i<Width;i++)
{
pData[transWidth*i+j]=pData[transWidth*j+i];
}
}
//y方向的fft
for(int i=0;i<Height;i++)
{
FastFFT(&pData2[i*transHeight],&pData[i*transHeight],nYLev);
}
for(j=0;j<transHeight;j++)
{
for(i=0;i<transWidth;i++)
{
pData[transWidth*j+i]=pData2[transHeight*i+j];
} }
//输出 memcpy(pData,pData2,sizeof(complex<double>)*transHeight*transWidth);
    CClientDC dc(this);
    bmpfile.Draw2DC(dc.m_hDC,0,0);
}
void CTest1View::FastFFT(complex<double> *pData2,complex<double> *pData,int nLevel)
{
int i=0,j,k;
double PI=3.14159; int nCount=0;  //傅里叶变换点数
nCount=(int)pow(2,nLevel); //某一级的长度
int nBtFlyLen=0; //变换系数的角度
double dAngle=2*PI*i/nCount; //分配内存,存储傅里叶变换需要的系数表
complex<double> *pCW=new complex<double>[nCount/2]; //计算fft变换系数
for(i=0;i<nCount/2;i++)
{
dAngle=-2*PI*i/nCount;
pCW[i]=complex<double>(cos(dAngle),sin(dAngle));
}
//变换需要的空间
complex<double> *pCWork1,*pCWork2;
//分配空间
pCWork1=new complex<double>[nCount];
pCWork2=new complex<double> [nCount]; //临时变量
complex<double> *pCTemp; //初始化写入数据
memcpy(pCWork1,pData,sizeof(complex<double>)*nCount); //临时变量
int nInter=0; /*蝶形算法*/
for(k=0;k<nLevel;k++)
{
for(j=0;j<(int)pow(2,k);j++)
{
nBtFlyLen=(int)pow(2,(nLevel-k));
//这一级的长度
for(i=0;i<nBtFlyLen/2;i++)
{
nInter=j*nBtFlyLen;
pCWork2[i+nInter]=pCWork1[i+nInter]+pCWork1[i+nInter+nBtFlyLen/2];
pCWork2[i+nInter+nBtFlyLen/2]=(pCWork1[i+nInter]-pCWork1[i+nInter+nBtFlyLen/2])*pCW[(int)(i*pow(2,k))];
}
}
//交换work1 work2的数据
pCTemp=pCWork1;
pCWork1=pCWork2;
pCWork2=pCTemp;
}
//重新排序
for(j=0;j<nCount;j++)
{
nInter=0;
for(i=0;i<nLevel;i++)
{
if(j&&(1<<i))
nInter+= 1<<(nLevel-i-1);
}
pData2[j]=pCWork1[nInter];
}
//释放空间
delete pCW;
delete pCWork1;
delete pCWork2;
}PS:BmpFile 是自己加进去的头文件  如下/*----------------------------------------------------------------------+
| BmpFile   |
|       Author:     DuanYanSong  2011/05/14 |
|            Ver 1.0 |
|       Copyright (c)2011, WHU RSGIS DPGrid Group |
|          All rights reserved.                                       |
| [email protected] |
+----------------------------------------------------------------------*/
#ifndef BMPFILE_H_DUANYANSONG_2011_05_14_10_38_345678976543
#define BMPFILE_H_DUANYANSONG_2011_05_14_10_38_345678976543class CBmpFile
{
public:
    CBmpFile(){ m_pImgDat=NULL; m_Cols=m_Rows=m_PxlBytes =0;
    m_pBmpInfo   = new BYTE[ sizeof(BITMAPINFOHEADER)+sizeof(RGBQUAD)*256 ];
memset( m_pBmpInfo,0,sizeof(BITMAPINFOHEADER)+sizeof(RGBQUAD)*256 );
RGBQUAD *pColorTab = (RGBQUAD *)(m_pBmpInfo+sizeof(BITMAPINFOHEADER));
for( int i=0;i<256;i++ ){ pColorTab[i].rgbRed=pColorTab[i].rgbGreen=pColorTab[i].rgbBlue=i;} 
}
    virtual ~CBmpFile(){ if (m_pImgDat) delete []m_pImgDat; m_pImgDat=NULL; if( m_pBmpInfo ) delete []m_pBmpInfo; m_pBmpInfo=NULL; };
BYTE*   operator[](int nIndex){ return (m_pImgDat+nIndex*m_Cols); };
const CBmpFile& operator=(CBmpFile& bmpFile){
CreateBmp( bmpFile.m_Cols,bmpFile.m_Rows,bmpFile.m_PxlBytes);
memcpy( m_pImgDat,bmpFile.m_pImgDat,m_Cols*m_Rows*m_PxlBytes );
memcpy( m_pBmpInfo,bmpFile.m_pBmpInfo,sizeof(BITMAPINFOHEADER)+sizeof(RGBQUAD)*256 );
return (*this); 
};

BOOL CreateBmp(int cols,int rows,int pixelPytes){
if (m_pImgDat) delete []m_pImgDat;
m_pImgDat = new BYTE[cols*rows*pixelPytes];
memset( m_pImgDat,0,cols*rows*pixelPytes );
m_Cols=cols; m_Rows=rows; m_PxlBytes =pixelPytes;
return TRUE;
};
    BOOL    Load4File( LPCSTR lpstrPathName ){
                BITMAPFILEHEADER  bmFileHdr; BITMAPINFOHEADER bmInfoHdr; DWORD rw;
                HANDLE hFile = ::CreateFile( lpstrPathName,GENERIC_READ,FILE_SHARE_READ,NULL,OPEN_EXISTING,FILE_FLAG_RANDOM_ACCESS,NULL );
                if ( hFile == INVALID_HANDLE_VALUE ) return FALSE;
                ::ReadFile( hFile,&bmFileHdr,sizeof(bmFileHdr),&rw,NULL );
                if ( bmFileHdr.bfType != ((WORD)('M'<<8)|'B') ){ ::CloseHandle(hFile); return FALSE; }
                ::ReadFile( hFile,&bmInfoHdr ,sizeof(bmInfoHdr ),&rw,NULL );
                if ( (bmInfoHdr.biBitCount!=8)&&(bmInfoHdr.biBitCount!=24) ){ ::CloseHandle(hFile); ::MessageBox( ::GetFocus(),"Just read 8 or 24 bits Bitmap File.","Error",MB_OK ); return FALSE; }
                
                m_Cols      = bmInfoHdr.biWidth;
                m_Rows      = bmInfoHdr.biHeight;
                m_PxlBytes  = int(bmInfoHdr.biBitCount/8); if ( m_PxlBytes==1 ) // Read Color Table
::ReadFile( hFile,m_pBmpInfo+sizeof(BITMAPINFOHEADER),256*sizeof(RGBQUAD),&rw,NULL );                if ( m_pImgDat ) delete m_pImgDat; m_pImgDat = new BYTE[ m_Cols*m_Rows*m_PxlBytes +8 ];
                ::SetFilePointer( hFile,bmFileHdr.bfOffBits,NULL,FILE_BEGIN );
                int rowBytes = ( ( bmInfoHdr.biWidth*(bmInfoHdr.biBitCount)+31)& ~31 )/8 ;
                for ( int i=0;i<m_Rows;i++ ) ::ReadFile( hFile,m_pImgDat+i*m_Cols*m_PxlBytes,rowBytes,&rw,NULL );
                ::CloseHandle(hFile);
                return TRUE;
            };
    BOOL    Save2File( LPCSTR lpstrPathName ){
BITMAPFILEHEADER  bmFileHdr; BITMAPINFOHEADER bmInfoHdr;   DWORD rw;
HANDLE hFile    = ::CreateFile( lpstrPathName,GENERIC_READ|GENERIC_WRITE,0,NULL,CREATE_ALWAYS,0,NULL );
if ( !hFile && hFile==INVALID_HANDLE_VALUE ) return FALSE;

memset( &bmInfoHdr,0,sizeof(bmInfoHdr) );
bmInfoHdr.biSize   = sizeof(bmInfoHdr);
bmInfoHdr.biPlanes    = 1;
bmInfoHdr.biWidth     = m_Cols      ;
bmInfoHdr.biHeight    = m_Rows      ;
bmInfoHdr.biBitCount  = m_PxlBytes*8;

memset( &bmFileHdr,0,sizeof(bmFileHdr) );
bmFileHdr.bfType      = ((WORD)('M'<<8)|'B');
bmFileHdr.bfOffBits   = sizeof(bmFileHdr)+sizeof(bmInfoHdr)+1024;
int rowBytes = ( (bmInfoHdr.biWidth*(bmInfoHdr.biBitCount)+31)& ~31 )/8 ;
bmFileHdr.bfSize      = bmFileHdr.bfOffBits + rowBytes*bmInfoHdr.biHeight ;

RGBQUAD pColTab[256];
for ( int i=0;i<256;i++ ) pColTab[i].rgbRed=pColTab[i].rgbGreen=pColTab[i].rgbBlue=i;
::WriteFile( hFile,&bmFileHdr,sizeof(bmFileHdr),&rw,NULL );
::WriteFile( hFile,&bmInfoHdr,sizeof(bmInfoHdr),&rw,NULL );                
::WriteFile( hFile,pColTab,sizeof(pColTab ),&rw,NULL );

if ( rowBytes==m_Cols*m_PxlBytes )
::WriteFile( hFile,m_pImgDat,bmFileHdr.bfSize-bmFileHdr.bfOffBits,&rw,NULL );
else{
for (int i=0;i<bmInfoHdr.biHeight-1;i++ )
::WriteFile( hFile,m_pImgDat+i*m_Cols*m_PxlBytes,rowBytes,&rw,NULL );
::WriteFile( hFile,m_pImgDat+i*m_Cols*m_PxlBytes,m_Cols*m_PxlBytes,&rw,NULL );
::WriteFile( hFile,m_pImgDat,rowBytes-m_Cols*m_PxlBytes,&rw,NULL );
}
::CloseHandle(hFile);
return TRUE;
};
void Draw2DC( HDC hDC,int x,int y ){
BITMAPINFO *pBmInf = (BITMAPINFO*)m_pBmpInfo;
pBmInf->bmiHeader.biSize        = sizeof(BITMAPINFOHEADER);
pBmInf->bmiHeader.biCompression = BI_RGB;
pBmInf->bmiHeader.biPlanes      = 1;
pBmInf->bmiHeader.biBitCount    = m_PxlBytes*8;
pBmInf->bmiHeader.biWidth       = m_Cols;
pBmInf->bmiHeader.biHeight      = m_Rows; 

BYTE *pBuf = m_pImgDat;
int rowBytes = ( (pBmInf->bmiHeader.biWidth*(pBmInf
>bmiHeader.biBitCount)+31)& ~31 )/8;
if ( rowBytes!=m_Cols*m_PxlBytes ){
pBuf = new BYTE[m_Rows*rowBytes];
for (int i=0;i<m_Rows;i++ ) memcpy( pBuf+i*rowBytes,m_pImgDat+i*m_Cols*m_PxlBytes,m_Cols*m_PxlBytes );
}
int oldMod = ::SetStretchBltMode( hDC,STRETCH_DELETESCANS );
::StretchDIBits( hDC,
 x,y,pBmInf->bmiHeader.biWidth,pBmInf->bmiHeader.biHeight,
 0,0,pBmInf->bmiHeader.biWidth,pBmInf->bmiHeader.biHeight,
 pBuf,(CONST BITMAPINFO *)pBmInf,
 DIB_RGB_COLORS,SRCCOPY );
::SetStretchBltMode( hDC,oldMod ); if ( pBuf!=m_pImgDat ) delete []pBuf;
};
public:
    BYTE*    m_pImgDat;
    int      m_Cols,m_Rows,m_PxlBytes;
BYTE*    m_pBmpInfo;};#endif