程序:

wKiom1PsKJ2ymWtvAAMoT6R_idE416.jpg

代码:

#include "cv.h"
#include "cxcore.h"
#include "highgui.h"
#include <iostream>
int DFTColor(int argc,char** argv)  //离散傅里叶变换(Discrete Fourier Transform,缩写为DFT)
{
IplImage* src=cvLoadImage("e:\\picture\\4.jpg");
IplImage* SrcB=cvCreateImage(cvGetSize(src),8,1);
IplImage* SrcG=cvCreateImage(cvGetSize(src),8,1);
IplImage* SrcR=cvCreateImage(cvGetSize(src),8,1);
IplImage* SrcB32F=cvCreateImage(cvGetSize(src),IPL_DEPTH_32F,1);
IplImage* SrcG32F=cvCreateImage(cvGetSize(src),IPL_DEPTH_32F,1);
IplImage* SrcR32F=cvCreateImage(cvGetSize(src),IPL_DEPTH_32F,1);
IplImage* DFTB32F=cvCreateImage(cvGetSize(src),IPL_DEPTH_32F,1);
IplImage* DFTG32F=cvCreateImage(cvGetSize(src),IPL_DEPTH_32F,1);
IplImage* DFTR32F=cvCreateImage(cvGetSize(src),IPL_DEPTH_32F,1);
IplImage* DFTBResult32F=cvCreateImage(cvGetSize(src),IPL_DEPTH_32F,1);
IplImage* DFTGResult32F=cvCreateImage(cvGetSize(src),IPL_DEPTH_32F,1);
IplImage* DFTRResult32F=cvCreateImage(cvGetSize(src),IPL_DEPTH_32F,1);
IplImage* DFTB=cvCreateImage(cvGetSize(src),8,1);
IplImage* DFTG=cvCreateImage(cvGetSize(src),8,1);
IplImage* DFTR=cvCreateImage(cvGetSize(src),8,1);
IplImage* Src2B32F=cvCreateImage(cvGetSize(src),IPL_DEPTH_32F,1);
IplImage* Src2G32F=cvCreateImage(cvGetSize(src),IPL_DEPTH_32F,1);
IplImage* Src2R32F=cvCreateImage(cvGetSize(src),IPL_DEPTH_32F,1);
IplImage* Src2B=cvCreateImage(cvGetSize(src),8,1);
IplImage* Src2G=cvCreateImage(cvGetSize(src),8,1);
IplImage* Src2R=cvCreateImage(cvGetSize(src),8,1);
IplImage* Src2=cvCreateImage(cvGetSize(src),8,3);
//分割彩***像
cvSplit(src,SrcB,SrcG,SrcR,NULL);
//分别转换B,G,R位32位浮点型
cvConvertScale(SrcB,SrcB32F);
cvConvertScale(SrcG,SrcG32F);
cvConvertScale(SrcR,SrcR32F);
//分别进行傅里叶变换
cvDFT(SrcB32F,DFTB32F,CV_DXT_FORWARD);
cvDFT(SrcG32F,DFTG32F,CV_DXT_FORWARD);
cvDFT(SrcR32F,DFTR32F,CV_DXT_FORWARD);
//对傅里叶变换结果进行归一化
double MaxVal=0;
double MinVal=0;
cvMinMaxLoc(DFTB32F,&MinVal,&MaxVal);
double scale=255/(MaxVal-MinVal);
double shift=-MinVal*scale;
cvConvertScale(DFTB32F,DFTBResult32F,scale,shift);
MaxVal=0;
MinVal=0;
cvMinMaxLoc(DFTG32F,&MinVal,&MaxVal);
scale=255/(MaxVal-MinVal);
shift=-MinVal*scale;
cvConvertScale(DFTG32F,DFTGResult32F,scale,shift);
MaxVal=0;
MinVal=0;
cvMinMaxLoc(DFTR32F,&MinVal,&MaxVal);
scale=255/(MaxVal-MinVal);
shift=-MinVal*scale;
cvConvertScale(DFTR32F,DFTRResult32F,scale,shift);
//转换傅里叶变换结果为8位
cvConvertScale(DFTBResult32F,DFTB);
cvConvertScale(DFTGResult32F,DFTG);
cvConvertScale(DFTRResult32F,DFTR);
//傅里叶逆变换
cvDFT(DFTB32F,Src2B32F,CV_DXT_INVERSE | CV_DXT_SCALE);
cvDFT(DFTG32F,Src2G32F,CV_DXT_INVERSE | CV_DXT_SCALE);
cvDFT(DFTR32F,Src2R32F,CV_DXT_INVERSE | CV_DXT_SCALE);
//转换傅里叶逆变换结果为8位
cvConvertScale(Src2B32F,Src2B);
cvConvertScale(Src2G32F,Src2G);
cvConvertScale(Src2R32F,Src2R);
//合成原图
cvMerge(Src2B,Src2G,Src2R,NULL,Src2);
//显示结果
cvNamedWindow("src");
cvNamedWindow("SrcB");
cvNamedWindow("SrcG");
cvNamedWindow("SrcR");
cvNamedWindow("DFTB");
cvNamedWindow("DFTG");
cvNamedWindow("DFTR");
cvNamedWindow("Src2B");
cvNamedWindow("Src2G");
cvNamedWindow("Src2R");
cvNamedWindow("Src2");
cvShowImage("src",src);
cvShowImage("SrcB",SrcB);
cvShowImage("SrcG",SrcG);
cvShowImage("SrcR",SrcR);
cvShowImage("DFTB",DFTB);
cvShowImage("DFTG",DFTG);
cvShowImage("DFTR",DFTR);
cvShowImage("Src2B",Src2B);
cvShowImage("Src2G",Src2G);
cvShowImage("Src2R",Src2R);
cvShowImage("Src2",Src2);
cvWaitKey(0);
return 0;
}