小波变换View.cpp
上传用户:aqingfeng
上传日期:2014-03-25
资源大小:1839k
文件大小:32k
- // 小波变换View.cpp : implementation of the CMyView class
- //
- #include "stdafx.h"
- #include "小波变换.h"
- #include "小波变换Doc.h"
- #include "小波变换View.h"
- #include "dibapi.h"
- #include "math.h"
- #include "waveletlevel.h"
- #include "WaveletCoi.h"
- #include "Daubechiesdlg.h"
- #include "WaveTranform.h"
- #include "HebingDlg.h"
- #include "Symletsdlg.h"
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
- /////////////////////////////////////////////////////////////////////////////
- // CMyView
- IMPLEMENT_DYNCREATE(CMyView, CView)
- BEGIN_MESSAGE_MAP(CMyView, CView)
- //{{AFX_MSG_MAP(CMyView)
- ON_COMMAND(ID_COMPRESSION, OnCompression)
- ON_COMMAND(ID_DISCOMPRESSION, OnDiscompression)
- ON_COMMAND(ID_WAVELETCONSTRUCTION, OnWaveletconstruction)
- ON_COMMAND(IDM_DIPROC_FUSION2, OnDiprocFusion2)
- ON_COMMAND(IDM_DIPROC_FUSION3, OnDiprocFusion3)
- ON_COMMAND(IDM_DIPROC_FUSION4, OnDiprocFusion4)
- ON_COMMAND(IDM_IMAGE_HEBING, OnImageHebing)
- ON_COMMAND(ID_DETECT_TEMPLATE, OnDetectTemplate)
- //}}AFX_MSG_MAP
- // Standard printing commands
- ON_COMMAND(ID_FILE_PRINT, CView::OnFilePrint)
- ON_COMMAND(ID_FILE_PRINT_DIRECT, CView::OnFilePrint)
- ON_COMMAND(ID_FILE_PRINT_PREVIEW, CView::OnFilePrintPreview)
- END_MESSAGE_MAP()
- /////////////////////////////////////////////////////////////////////////////
- // CMyView construction/destruction
- CMyView::CMyView()
- {
- // TODO: add construction code here
- m_nLevel=1;
- FWidth=0;
- wavefunction=-1;
- }
- CMyView::~CMyView()
- {
- }
- BOOL CMyView::PreCreateWindow(CREATESTRUCT& cs)
- {
- // TODO: Modify the Window class or styles here by modifying
- // the CREATESTRUCT cs
- return CView::PreCreateWindow(cs);
- }
- /////////////////////////////////////////////////////////////////////////////
- // CMyView drawing
- void CMyView::OnDraw(CDC* pDC)
- {
- BeginWaitCursor();
- CMyDoc* pDoc = GetDocument();
- ASSERT_VALID(pDoc);
- // TODO: add draw code for native data here
- // 获取DIB
- HDIB hDIB = pDoc->GetHDIB();
- HDIB m_hMulDIB=pDoc->m_hMulDIB;
- // 判断DIB是否为空
- if (hDIB != NULL)
- {
- LPSTR lpDIB = (LPSTR) ::GlobalLock((HGLOBAL) hDIB);
- // 获取DIB宽度
- int cxDIB = (int) ::DIBWidth(lpDIB);
- // 获取DIB高度
- int cyDIB = (int) ::DIBHeight(lpDIB);
- ::GlobalUnlock((HGLOBAL) hDIB);
- CRect rcDIB;
- rcDIB.top = rcDIB.left = 0;
- rcDIB.right = cxDIB;
- rcDIB.bottom = cyDIB;
- // 输出DIB
- ::PaintDIB(pDC->m_hDC, &rcDIB, pDoc->GetHDIB(),
- &rcDIB, pDoc->GetDocPalette());
- }
- if (m_hMulDIB!= NULL)
- {
- LPSTR lpDIB = (LPSTR) ::GlobalLock((HGLOBAL)m_hMulDIB);
- // 获取DIB宽度
- int cxDIB = (int) ::DIBWidth(lpDIB);
- // 获取DIB高度
- int cyDIB = (int) ::DIBHeight(lpDIB);
- ::GlobalUnlock((HGLOBAL)m_hMulDIB);
- CRect rcDIB;
- rcDIB.top =0;
- rcDIB.left =600;
- rcDIB.right = cxDIB;
- rcDIB.bottom = cyDIB;
- // 输出DIB
- ::PaintDIB(pDC->m_hDC, &rcDIB, pDoc->m_hMulDIB,
- &rcDIB, pDoc->GetDocPalette());
- }
- // 恢复正常光标
- }
- /////////////////////////////////////////////////////////////////////////////
- // CMyView printing
- BOOL CMyView::OnPreparePrinting(CPrintInfo* pInfo)
- {
- // default preparation
- return DoPreparePrinting(pInfo);
- }
- void CMyView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
- {
- // TODO: add extra initialization before printing
- }
- void CMyView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
- {
- // TODO: add cleanup after printing
- }
- /////////////////////////////////////////////////////////////////////////////
- // CMyView diagnostics
- #ifdef _DEBUG
- void CMyView::AssertValid() const
- {
- CView::AssertValid();
- }
- void CMyView::Dump(CDumpContext& dc) const
- {
- CView::Dump(dc);
- }
- CMyDoc* CMyView::GetDocument() // non-debug version is inline
- {
- ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CMyDoc)));
- return (CMyDoc*)m_pDocument;
- }
- #endif //_DEBUG
- /////////////////////////////////////////////////////////////////////////////
- // CMyView message handlers
- void CMyView::OnWaveletconstruction()
- {
- // TODO: Add your command handler code here
- //所谓的构建,其实是已经将数据存入了数组里。
- BeginWaitCursor();
- CMyDoc* pDoc = GetDocument();
- Ld = new double[20]; //分解尺度函数
- Hd = new double[20]; //分解母函数
- Lr = new double[20]; //重建尺度函数
- Hr = new double[20]; //重建母函数
- CWaveletCoi waveletcoi;
- if(waveletcoi.DoModal()==IDOK)
- {
- FWidth=waveletcoi.m_waveletlength;
- wavefunction=waveletcoi.m_waveletfunction;
- switch(wavefunction)
- {
- case 0://IDC_SHANNON
- {
- Ld[0]=1/sqrt(2);
- Ld[1]=1/sqrt(2);
- break;
- }
- case 1://IDC_DAUBECHIES
- {
- switch(FWidth)
- {
- case 2:
- Ld[0]=1/sqrt(2); Ld[1]=1/sqrt(2);
- m_wavetransform.m_preoffset=0;
- m_wavetransform.m_aftoffset=1;
- break;
- case 4:
- Ld[0]=0.4829629131445341; Ld[1]=0.8365163037378077; Ld[2]=0.2241438680420134;
- Ld[3]=-0.1294095225512603;
- m_wavetransform.m_preoffset=0;
- m_wavetransform.m_aftoffset=3;
- break;
- case 6:
- Ld[0]=0.3326705529500825; Ld[1]=0.8068915093110924; Ld[2]=0.4598775021184914;
- Ld[3]=-0.1350110200102546; Ld[4]=-0.0854412738820267; Ld[5]=0.035226218857095;
- m_wavetransform.m_preoffset=1;
- m_wavetransform.m_aftoffset=4;
- break;
- case 8:
- Ld[0]=0.230377813309; Ld[1]=0.714846570553; Ld[2]=0.630880767930;
- Ld[3]=-0.027983769417; Ld[4]=-0.187034811719; Ld[5]=0.030841381836;
- Ld[6]=0.032883011667; Ld[7]=-0.010597401785;
- m_wavetransform.m_preoffset=1;
- m_wavetransform.m_aftoffset=6;
- break;
- case 10:
- Ld[0]=0.160102397974; Ld[1]=0.603829269797; Ld[2]=0.724308528438;
- Ld[3]=0.138428145901; Ld[4]=-0.242294887066; Ld[5]=-0.032244869585;
- Ld[6]=0.077571493840; Ld[7]=-0.006241490213; Ld[8]=-0.012580751999;
- Ld[9]=0.003335725285;
- m_wavetransform.m_preoffset=1;
- m_wavetransform.m_aftoffset=8;
- break;
- case 12:
- Ld[0]=0.111540743350; Ld[1]=0.494623890398; Ld[2]=0.751133908021;
- Ld[3]=0.315250351709; Ld[4]=-0.226264693965; Ld[5]=-0.129766867567;
- Ld[6]=0.097501605587; Ld[7]=0.027522865530; Ld[8]=-0.031582039318;
- Ld[9]=0.000553842201; Ld[10]=0.004777257511; Ld[11]=-0.001077301085;
- m_wavetransform.m_preoffset=1;
- m_wavetransform.m_aftoffset=10;
- break;
- case 14:
- Ld[0]=0.077852054085; Ld[1]=0.396539319482; Ld[2]=0.729132090846;
- Ld[3]=0.469782287405; Ld[4]=-0.143906003929; Ld[5]=-0.224036184994;
- Ld[6]=0.071309219267; Ld[7]=0.080612609151; Ld[8]=-0.038029936935;
- Ld[9]=-0.016574541631; Ld[10]=0.012550998556; Ld[11]=0.000429577973;
- Ld[12]=-0.001801640704; Ld[13]=0.000353713800;
- m_wavetransform.m_preoffset=1;
- m_wavetransform.m_aftoffset=12;
- break;
- case 16:
- Ld[0]=0.054415842243; Ld[1]=0.312871590914; Ld[2]=0.675630736297;
- Ld[3]=0.585354683654; Ld[4]=-0.015829105256; Ld[5]=-0.284015542962;
- Ld[6]=0.000472484574; Ld[7]=0.128747426620; Ld[8]=-0.017369301002;
- Ld[9]=-0.044088253931; Ld[10]=0.013981027917; Ld[11]=0.008746094047;
- Ld[12]=-0.004870352993; Ld[13]=-0.000391740373; Ld[14]=0.000675449406;
- Ld[15]=-0.000117476784;
- m_wavetransform.m_preoffset=1;
- m_wavetransform.m_aftoffset=14;
- break;
- case 18:
- Ld[0]=0.038077947364; Ld[1]=0.243834674613; Ld[2]=0.604823123690;
- Ld[3]=0.657288078051; Ld[4]=0.133197385825; Ld[5]=-0.293273783279;
- Ld[6]=-0.096840783223; Ld[7]=0.148540749338; Ld[8]=0.030725681479;
- Ld[9]=-0.067632829061; Ld[10]=0.000250947115; Ld[11]=0.022361662124;
- Ld[12]=-0.004723204758; Ld[13]=-0.004281503682; Ld[14]=0.001847646883;
- Ld[15]=0.000230385764; Ld[16]=-0.000251963189; Ld[17]=0.000039347320;
- m_wavetransform.m_preoffset=2;
- m_wavetransform.m_aftoffset=15;
- break;
- case 20:
- Ld[0]=0.026670057901; Ld[1]=0.188176800078; Ld[2]=0.527201188932;
- Ld[3]=0.688459039454; Ld[4]=0.281172343661; Ld[5]=-0.249846424327;
- Ld[6]=-0.195946274377; Ld[7]=0.127369340336; Ld[8]=0.093057364604;
- Ld[9]=-0.071394147166; Ld[10]=-0.029457536822; Ld[11]=0.033212674059;
- Ld[12]=0.003606553567; Ld[13]=-0.010733175483; Ld[14]=0.001395351747;
- Ld[15]=0.001992405295; Ld[16]=-0.000685856695; Ld[17]=-0.000116466855;
- Ld[18]=0.000093588670; Ld[19]=-0.000013264203;
- m_wavetransform.m_preoffset=2;
- m_wavetransform.m_aftoffset=17;
- break;
- }
- }
- break;
- case 2://IDC_MORLET
- break;
- case 3://IDC_MEXICANHAT
- break;
- case 4://IDC_MEYER
- break;
- case 5://IDC_BSPLINE
- break;
- case 6://IDC_SYMLETS
- {
- switch(FWidth)
- {
- case 8:
- Ld[0]=-0.107148901418/sqrt(2); Ld[1]=-0.041910965126/sqrt(2); Ld[2]=0.703739068656/sqrt(2);
- Ld[3]=1.136658243409/sqrt(2); Ld[4]=0.421234534204/sqrt(2); Ld[5]=-0.140317624179/sqrt(2);
- Ld[6]=-0.017824701442/sqrt(2); Ld[7]=0.045570345896/sqrt(2);
- m_wavetransform.m_preoffset=3;
- m_wavetransform.m_aftoffset=4;
- break;
- case 10:
- Ld[0]=0.038654795955/sqrt(2); Ld[1]=0.041746864422/sqrt(2); Ld[2]=-0.055344186117/sqrt(2);
- Ld[3]=0.281990696854/sqrt(2); Ld[4]=1.023052966894/sqrt(2); Ld[5]=0.896581648380/sqrt(2);
- Ld[6]=0.023478923136/sqrt(2); Ld[7]=-0.247951362613/sqrt(2); Ld[8]=-0.029842499869/sqrt(2);
- Ld[9]=0.027632152958/sqrt(2);
- m_wavetransform.m_preoffset=4;
- m_wavetransform.m_aftoffset=5;
- break;
- case 12:
- Ld[0]=0.021784700327/sqrt(2); Ld[1]=0.004936612372/sqrt(2); Ld[2]=-0.166863215412/sqrt(2);
- Ld[3]=-0.068323121587/sqrt(2); Ld[4]=0.0694457972958/sqrt(2); Ld[5]=1.113892783926/sqrt(2);
- Ld[6]=0.477904371333/sqrt(2); Ld[7]=-0.102724969862/sqrt(2); Ld[8]=-0.029783751299/sqrt(2);
- Ld[9]=0.063250562660/sqrt(2); Ld[10]=0.002499922093/sqrt(2); Ld[11]=-0.011031867509/sqrt(2);
- m_wavetransform.m_preoffset=5;
- m_wavetransform.m_aftoffset=6;
- break;
- case 14:
- Ld[0]=0.003792658534/sqrt(2); Ld[1]=-0.001481225915/sqrt(2); Ld[2]=-0.017870431651/sqrt(2);
- Ld[3]=0.043155452582/sqrt(2); Ld[4]=0.096014767936/sqrt(2); Ld[5]=-0.070078291222/sqrt(2);
- Ld[6]=0.024665659489/sqrt(2); Ld[7]=0.758162601964/sqrt(2); Ld[8]=1.085782709814/sqrt(2);
- Ld[9]=0.408183939725/sqrt(2); Ld[10]=-0.198056706807/sqrt(2); Ld[11]=-0.152463872896/sqrt(2);
- Ld[12]=0.005671342686/sqrt(2); Ld[13]=0.014521394762/sqrt(2);
- m_wavetransform.m_preoffset=7;
- m_wavetransform.m_aftoffset=6;
- break;
- case 16:
- Ld[0]=0.002672793393/sqrt(2); Ld[1]=-0.000428394300/sqrt(2); Ld[2]=-0.021145686528/sqrt(2);
- Ld[3]=0.005386388754/sqrt(2); Ld[4]=0.069490465911/sqrt(2); Ld[5]=-0.038493521263/sqrt(2);
- Ld[6]=-0.073462508761/sqrt(2); Ld[7]=0.515398670374/sqrt(2); Ld[8]=1.099106630537/sqrt(2);
- Ld[9]=0.680745347190/sqrt(2); Ld[10]=-0.086653615406/sqrt(2); Ld[11]=-0.202648655286/sqrt(2);
- Ld[12]=0.010758611751/sqrt(2); Ld[13]=0.044823623042/sqrt(2); Ld[14]=-0.000766690896/sqrt(2);
- Ld[15]=-0.004783458512/sqrt(2);
- m_wavetransform.m_preoffset=8;
- m_wavetransform.m_aftoffset=7;
- break;
- case 18:
- Ld[0]=0.001512487309/sqrt(2); Ld[1]=-0.000669141509/sqrt(2); Ld[2]=-0.014515578553/sqrt(2);
- Ld[3]=0.012528896242/sqrt(2); Ld[4]=0.087791251554/sqrt(2); Ld[5]=-0.025786445930/sqrt(2);
- Ld[6]=-0.270893783503/sqrt(2); Ld[7]=0.049882830959/sqrt(2); Ld[8]=0.873048407349/sqrt(2);
- Ld[9]=1.015259790832/sqrt(2); Ld[10]=0.337658923602/sqrt(2); Ld[11]=-0.077172161097/sqrt(2);
- Ld[12]=0.000825140929/sqrt(2); Ld[13]=0.042744433602/sqrt(2); Ld[14]=-0.016303351226/sqrt(2);
- Ld[15]=-0.018769396836/sqrt(2); Ld[16]=0.000876502539/sqrt(2); Ld[17]=0.001981193736/sqrt(2);
- m_wavetransform.m_preoffset=8;
- m_wavetransform.m_aftoffset=9;
- break;
- case 20:
- Ld[0]=0.001089170447/sqrt(2); Ld[1]=0.000135245020/sqrt(2); Ld[2]=-0.012220642630/sqrt(2);
- Ld[3]=-0.002072363923/sqrt(2); Ld[4]=0.064950924579/sqrt(2); Ld[5]=0.016418869426/sqrt(2);
- Ld[6]=-0.225558972234/sqrt(2); Ld[7]=-0.100240215031/sqrt(2); Ld[8]=0.667071338154/sqrt(2);
- Ld[9]=1.088251530500/sqrt(2); Ld[10]=0.542813011213/sqrt(2); Ld[11]=-0.050256540092/sqrt(2);
- Ld[12]=-0.045240772218/sqrt(2); Ld[13]=0.070703567550/sqrt(2); Ld[14]=0.008152816799/sqrt(2);
- Ld[15]=-0.028786231926/sqrt(2); Ld[16]=-0.001137535314/sqrt(2); Ld[17]=0.006495728375/sqrt(2);
- Ld[18]=0.000080661204/sqrt(2); Ld[19]=-0.000649589896/sqrt(2);
- m_wavetransform.m_preoffset=9;
- m_wavetransform.m_aftoffset=10;
- break;
- }
- }
- break;
- case 7://IDC_COIFLETS
- Ld[0]=-0.0802861503271*sqrt(2); Ld[1]=-0.0243085969067*sqrt(2); Ld[2]=0.362806341593*sqrt(2);
- Ld[3]=0.550576616156*sqrt(2); Ld[4]=0.229036357075*sqrt(2); Ld[5]=-0.0644368523121*sqrt(2);
- Ld[6]=-0.0115565483406*sqrt(2); Ld[7]=0.0381688330633*sqrt(2);
- m_wavetransform.m_preoffset=3;
- m_wavetransform.m_aftoffset=4;
- break;
- }
- for(int i=0;i<FWidth;i++)
- {
- Hd[i]=pow(-1,i+1)*Ld[-i-1+FWidth];
- }
- for(i=0;i<FWidth;i++)
- {
- Lr[i]=Ld[-i-1+FWidth];
- Hr[i]=Hd[-i-1+FWidth];
- }
- }
- pDoc->UpdateAllViews(NULL);
- EndWaitCursor();
- }
- void CMyView::OnCompression()
- {
- // TODO: Add your command handler code here
- BeginWaitCursor();
- CMyDoc* pDoc = GetDocument();
- LPSTR lpDIB;
- // 指向DIB象素指针
- LPSTR lpDIBBits;
- // 锁定DIB
- lpDIB = (LPSTR) ::GlobalLock((HGLOBAL) pDoc->GetHDIB());
- // 找到DIB图像象素起始位置
- lpDIBBits = ::FindDIBBits(lpDIB);
- CWaveletLevel leveldlg;
- if(leveldlg.DoModal()==IDOK)
- {
- m_nLevel=leveldlg.m_nlevel;
- //分解
- m_wavetransform.DIBWavelet(lpDIB,lpDIBBits,Ld,Hd,FWidth,m_nLevel);
- pDoc->SetModifiedFlag(TRUE);
- pDoc->UpdateAllViews(NULL);
- }
- // 解除锁定
- ::GlobalUnlock((HGLOBAL) pDoc->GetHDIB());
- EndWaitCursor();
- }
- void CMyView::OnDiscompression()
- {
- // TODO: Add your command handler code here
- CMyDoc* pDoc = GetDocument();
- LPSTR lpDIB;
- // 指向DIB象素指针
- LPSTR lpDIBBits;
- // 锁定DIB
- lpDIB = (LPSTR) ::GlobalLock((HGLOBAL) pDoc->GetHDIB());
- // 找到DIB图像象素起始位置
- lpDIBBits = ::FindDIBBits(lpDIB);
- //重建
- m_wavetransform.DIBDisWavelet(lpDIB,lpDIBBits,Lr,Hr,FWidth,m_nLevel);
- pDoc->SetModifiedFlag(TRUE);
- pDoc->UpdateAllViews(NULL);
- // 解除锁定
- ::GlobalUnlock((HGLOBAL) pDoc->GetHDIB());
- }
- void CMyView::OnDiprocFusion2()
- {
- // TODO: Add your command handler code here
- //读取数字图像的文件头,获取图像的属性参数
- CMyDoc* pDoc = GetDocument();
- LPSTR lpDIB1;
- // 指向DIB象素指针
- LPSTR lpDIBBits1;
- LPSTR lpDIB2;
- // 指向DIB象素指针
- LPSTR lpDIBBits2;
- // 锁定DIB
- lpDIB1 = (LPSTR) ::GlobalLock((HGLOBAL)pDoc->GetHDIB());
- // 找到DIB图像象素起始位置
- lpDIBBits1 = ::FindDIBBits(lpDIB1);
- unsigned long lWidth =::DIBWidth(lpDIB1);
- unsigned long lHeight = ::DIBHeight(lpDIB1);
- Dwvlttrans(lpDIB1,lpDIBBits1);
- pDoc->SetModifiedFlag(TRUE);
- pDoc->UpdateAllViews(NULL);
- pDoc->Openanother();
- pDoc->SetModifiedFlag(TRUE);
- //显示新打开的图像
- pDoc->UpdateAllViews(NULL);
- lpDIB2 = (LPSTR) ::GlobalLock((HGLOBAL)pDoc->m_hMulDIB);
- // 找到DIB图像象素起始位置
- lpDIBBits2 = ::FindDIBBits(lpDIB2);
- Dwvlttrans(lpDIB2,lpDIBBits2);
- pDoc->SetModifiedFlag(TRUE);
- pDoc->UpdateAllViews(NULL);
- m_wavetransform.DIP_ImageFusion2(lpDIB1,lpDIBBits1,lpDIB2,lpDIBBits2,m_nLevel);
- pDoc->SetModifiedFlag(TRUE);
- pDoc->UpdateAllViews(NULL);
- ::GlobalUnlock((HGLOBAL) pDoc->GetHDIB());
- ::GlobalUnlock((HGLOBAL) pDoc->m_hMulDIB);
- lpDIB1 = (LPSTR) ::GlobalLock((HGLOBAL)pDoc->GetHDIB() );
- // 找到DIB图像象素起始位置
- lpDIBBits1 = ::FindDIBBits(lpDIB1);
- m_wavetransform.DIBDisWavelet(lpDIB1,lpDIBBits1,Lr,Hr,FWidth,m_nLevel);
- pDoc->SetModifiedFlag(TRUE);
- pDoc->UpdateAllViews(NULL);
- // 解除锁定
- ::GlobalUnlock((HGLOBAL) pDoc->GetHDIB());
- ::GlobalUnlock((HGLOBAL) pDoc->m_hMulDIB);
- }
- void CMyView::OnDiprocFusion3()
- {
- CMyDoc* pDoc = GetDocument();
- LPSTR lpDIB1;
- // 指向DIB象素指针
- LPSTR lpDIBBits1;
- LPSTR lpDIB2;
- // 指向DIB象素指针
- LPSTR lpDIBBits2;
- // 锁定DIB
- lpDIB1 = (LPSTR) ::GlobalLock((HGLOBAL)pDoc->GetHDIB());
- // 找到DIB图像象素起始位置
- lpDIBBits1 = ::FindDIBBits(lpDIB1);
- unsigned long lWidth =::DIBWidth(lpDIB1);
- unsigned long lHeight = ::DIBHeight(lpDIB1);
- Swvlttrans(lpDIB1,lpDIBBits1);
- pDoc->SetModifiedFlag(TRUE);
- pDoc->UpdateAllViews(NULL);
- pDoc->Openanother();
- pDoc->SetModifiedFlag(TRUE);
- //显示新打开的图像
- pDoc->UpdateAllViews(NULL);
- lpDIB2 = (LPSTR) ::GlobalLock((HGLOBAL)pDoc->m_hMulDIB);
- // 找到DIB图像象素起始位置
- lpDIBBits2 = ::FindDIBBits(lpDIB2);
- Swvlttrans(lpDIB2,lpDIBBits2);
- pDoc->SetModifiedFlag(TRUE);
- pDoc->UpdateAllViews(NULL);
- m_wavetransform.DIP_ImageFusion2(lpDIB1,lpDIBBits1,lpDIB2,lpDIBBits2,m_nLevel);
- pDoc->SetModifiedFlag(TRUE);
- pDoc->UpdateAllViews(NULL);
- ::GlobalUnlock((HGLOBAL) pDoc->GetHDIB());
- ::GlobalUnlock((HGLOBAL) pDoc->m_hMulDIB);
- lpDIB1 = (LPSTR) ::GlobalLock((HGLOBAL)pDoc->GetHDIB() );
- // 找到DIB图像象素起始位置
- lpDIBBits1 = ::FindDIBBits(lpDIB1);
- m_wavetransform.DIBDisWavelet(lpDIB1,lpDIBBits1,Lr,Hr,FWidth,m_nLevel);
- pDoc->SetModifiedFlag(TRUE);
- pDoc->UpdateAllViews(NULL);
- // 解除锁定
- ::GlobalUnlock((HGLOBAL) pDoc->GetHDIB());
- ::GlobalUnlock((HGLOBAL) pDoc->m_hMulDIB);
- }
- void CMyView::OnDiprocFusion4()
- {
- // TODO: Add your command handler code here
- //读取数字图像的文件头,获取图像的属性参数
- CMyDoc* pDoc = GetDocument();
- LPSTR lpDIB1;
- // 指向DIB象素指针
- LPSTR lpDIBBits1;
- LPSTR lpDIB2;
- // 指向DIB象素指针
- LPSTR lpDIBBits2;
- // 锁定DIB
- lpDIB1 = (LPSTR) ::GlobalLock((HGLOBAL)pDoc->GetHDIB());
- // 找到DIB图像象素起始位置
- lpDIBBits1 = ::FindDIBBits(lpDIB1);
- unsigned long lWidth =::DIBWidth(lpDIB1);
- unsigned long lHeight = ::DIBHeight(lpDIB1);
- Cwvlttrans(lpDIB1,lpDIBBits1);
- pDoc->SetModifiedFlag(TRUE);
- pDoc->UpdateAllViews(NULL);
- pDoc->Openanother();
- pDoc->SetModifiedFlag(TRUE);
- //显示新打开的图像
- pDoc->UpdateAllViews(NULL);
- lpDIB2 = (LPSTR) ::GlobalLock((HGLOBAL)pDoc->m_hMulDIB);
- // 找到DIB图像象素起始位置
- lpDIBBits2 = ::FindDIBBits(lpDIB2);
- Cwvlttrans(lpDIB2,lpDIBBits2);
- pDoc->SetModifiedFlag(TRUE);
- pDoc->UpdateAllViews(NULL);
- m_wavetransform.DIP_ImageFusion2(lpDIB1,lpDIBBits1,lpDIB2,lpDIBBits2,m_nLevel);
- pDoc->SetModifiedFlag(TRUE);
- pDoc->UpdateAllViews(NULL);
- ::GlobalUnlock((HGLOBAL) pDoc->GetHDIB());
- ::GlobalUnlock((HGLOBAL) pDoc->m_hMulDIB);
- lpDIB1 = (LPSTR) ::GlobalLock((HGLOBAL)pDoc->GetHDIB());
- // 找到DIB图像象素起始位置
- lpDIBBits1 = ::FindDIBBits(lpDIB1);
- m_wavetransform.DIBDisWavelet(lpDIB1,lpDIBBits1,Lr,Hr,FWidth,m_nLevel);
- pDoc->SetModifiedFlag(TRUE);
- pDoc->UpdateAllViews(NULL);
- // 解除锁定
- ::GlobalUnlock((HGLOBAL) pDoc->GetHDIB());
- ::GlobalUnlock((HGLOBAL) pDoc->m_hMulDIB);
- }
- BOOL CMyView::Dwvlttrans(LPSTR lpDIB,LPSTR lpDIBBits)
- {
- CMyDoc* pDoc = GetDocument();
- Ld = new double[20]; //分解尺度函数
- Hd = new double[20]; //分解母函数
- Lr = new double[20]; //重建尺度函数
- Hr = new double[20]; //重建母函数
- CDaubechiesdlg daubechiesdlg;
- if(daubechiesdlg.DoModal()==IDOK)
- {
- FWidth=2*daubechiesdlg.m_nlength;
- switch(FWidth)
- {
- case 2:
- Ld[0]=1/sqrt(2); Ld[1]=1/sqrt(2);
- m_wavetransform.m_preoffset=0;
- m_wavetransform.m_aftoffset=1;
- break;
- case 4:
- Ld[0]=0.4829629131445341; Ld[1]=0.8365163037378077; Ld[2]=0.2241438680420134;
- Ld[3]=-0.1294095225512603;
- m_wavetransform.m_preoffset=0;
- m_wavetransform.m_aftoffset=3;
- break;
- case 6:
- Ld[0]=0.3326705529500825; Ld[1]=0.8068915093110924; Ld[2]=0.4598775021184914;
- Ld[3]=-0.1350110200102546; Ld[4]=-0.0854412738820267; Ld[5]=0.035226218857095;
- m_wavetransform.m_preoffset=1;
- m_wavetransform.m_aftoffset=4;
- break;
- case 8:
- Ld[0]=0.230377813309; Ld[1]=0.714846570553; Ld[2]=0.630880767930;
- Ld[3]=-0.027983769417; Ld[4]=-0.187034811719; Ld[5]=0.030841381836;
- Ld[6]=0.032883011667; Ld[7]=-0.010597401785;
- m_wavetransform.m_preoffset=1;
- m_wavetransform.m_aftoffset=6;
- break;
- case 10:
- Ld[0]=0.160102397974; Ld[1]=0.603829269797; Ld[2]=0.724308528438;
- Ld[3]=0.138428145901; Ld[4]=-0.242294887066; Ld[5]=-0.032244869585;
- Ld[6]=0.077571493840; Ld[7]=-0.006241490213; Ld[8]=-0.012580751999;
- Ld[9]=0.003335725285;
- m_wavetransform.m_preoffset=1;
- m_wavetransform.m_aftoffset=8;
- break;
- case 12:
- Ld[0]=0.111540743350; Ld[1]=0.494623890398; Ld[2]=0.751133908021;
- Ld[3]=0.315250351709; Ld[4]=-0.226264693965; Ld[5]=-0.129766867567;
- Ld[6]=0.097501605587; Ld[7]=0.027522865530; Ld[8]=-0.031582039318;
- Ld[9]=0.000553842201; Ld[10]=0.004777257511; Ld[11]=-0.001077301085;
- m_wavetransform.m_preoffset=1;
- m_wavetransform.m_aftoffset=10;
- break;
- case 14:
- Ld[0]=0.077852054085; Ld[1]=0.396539319482; Ld[2]=0.729132090846;
- Ld[3]=0.469782287405; Ld[4]=-0.143906003929; Ld[5]=-0.224036184994;
- Ld[6]=0.071309219267; Ld[7]=0.080612609151; Ld[8]=-0.038029936935;
- Ld[9]=-0.016574541631; Ld[10]=0.012550998556; Ld[11]=0.000429577973;
- Ld[12]=-0.001801640704; Ld[13]=0.000353713800;
- m_wavetransform.m_preoffset=1;
- m_wavetransform.m_aftoffset=12;
- break;
- case 16:
- Ld[0]=0.054415842243; Ld[1]=0.312871590914; Ld[2]=0.675630736297;
- Ld[3]=0.585354683654; Ld[4]=-0.015829105256; Ld[5]=-0.284015542962;
- Ld[6]=0.000472484574; Ld[7]=0.128747426620; Ld[8]=-0.017369301002;
- Ld[9]=-0.044088253931; Ld[10]=0.013981027917; Ld[11]=0.008746094047;
- Ld[12]=-0.004870352993; Ld[13]=-0.000391740373; Ld[14]=0.000675449406;
- Ld[15]=-0.000117476784;
- m_wavetransform.m_preoffset=1;
- m_wavetransform.m_aftoffset=14;
- break;
- case 18:
- Ld[0]=0.038077947364; Ld[1]=0.243834674613; Ld[2]=0.604823123690;
- Ld[3]=0.657288078051; Ld[4]=0.133197385825; Ld[5]=-0.293273783279;
- Ld[6]=-0.096840783223; Ld[7]=0.148540749338; Ld[8]=0.030725681479;
- Ld[9]=-0.067632829061; Ld[10]=0.000250947115; Ld[11]=0.022361662124;
- Ld[12]=-0.004723204758; Ld[13]=-0.004281503682; Ld[14]=0.001847646883;
- Ld[15]=0.000230385764; Ld[16]=-0.000251963189; Ld[17]=0.000039347320;
- m_wavetransform.m_preoffset=2;
- m_wavetransform.m_aftoffset=15;
- break;
- case 20:
- Ld[0]=0.026670057901; Ld[1]=0.188176800078; Ld[2]=0.527201188932;
- Ld[3]=0.688459039454; Ld[4]=0.281172343661; Ld[5]=-0.249846424327;
- Ld[6]=-0.195946274377; Ld[7]=0.127369340336; Ld[8]=0.093057364604;
- Ld[9]=-0.071394147166; Ld[10]=-0.029457536822; Ld[11]=0.033212674059;
- Ld[12]=0.003606553567; Ld[13]=-0.010733175483; Ld[14]=0.001395351747;
- Ld[15]=0.001992405295; Ld[16]=-0.000685856695; Ld[17]=-0.000116466855;
- Ld[18]=0.000093588670; Ld[19]=-0.000013264203;
- m_wavetransform.m_preoffset=2;
- m_wavetransform.m_aftoffset=17;
- break;
- }
-
- for(int i=0;i<FWidth;i++)
- {
- Hd[i]=pow(-1,i+1)*Ld[-i-1+FWidth];
- }
- for(i=0;i<FWidth;i++)
- {
- Lr[i]=Ld[-i-1+FWidth];
- Hr[i]=Hd[-i-1+FWidth];
- }
- }
- CWaveletLevel leveldlg;
- if(leveldlg.DoModal()==IDOK)
- {
- m_nLevel=leveldlg.m_nlevel;
- //分解
- m_wavetransform.DIBWavelet(lpDIB,lpDIBBits,Ld,Hd,FWidth,m_nLevel);
- pDoc->SetModifiedFlag(TRUE);
- pDoc->UpdateAllViews(NULL);
- }
- return TRUE;// 返回
- }
- BOOL CMyView::Swvlttrans(LPSTR lpDIB,LPSTR lpDIBBits)
- {
- CMyDoc* pDoc = GetDocument();
- Ld = new double[20]; //分解尺度函数
- Hd = new double[20]; //分解母函数
- Lr = new double[20]; //重建尺度函数
- Hr = new double[20]; //重建母函数
- CSymletsdlg symdlg;
- if(symdlg.DoModal()==IDOK)
- { FWidth=2*symdlg.m_symlength;
- switch(FWidth)
- {
- case 8:
- Ld[0]=-0.107148901418/sqrt(2); Ld[1]=-0.041910965126/sqrt(2); Ld[2]=0.703739068656/sqrt(2);
- Ld[3]=1.136658243409/sqrt(2); Ld[4]=0.421234534204/sqrt(2); Ld[5]=-0.140317624179/sqrt(2);
- Ld[6]=-0.017824701442/sqrt(2); Ld[7]=0.045570345896/sqrt(2);
- m_wavetransform.m_preoffset=3;
- m_wavetransform.m_aftoffset=4;
- break;
- case 10:
- Ld[0]=0.038654795955/sqrt(2); Ld[1]=0.041746864422/sqrt(2); Ld[2]=-0.055344186117/sqrt(2);
- Ld[3]=0.281990696854/sqrt(2); Ld[4]=1.023052966894/sqrt(2); Ld[5]=0.896581648380/sqrt(2);
- Ld[6]=0.023478923136/sqrt(2); Ld[7]=-0.247951362613/sqrt(2); Ld[8]=-0.029842499869/sqrt(2);
- Ld[9]=0.027632152958/sqrt(2);
- m_wavetransform.m_preoffset=4;
- m_wavetransform.m_aftoffset=5;
- break;
- case 12:
- Ld[0]=0.021784700327/sqrt(2); Ld[1]=0.004936612372/sqrt(2); Ld[2]=-0.166863215412/sqrt(2);
- Ld[3]=-0.068323121587/sqrt(2); Ld[4]=0.0694457972958/sqrt(2); Ld[5]=1.113892783926/sqrt(2);
- Ld[6]=0.477904371333/sqrt(2); Ld[7]=-0.102724969862/sqrt(2); Ld[8]=-0.029783751299/sqrt(2);
- Ld[9]=0.063250562660/sqrt(2); Ld[10]=0.002499922093/sqrt(2); Ld[11]=-0.011031867509/sqrt(2);
- m_wavetransform.m_preoffset=5;
- m_wavetransform.m_aftoffset=6;
- break;
- case 14:
- Ld[0]=0.003792658534/sqrt(2); Ld[1]=-0.001481225915/sqrt(2); Ld[2]=-0.017870431651/sqrt(2);
- Ld[3]=0.043155452582/sqrt(2); Ld[4]=0.096014767936/sqrt(2); Ld[5]=-0.070078291222/sqrt(2);
- Ld[6]=0.024665659489/sqrt(2); Ld[7]=0.758162601964/sqrt(2); Ld[8]=1.085782709814/sqrt(2);
- Ld[9]=0.408183939725/sqrt(2); Ld[10]=-0.198056706807/sqrt(2); Ld[11]=-0.152463872896/sqrt(2);
- Ld[12]=0.005671342686/sqrt(2); Ld[13]=0.014521394762/sqrt(2);
- m_wavetransform.m_preoffset=7;
- m_wavetransform.m_aftoffset=6;
- break;
- case 16:
- Ld[0]=0.002672793393/sqrt(2); Ld[1]=-0.000428394300/sqrt(2); Ld[2]=-0.021145686528/sqrt(2);
- Ld[3]=0.005386388754/sqrt(2); Ld[4]=0.069490465911/sqrt(2); Ld[5]=-0.038493521263/sqrt(2);
- Ld[6]=-0.073462508761/sqrt(2); Ld[7]=0.515398670374/sqrt(2); Ld[8]=1.099106630537/sqrt(2);
- Ld[9]=0.680745347190/sqrt(2); Ld[10]=-0.086653615406/sqrt(2); Ld[11]=-0.202648655286/sqrt(2);
- Ld[12]=0.010758611751/sqrt(2); Ld[13]=0.044823623042/sqrt(2); Ld[14]=-0.000766690896/sqrt(2);
- Ld[15]=-0.004783458512/sqrt(2);
- m_wavetransform.m_preoffset=8;
- m_wavetransform.m_aftoffset=7;
- break;
- case 18:
- Ld[0]=0.001512487309/sqrt(2); Ld[1]=-0.000669141509/sqrt(2); Ld[2]=-0.014515578553/sqrt(2);
- Ld[3]=0.012528896242/sqrt(2); Ld[4]=0.087791251554/sqrt(2); Ld[5]=-0.025786445930/sqrt(2);
- Ld[6]=-0.270893783503/sqrt(2); Ld[7]=0.049882830959/sqrt(2); Ld[8]=0.873048407349/sqrt(2);
- Ld[9]=1.015259790832/sqrt(2); Ld[10]=0.337658923602/sqrt(2); Ld[11]=-0.077172161097/sqrt(2);
- Ld[12]=0.000825140929/sqrt(2); Ld[13]=0.042744433602/sqrt(2); Ld[14]=-0.016303351226/sqrt(2);
- Ld[15]=-0.018769396836/sqrt(2); Ld[16]=0.000876502539/sqrt(2); Ld[17]=0.001981193736/sqrt(2);
- m_wavetransform.m_preoffset=8;
- m_wavetransform.m_aftoffset=9;
- break;
- case 20:
- Ld[0]=0.001089170447/sqrt(2); Ld[1]=0.000135245020/sqrt(2); Ld[2]=-0.012220642630/sqrt(2);
- Ld[3]=-0.002072363923/sqrt(2); Ld[4]=0.064950924579/sqrt(2); Ld[5]=0.016418869426/sqrt(2);
- Ld[6]=-0.225558972234/sqrt(2); Ld[7]=-0.100240215031/sqrt(2); Ld[8]=0.667071338154/sqrt(2);
- Ld[9]=1.088251530500/sqrt(2); Ld[10]=0.542813011213/sqrt(2); Ld[11]=-0.050256540092/sqrt(2);
- Ld[12]=-0.045240772218/sqrt(2); Ld[13]=0.070703567550/sqrt(2); Ld[14]=0.008152816799/sqrt(2);
- Ld[15]=-0.028786231926/sqrt(2); Ld[16]=-0.001137535314/sqrt(2); Ld[17]=0.006495728375/sqrt(2);
- Ld[18]=0.000080661204/sqrt(2); Ld[19]=-0.000649589896/sqrt(2);
- m_wavetransform.m_preoffset=9;
- m_wavetransform.m_aftoffset=10;
- break;
- }
- for(int i=0;i<FWidth;i++)
- {
- Hd[i]=pow(-1,i+1)*Ld[-i-1+FWidth];
- }
- for(i=0;i<FWidth;i++)
- {
- Lr[i]=Ld[-i-1+FWidth];
- Hr[i]=Hd[-i-1+FWidth];
- }
- }
- CWaveletLevel leveldlg;
- if(leveldlg.DoModal()==IDOK)
- {
- m_nLevel=leveldlg.m_nlevel;
- //分解
- m_wavetransform.DIBWavelet(lpDIB,lpDIBBits,Ld,Hd,FWidth,m_nLevel);
- pDoc->SetModifiedFlag(TRUE);
- pDoc->UpdateAllViews(NULL);
- }
- return TRUE;// 返回
- }
- BOOL CMyView::Cwvlttrans(LPSTR lpDIB,LPSTR lpDIBBits)
- {
- CMyDoc* pDoc = GetDocument();
- Ld = new double[20]; //分解尺度函数
- Hd = new double[20]; //分解母函数
- Lr = new double[20]; //重建尺度函数
- Hr = new double[20]; //重建母函数
- FWidth=8;
- Ld[0]=-0.0802861503271*sqrt(2); Ld[1]=-0.0243085969067*sqrt(2); Ld[2]=0.362806341593*sqrt(2);
- Ld[3]=0.550576616156*sqrt(2); Ld[4]=0.229036357075*sqrt(2); Ld[5]=-0.0644368523121*sqrt(2);
- Ld[6]=-0.0115565483406*sqrt(2); Ld[7]=0.0381688330633*sqrt(2);
- m_wavetransform.m_preoffset=3;
- m_wavetransform.m_aftoffset=4;
- for(int i=0;i<FWidth;i++)
- {
- Hd[i]=pow(-1,i+1)*Ld[-i-1+FWidth];
- }
- for(i=0;i<FWidth;i++)
- {
- Lr[i]=Ld[-i-1+FWidth];
- Hr[i]=Hd[-i-1+FWidth];
- }
- CWaveletLevel leveldlg;
- if(leveldlg.DoModal()==IDOK)
- {
- m_nLevel=leveldlg.m_nlevel;
- //分解
- m_wavetransform.DIBWavelet(lpDIB,lpDIBBits,Ld,Hd,FWidth,m_nLevel);
- pDoc->SetModifiedFlag(TRUE);
- pDoc->UpdateAllViews(NULL);
- }
- return TRUE;// 返回
- }
- void CMyView::OnImageHebing()
- {
- CHebingDlg dlg;
- dlg.DoModal();
- }
- void CMyView::OnDetectTemplate()
- {
- // 获取文档
- CMyDoc* pDoc = GetDocument();
-
- // 指向DIB的指针
- LPSTR lpDIB,lpTemplateDIB;
- // 指向DIB象素指针
- LPSTR lpDIBBits,lpTemplateDIBBits;
-
- //图像的宽度与高度
- long lWidth,lHeight;
- //模板的宽度与高度
- long lTemplateWidth,lTemplateHeight;
- HDIB hTemplateDIB;
- // 锁定DIB
- lpDIB = (LPSTR) ::GlobalLock((HGLOBAL) pDoc->GetHDIB());
-
-
- // 判断是否是8-bpp位图(这里为了方便,只处理8-bpp位图的水平镜像,其它的可以类推)
- if (::DIBNumColors(lpDIB) != 256)
- {
- // 提示用户
- MessageBox("目前只支持256色位图的平移!", "系统提示" , MB_ICONINFORMATION | MB_OK);
- // 解除锁定
- ::GlobalUnlock((HGLOBAL) pDoc->GetHDIB());
-
- // 返回
- return;
- }
-
-
- // 更改光标形状
- BeginWaitCursor();
- // 找到DIB图像象素起始位置
- lpDIBBits = ::FindDIBBits(lpDIB);
-
- lWidth = ::DIBWidth(lpDIB);
- lHeight = ::DIBHeight(lpDIB);
- CFileDialog dlg(TRUE,"bmp","*.bmp");
- if(dlg.DoModal() == IDOK)
- {
-
- CFile file;
- CFileException fe;
-
- CString strPathName;
-
- strPathName = dlg.GetPathName();
-
- // 打开文件
- VERIFY(file.Open(strPathName, CFile::modeRead | CFile::shareDenyWrite, &fe));
- // 尝试调用ReadDIBFile()读取图像
- TRY
- {
- hTemplateDIB = ::ReadDIBFile(file);
- }
- CATCH (CFileException, eLoad)
- {
- // 读取失败
- file.Abort();
-
- // 恢复光标形状
- EndWaitCursor();
-
- // 报告失败
- //ReportSaveLoadException(strPathName, eLoad,
- // FALSE, AFX_IDP_FAILED_TO_OPEN_DOC);
-
- // 设置DIB为空
- hTemplateDIB = NULL;
-
- // 返回
- return;
- }
- END_CATCH
-
- // 初始化DIB
- //InitDIBData();
-
- // 判断读取文件是否成功
- if (hTemplateDIB == NULL)
- {
- // 失败,可能非BMP格式
- CString strMsg;
- strMsg = "读取图像时出错!可能是不支持该类型的图像文件!";
-
- // 提示出错
- MessageBox(strMsg, NULL, MB_ICONINFORMATION | MB_OK);
-
- // 恢复光标形状
- EndWaitCursor();
-
- // 返回
- return;
- }
- }
- else
- {
- // 恢复光标形状
- EndWaitCursor();
- return;
- }
- // 锁定DIB
- lpTemplateDIB = (LPSTR) ::GlobalLock((HGLOBAL) hTemplateDIB);
-
- // 判断是否是8-bpp位图(这里为了方便,只处理8-bpp位图的模板匹配,其它的可以类推)
- if (::DIBNumColors(lpTemplateDIB) != 256)
- {
- // 提示用户
- MessageBox("目前只支持256色位图!", "系统提示" , MB_ICONINFORMATION | MB_OK);
- // 解除锁定
- ::GlobalUnlock((HGLOBAL) hTemplateDIB);
-
- // 返回
- return;
- }
-
-
- // 更改光标形状
- BeginWaitCursor();
- // 找到DIB图像象素起始位置
- lpTemplateDIBBits = ::FindDIBBits(lpTemplateDIB);
-
- lTemplateWidth = ::DIBWidth(lpTemplateDIB);
- lTemplateHeight = ::DIBHeight(lpTemplateDIB);
- if(lTemplateHeight > lHeight || lTemplateWidth > lWidth )
- {
- // 提示用户
- MessageBox("模板尺寸大于源图像尺寸!", "系统提示" , MB_ICONINFORMATION | MB_OK);
- // 解除锁定
- ::GlobalUnlock((HGLOBAL) hTemplateDIB);
-
- // 返回
- return;
- }
- // 调用TemplateMatchDIB()函数进行模板匹配
- if (TemplateMatchDIB(lpDIBBits,lpTemplateDIBBits, lWidth,lHeight, lTemplateWidth,lTemplateHeight))
- {
-
- // 设置脏标记
- pDoc->SetModifiedFlag(TRUE);
- // 更新视图
- pDoc->UpdateAllViews(NULL);
- }
- else
- {
- // 提示用户
- MessageBox("分配内存失败!", "系统提示" , MB_ICONINFORMATION | MB_OK);
- }
-
- // 解除锁定
- ::GlobalUnlock((HGLOBAL) pDoc->GetHDIB());
- ::GlobalUnlock((HGLOBAL) hTemplateDIB);
- // 恢复光标
- EndWaitCursor();
-
- }