核心函数:cvDFT
程序:
代码:
#include "cv.h" #include "cxcore.h" #include "highgui.h" #include <iostream> int DFT2(int argc,char** argv) //离散傅里叶变换(Discrete Fourier Transform,缩写为DFT) { IplImage* src=cvLoadImage("e:\\picture\\4.jpg",0); IplImage* Src32F=cvCreateImage(cvGetSize(src),IPL_DEPTH_32F,1); IplImage* Dst32F=cvCreateImage(cvGetSize(src),IPL_DEPTH_32F,1); IplImage* Dst32F_Inverse=cvCreateImage(cvGetSize(src),IPL_DEPTH_32F,1); IplImage* DFTResult_32F=cvCreateImage(cvGetSize(src),IPL_DEPTH_32F,1); IplImage* DFTResult=cvCreateImage(cvGetSize(src),8,1); IplImage* src2=cvCreateImage(cvGetSize(src),8,1); cvConvertScale(src,Src32F); cvDFT(Src32F,Dst32F,CV_DXT_FORWARD); cvDFT(Dst32F,Dst32F_Inverse,CV_DXT_INVERSE | CV_DXT_SCALE); //用CV_DXT_SCALE即可不做归一化处理 cvConvertScale(Dst32F_Inverse,src2); //对傅里叶变换结果进行归一化以显示结果 double MaxVal=0; double MinVal=0; cvMinMaxLoc(Dst32F,&MinVal,&MaxVal); double scale=255/(MaxVal-MinVal); double shift=-MinVal*scale; cvConvertScale(Dst32F,DFTResult_32F,scale,shift); //把归一化的福利叶变换结果转换为8位以便显示 cvConvertScale(DFTResult_32F,DFTResult); cvMinMaxLoc(DFTResult,&MinVal,&MaxVal); std::cout<<"DFTResult Max:"<<MaxVal<<"DFTResult Max:"<<MinVal<<std::endl; cvNamedWindow("src"); cvNamedWindow("src2"); cvNamedWindow("DFTResult"); cvShowImage("src",src); cvShowImage("src2",src2); cvShowImage("DFTResult",DFTResult); cvWaitKey(0); cvDestroyWindow("src"); cvDestroyWindow("src2"); cvDestroyWindow("DFTResult"); cvReleaseImage(&src); cvReleaseImage(&src2); cvReleaseImage(&DFTResult); return 0; }
本文出自 “flyclc” 博客,请务必保留此出处http://flyclc.blog.51cto.com/1385758/1539814
离散傅里叶变换2 用标记方法而不是归一化,布布扣,bubuko.com
原文:http://flyclc.blog.51cto.com/1385758/1539814