⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 pro2doc.cpp

📁 用VC++写的关于数字图像处理的程序源码
💻 CPP
字号:
// Pro2Doc.cpp : implementation of the CPro2Doc class
//

#include "stdafx.h"
#include "Pro2.h"

#include "Pro2Doc.h"
#include "CDib.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CPro2Doc

IMPLEMENT_DYNCREATE(CPro2Doc, CDocument)

BEGIN_MESSAGE_MAP(CPro2Doc, CDocument)
	//{{AFX_MSG_MAP(CPro2Doc)
		// NOTE - the ClassWizard will add and remove mapping macros here.
		//    DO NOT EDIT what you see in these blocks of generated code!
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CPro2Doc construction/destruction

CPro2Doc::CPro2Doc()
{
	// TODO: add one-time construction code here

}

CPro2Doc::~CPro2Doc()
{
}

BOOL CPro2Doc::OnNewDocument()
{
	if (!CDocument::OnNewDocument())
		return FALSE;

	// TODO: add reinitialization code here
	// (SDI documents will reuse this document)

	return TRUE;
}



/////////////////////////////////////////////////////////////////////////////
// CPro2Doc serialization

void CPro2Doc::Serialize(CArchive& ar)
{
	if (ar.IsStoring())
	{
		// TODO: add storing code here
	}
	else
	{
		// TODO: add loading code here
	}
}

/////////////////////////////////////////////////////////////////////////////
// CPro2Doc diagnostics

#ifdef _DEBUG
void CPro2Doc::AssertValid() const
{
	CDocument::AssertValid();
}

void CPro2Doc::Dump(CDumpContext& dc) const
{
	CDocument::Dump(dc);
}
#endif //_DEBUG

/////////////////////////////////////////////////////////////////////////////
// CPro2Doc commands
void CPro2Doc::FFT_1D(complex<double>* pCTData,complex<double>* pCFData,int nLevel)
{
	int i;
	int j;
	int k;

	double PI=3.1415926;

	int nCount=0;

	nCount=(int)pow(2,nLevel);

	int nBtFlyLen;
	nBtFlyLen=0;

	double dAngle;

	complex<double>* pCW;
	pCW=new complex<double>[nCount/2];

	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>* pCTmp;

	memcpy(pCWork1,pCTData,sizeof(complex<double>)*nCount);

	int nInter;
	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))];
			}
		}
		pCTmp=pCWork1;
		pCWork1=pCWork2;
		pCWork2=pCTmp;
	}

	for(j=0;j<nCount;j++)
	{
		nInter=0;
		for(i=0;i<nLevel;i++)
		{
			if(j&(1<<i))
				nInter+=1<<(nLevel-i-1);
		}

		pCFData[j]=pCWork1[nInter];
	}

	delete pCW;
	delete pCWork1;
	delete pCWork2;
	pCW=NULL;
	pCWork1=NULL;
	pCWork2=NULL;
}

void CPro2Doc::FFT_2D(complex<double>* pCTData,int nWidth,int nHeight,complex<double>* pCFData)
{
	int x,y;
	double dTmpOne;
	double dTmpTwo;

	int nTransWidth;
	int nTransHeight;

	dTmpOne=log(nWidth)/log(2);
	dTmpTwo=ceil(dTmpOne);
	dTmpTwo=pow(2,dTmpTwo);
	nTransWidth=(int)dTmpTwo;

	dTmpOne=log(nHeight)/log(2);
	dTmpTwo=ceil(dTmpOne);
	dTmpTwo=pow(2,dTmpTwo);
	nTransHeight=(int)dTmpTwo;

	int nXLev;
	int nYLev;

	nXLev=(int)(log(nTransWidth)/log(2)+0.5);
	nYLev=(int)(log(nTransHeight)/log(2)+0.5);

	for(y=0;y<nTransHeight;y++)
	{
		FFT_1D(&pCTData[nTransWidth*y],&pCFData[nTransWidth*y],nXLev);
	}

	for(y=0;y<nTransHeight;y++)
	{
		for(x=0;x<nTransWidth;x++)
		{
			pCTData[nTransHeight*x+y]=pCFData[nTransWidth*y+x];
		}
	}

	for(x=0;x<nTransWidth;x++)
	{
		FFT_1D(&pCTData[x*nTransHeight],&pCFData[x*nTransHeight],nYLev);
	} 

	for(y=0;y<nTransHeight;y++)
	{
		for(x=0;x<nTransWidth;x++)
		{
			pCTData[nTransWidth*y+x]=pCFData[nTransHeight*x+y];
		}
	}

	memcpy(pCTData,pCFData,sizeof(complex<double>)*nTransHeight*nTransWidth);
}

void CPro2Doc::IFFT_1D(complex<double>* pCFTData,complex<double>* pCTData,int nLevel)
{
	int i;
	int nCount;

	nCount=(int)pow(2,nLevel);

	complex<double>* pCWork;

	pCWork=new complex<double>[nCount];

	memcpy(pCWork,pCFTData,sizeof(complex<double>)* nCount);

	for(i=0;i<nCount;i++)
	{
		pCWork[i]=complex<double>(pCWork[i].real(),-pCWork[i].imag());
	}

	FFT_1D(pCWork,pCTData,nLevel);

	for(i=0;i<nCount;i++)
	{
		pCTData[i]=complex<double>(pCTData[i].real()/nCount,-pCTData[i].imag()/nCount);
	}

	delete pCWork;
	pCWork=NULL;
}

void CPro2Doc::IFFT_2D(complex<double>* pCFData,int nWidth,int nHeight,complex<double>* pCTData)
{
	int x,y;
	double dTmpOne;
	double dTmpTwo;

	int nTransWidth;
	int nTransHeight;

	dTmpOne=log(nWidth)/log(2);
	dTmpTwo=ceil(dTmpOne);
	dTmpTwo=pow(2,dTmpTwo);
	nTransWidth=(int)dTmpTwo;

	dTmpOne=log(nHeight)/log(2);
	dTmpTwo=ceil(dTmpOne);
	dTmpTwo=pow(2,dTmpTwo);
	nTransHeight=(int)dTmpTwo;

	complex<double>* pCWork=new complex<double>[nTransWidth*nTransHeight];

	complex<double>* pCTmp;

	for(y=0;y<nTransHeight;y++)
	{
		for(x=0;x<nTransWidth;x++)
		{
			pCTmp=&pCFData[nTransWidth*y+x];
			pCWork[nTransWidth*y+x]=complex<double>(pCTmp->real(),-pCTmp->imag());
		}
	}

	FFT_2D(pCWork,nWidth,nHeight,pCTData);

	for(y=0;y<nTransHeight;y++)
	{
		for(x=0;x<nTransWidth;x++)
		{
			pCTmp=&pCTData[nTransWidth*y+x];
			pCWork[nTransWidth*y+x]=
				complex<double>(pCTmp->real()/(nTransWidth*nTransHeight),-pCTmp->imag()/(nTransWidth*nTransHeight));
		}
	}

	delete pCWork;
	pCWork=NULL;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -