www.pudn.com > wavelet-vc++6.rar > CS96.cpp
// CS96.cpp : implementation file
//
#include "stdafx.h"
#include "wavelet.h"
#include "MainFrm.h"
#include "waveletView.h"
#include "CS96.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
#define DD 8
#define N1 0
#define N2 7
/////////////////////////////////////////////////////////////////////////////
// CCS96 dialog
extern float h6[DD]={(float)0.230377813309,(float)0.714846570553,(float)0.630880767930,
(float)-0.027983769417,(float)-0.187034811719,(float)0.030841381836,
(float)0.032883011667,(float)-0.010597401785}; //sum h[n]=1
extern float g6[DD]={(float)-0.010597401785,(float)0.032883011667,(float)-0.030841381836,
(float)-0.187034811719,(float)0.027983769417,(float)0.630880767930,
(float)-0.714846570553,(float)0.230377813309};
extern float hi[DD],gi[DD];
CCS96::CCS96(CWnd* pParent /*=NULL*/)
: CDialog(CCS96::IDD, pParent)
{
//{{AFX_DATA_INIT(CCS96)
m_length = 0;
m_infile = _T("");
m_midfile = _T("");
m_outfile = _T("");
//}}AFX_DATA_INIT
}
void CCS96::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CCS96)
DDX_Text(pDX, IDC_IMAGELENGTH, m_length);
DDX_Text(pDX, IDC_INFILE, m_infile);
DDX_Text(pDX, IDC_MIDFILE, m_midfile);
DDX_Text(pDX, IDC_OUTFILE, m_outfile);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CCS96, CDialog)
//{{AFX_MSG_MAP(CCS96)
ON_BN_CLICKED(IDC_FILELOOK96, OnFilelook96)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CCS96 message handlers
void CCS96::OnFilelook96()
{
// TODO: Add your control notification handler code here
static char szFilter[]="DAT文件(*.dat)|*.dat||";
CFileDialog dlg(TRUE,"dat",NULL,OFN_HIDEREADONLY|OFN_OVERWRITEPROMPT,szFilter);
if(dlg.DoModal()==IDOK)
{
m_infile=dlg.GetPathName();
}
UpdateData(FALSE);
}
void CCS96::mainprogram()
{
CFile inputfile,mfile,outputfile;
int xs=0,ys=0,i=0,j=0,k=0;
CString str="";
float *image,t=0,max=0,min=0;
if(!inputfile.Open((LPCTSTR)m_infile,CFile::modeRead))
{
AfxMessageBox("输入文件错误");
return;
}
if(!outputfile.Open((LPCTSTR)m_outfile,CFile::modeCreate|CFile::modeWrite))
{
AfxMessageBox("输出文件错误");
return;
}
if(!mfile.Open((LPCTSTR)m_midfile,CFile::modeCreate|CFile::modeWrite))
{
str.Format("Can't open %s!",m_midfile);
AfxMessageBox(str);
return;
}
image=new float[m_length*sizeof(float)];
if(!image)
{
AfxMessageBox("Memory Error!");
return;
}
if(!inputfile.Read(image,m_length))
{
AfxMessageBox("Read file error!");
return;
}
xs=(int)m_length;
coef();
wt(xs,m_length,image);
xs=xs/2;
wt(xs,m_length,image);
xs=xs/2;
wt(xs,m_length,image);
CMainFrame* pFrame=(CMainFrame*)AfxGetApp()->GetMainWnd();
CWaveletView* pView=(CWaveletView*)pFrame->GetActiveView();
CDC* dc=pView->GetDC();
mfile.Write(image,m_length);
str.Format("1 level wt has finished xs=%d!",xs);
dc->TextOut(150,100,str);
for(j=0;jt)?max:t;
min=(minTextOut(150,150,str);
outputfile.Write(image,m_length);
inputfile.Close();
outputfile.Close();
mfile.Close();
delete image;
str.Format("Wavelet result max=%g, min=%g!",max,min);
dc->TextOut(150,200,str);
dc->DeleteDC();
}
//-----------Edge Process--------------
int CCS96::a(int x, int xsize)
{
if(x<0) x=-x;
if(x>=xsize) x=xsize*2-x-2;
return(x);
}
//-----------Set Inverse Filter Coefficients---------
void CCS96::coef()
{
int i=0,j=0;
for(i=0;imax) max=temp1;
if(temp2>max) max=temp2;
if(temp1