码迷,mamicode.com
首页 > 其他好文 > 详细

傅里叶变换 彩色

时间:2014-08-14 17:05:49      阅读:225      评论:0      收藏:0      [点我收藏+]

标签:opencv 傅里叶变换 彩色

程序:

bubuko.com,布布扣

代码:

#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;
}


本文出自 “flyclc” 博客,请务必保留此出处http://flyclc.blog.51cto.com/1385758/1539808

傅里叶变换 彩色,布布扣,bubuko.com

傅里叶变换 彩色

标签:opencv 傅里叶变换 彩色

原文地址:http://flyclc.blog.51cto.com/1385758/1539808

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!