资源描述:
《基于opencv的傅里叶变换和逆变换》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
1、基于OpenCV的傅里叶变换及逆变换#include#include#include#include/**************************************************************************//srcIPL_DEPTH_8U//dstIPL_DEPTH_64F**************************************************************************///傅里叶
2、正变换voidfft2(IplImage*src,IplImage*dst){ //实部、虚部 IplImage*image_Re=0,*image_Im=0,*Fourier=0; // inti,j; image_Re=cvCreateImage(cvGetSize(src),IPL_DEPTH_64F,1); //实部 //Imaginarypart image_Im=cvCreateImage(cvGetSize(src),IPL_DEPTH_64F,1); //虚部 //2channels(image_Re,image_Im) Fo
3、urier=cvCreateImage(cvGetSize(src),IPL_DEPTH_64F,2); //Realpartconversionfromu8to64f(double) cvConvertScale(src,image_Re,1,0); //Imaginarypart(zeros) cvZero(image_Im); //JoinrealandimaginarypartsandstocktheminFourierimage cvMerge(image_Re,image_Im,0,0,Fourier); //Applicationo
4、ftheforwardFouriertransform cvDFT(Fourier,dst,CV_DXT_FORWARD); cvReleaseImage(&image_Re); cvReleaseImage(&image_Im); cvReleaseImage(&Fourier);}/**************************************************************************//srcIPL_DEPTH_64F//dstIPL_DEPTH_8U***********************
5、***************************************************/voidfft2shift(IplImage*src,IplImage*dst){IplImage*image_Re=0,*image_Im=0;intnRow,nCol,i,j,cy,cx;doublescale,shift,tmp13,tmp24;image_Re=cvCreateImage(cvGetSize(src),IPL_DEPTH_64F,1);//Imaginarypartimage_Im=cvCreateImage(cvGet
6、Size(src),IPL_DEPTH_64F,1);cvSplit(src,image_Re,image_Im,0,0); //具体原理见冈萨雷斯数字图像处理p123 //ComputethemagnitudeofthespectrumMag=sqrt(Re^2+Im^2) //计算傅里叶谱 cvPow(image_Re,image_Re,2.0); cvPow(image_Im,image_Im,2.0); cvAdd(image_Re,image_Im,image_Re); cvPow(image_Re,image_Re,0.5); //对
7、数变换以增强灰度级细节(这种变换使以窄带低灰度输入图像值映射 //一宽带输出值,具体可见冈萨雷斯数字图像处理p62) //Computelog(1+Mag); cvAddS(image_Re,cvScalar(1.0),image_Re);//1+Mag cvLog(image_Re,image_Re);//log(1+Mag) //RearrangethequadrantsofFourierimagesothattheoriginisat theimagecenter nRow=src->height; nCol=src->width; cy=
8、nRow/2;//imagecenter cx=nCol/2;//CV_IMAGE_ELEM为OpenCV定义的宏,用来读取图像的像素值