www.pudn.com > VC_图像小波分解.rar > ImgDemoView.cpp
// ImgDemoView.cpp : implementation of the CImgDemoView class // #include "stdafx.h" #include "ImgDemo.h" #include "ImgDemoDoc.h" #include "ImgDemoView.h" #include#ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif #define WIDTHBYTES(bits) (((bits) + 31) / 32 * 4) ///////////////////////////////////////////////////////////////////////////// // CImgDemoView IMPLEMENT_DYNCREATE(CImgDemoView, CScrollView) BEGIN_MESSAGE_MAP(CImgDemoView, CScrollView) //{{AFX_MSG_MAP(CImgDemoView) ON_WM_SIZE() ON_COMMAND(ID_INVERTCOLOR, OnInvertcolor) ON_COMMAND(ID_LIGHTEN, OnLighten) ON_COMMAND(ID_DELIGHTEN, OnDelighten) ON_COMMAND(ID_PRC_LOG, OnPrcLog) ON_COMMAND(ID_PRC_EXP, OnPrcExp) ON_COMMAND(ID_PRC_2562BIN, OnPrc2562bin) ON_COMMAND(ID_PRC_256to8, OnPRC256to8) ON_COMMAND(ID_GRAY_EXTENTION, OnGrayExtention) ON_COMMAND(ID_P0, OnP0) ON_COMMAND(ID_P7, OnP7) ON_COMMAND(ID_P3, OnP3) ON_COMMAND(ID_WT_DAU_fenjie, OnWT_DAU_fenjie) ON_COMMAND(ID_WT_DAU_fenjie2, OnWTDAUfenjie2) ON_COMMAND(ID_WT_DAU_fenjie3, OnWTDAUfenjie3) ON_COMMAND(ID_WT_DAU_fenjie4, OnWTDAUfenjie4) ON_COMMAND(ID_WT_DAU_fenjie5, OnWTDAUfenjie5) //}}AFX_MSG_MAP // Standard printing commands ON_COMMAND(ID_FILE_PRINT, CScrollView::OnFilePrint) ON_COMMAND(ID_FILE_PRINT_DIRECT, CScrollView::OnFilePrint) ON_COMMAND(ID_FILE_PRINT_PREVIEW, CScrollView::OnFilePrintPreview) END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // CImgDemoView construction/destruction CImgDemoView::CImgDemoView() { // TODO: add construction code here } CImgDemoView::~CImgDemoView() { } BOOL CImgDemoView::PreCreateWindow(CREATESTRUCT& cs) { // TODO: Modify the Window class or styles here by modifying // the CREATESTRUCT cs //cs.lpszName ="hhh"; return CScrollView::PreCreateWindow(cs); } ///////////////////////////////////////////////////////////////////////////// // CImgDemoView drawing void CImgDemoView::OnDraw(CDC* pDC) { int i,j; unsigned char *lpSrc; CImgDemoDoc* pDoc = GetDocument(); ASSERT_VALID(pDoc); if(pDoc->m_hDIB == NULL) return ; // TODO: add draw code for native data here LPSTR lpDIB = (LPSTR) ::GlobalLock((HGLOBAL) pDoc->m_hDIB); int cxDIB = (int) ::DIBWidth(lpDIB); // Size of DIB - x int cyDIB = (int) ::DIBHeight(lpDIB); // Size of DIB - y LPSTR lpDIBBits=::FindDIBBits (lpDIB); // 计算图像每行的字节数 long lLineBytes = WIDTHBYTES(cxDIB * 8); // 每行 for(i = 0; i < cyDIB; i++) { // 每列 for(j = 0; j < cxDIB; j++) { // 指向DIB第i行,第j个象素的指针 lpSrc = (unsigned char*)lpDIBBits + lLineBytes * (cyDIB - 1 - i) + j; // 计算新的灰度值 //*(lpSrc) = BYTE(255-*lpSrc); } } ::GlobalUnlock((HGLOBAL) pDoc->m_hDIB); CRect rect(0,0,cxDIB,cyDIB), rcDIB(0,0,cxDIB,cyDIB); ::PaintDIB(pDC->m_hDC, &rect, pDoc->m_hDIB, &rcDIB, pDoc->m_palDIB); } void CImgDemoView::OnInitialUpdate() { CScrollView::OnInitialUpdate(); CSize sizeTotal; // TODO: calculate the total size of this view // sizeTotal.cx = sizeTotal.cy = 100; SetScrollSizes(MM_TEXT, GetDocument()->m_nDocSize); } ///////////////////////////////////////////////////////////////////////////// // CImgDemoView printing BOOL CImgDemoView::OnPreparePrinting(CPrintInfo* pInfo) { // default preparation return DoPreparePrinting(pInfo); } void CImgDemoView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/) { // TODO: add extra initialization before printing } void CImgDemoView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/) { // TODO: add cleanup after printing } ///////////////////////////////////////////////////////////////////////////// // CImgDemoView diagnostics #ifdef _DEBUG void CImgDemoView::AssertValid() const { CScrollView::AssertValid(); } void CImgDemoView::Dump(CDumpContext& dc) const { CScrollView::Dump(dc); } CImgDemoDoc* CImgDemoView::GetDocument() // non-debug version is inline { ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CImgDemoDoc))); return (CImgDemoDoc*)m_pDocument; } #endif //_DEBUG ///////////////////////////////////////////////////////////////////////////// // CImgDemoView message handlers void CImgDemoView::OnSize(UINT nType, int cx, int cy) { CScrollView::OnSize(nType, cx, cy); // TODO: Add your message handler code here } void CImgDemoView::OnInvertcolor() { // TODO: Add your command handler code here int i,j; unsigned char *lpSrc; CImgDemoDoc* pDoc = GetDocument(); ASSERT_VALID(pDoc); if(pDoc->m_hDIB == NULL) return ; LPSTR lpDIB = (LPSTR) ::GlobalLock((HGLOBAL) pDoc->m_hDIB); int cxDIB = (int) ::DIBWidth(lpDIB); // Size of DIB - x int cyDIB = (int) ::DIBHeight(lpDIB); // Size of DIB - y LPSTR lpDIBBits=::FindDIBBits (lpDIB); // 计算图像每行的字节数 long lLineBytes = WIDTHBYTES(cxDIB * 8); // 每行 for(i = 0; i < cyDIB; i++) { // 每列 for(j = 0; j < cxDIB; j++) { // 指向DIB第i行,第j个象素的指针 lpSrc = (unsigned char*)lpDIBBits + lLineBytes * (cyDIB - 1 - i) + j; // 计算新的灰度值 *(lpSrc) = BYTE(255-*lpSrc); } } ::GlobalUnlock((HGLOBAL) pDoc->m_hDIB); Invalidate(TRUE); } void CImgDemoView::OnGrayext() { } void CImgDemoView::OnLighten() { // TODO: Add your command handler code here int i,j; unsigned char *lpSrc; CImgDemoDoc* pDoc = GetDocument(); ASSERT_VALID(pDoc); if(pDoc->m_hDIB == NULL) return ; LPSTR lpDIB = (LPSTR) ::GlobalLock((HGLOBAL) pDoc->m_hDIB); LPSTR lpDIBBits=::FindDIBBits (lpDIB); int cxDIB = (int) ::DIBWidth(lpDIB); // Size of DIB - x int cyDIB = (int) ::DIBHeight(lpDIB); // Size of DIB - y long lLineBytes = WIDTHBYTES(cxDIB * 8); // 计算图像每行的字节数 // 每行 for(i = 0; i < cyDIB; i++) { // 每列 for(j = 0; j < cxDIB; j++) { // 指向DIB第i行,第j个象素的指针 lpSrc = (unsigned char*)lpDIBBits + lLineBytes * (cyDIB - 1 - i) + j; // 计算新的灰度值 if(*lpSrc<239) *(lpSrc) = BYTE(16+*lpSrc); } } ::GlobalUnlock((HGLOBAL) pDoc->m_hDIB); Invalidate(TRUE); } void CImgDemoView::OnDelighten() { // TODO: Add your command handler code here int i,j; unsigned char *lpSrc; CImgDemoDoc* pDoc = GetDocument(); ASSERT_VALID(pDoc); if(pDoc->m_hDIB == NULL) return ; LPSTR lpDIB = (LPSTR) ::GlobalLock((HGLOBAL) pDoc->m_hDIB); LPSTR lpDIBBits=::FindDIBBits (lpDIB); int cxDIB = (int) ::DIBWidth(lpDIB); // Size of DIB - x int cyDIB = (int) ::DIBHeight(lpDIB); // Size of DIB - y long lLineBytes = WIDTHBYTES(cxDIB * 8); // 计算图像每行的字节数 // 每行 for(i = 0; i < cyDIB; i++) { // 每列 for(j = 0; j < cxDIB; j++) { // 指向DIB第i行,第j个象素的指针 lpSrc = (unsigned char*)lpDIBBits + lLineBytes * (cyDIB - 1 - i) + j; // 计算新的灰度值 if(*lpSrc>=16) *(lpSrc) = BYTE(*lpSrc-16); } } ::GlobalUnlock((HGLOBAL) pDoc->m_hDIB); Invalidate(TRUE); } void CImgDemoView::OnPrcLog() { // TODO: Add your command handler code here int i,j; double c; unsigned char *lpSrc; CImgDemoDoc* pDoc = GetDocument(); ASSERT_VALID(pDoc); if(pDoc->m_hDIB == NULL) return ; LPSTR lpDIB = (LPSTR) ::GlobalLock((HGLOBAL) pDoc->m_hDIB); LPSTR lpDIBBits=::FindDIBBits (lpDIB); int cxDIB = (int) ::DIBWidth(lpDIB); // Size of DIB - x int cyDIB = (int) ::DIBHeight(lpDIB); // Size of DIB - y long lLineBytes = WIDTHBYTES(cxDIB * 8); // 计算图像每行的字节数 // 每行 for(i = 0; i < cyDIB; i++) { // 每列 for(j = 0; j < cxDIB; j++) { // 指向DIB第i行,第j个象素的指针 lpSrc = (unsigned char*)lpDIBBits + lLineBytes * (cyDIB - 1 - i) + j; // 计算新的灰度值 c=255/log(256); *(lpSrc) = BYTE(c*log(*lpSrc+1)); } } ::GlobalUnlock((HGLOBAL) pDoc->m_hDIB); Invalidate(TRUE); } void CImgDemoView::OnPrcExp() { // TODO: Add your command handler code here int i,j; unsigned char *lpSrc; double c,r; CImgDemoDoc* pDoc = GetDocument(); ASSERT_VALID(pDoc); if(pDoc->m_hDIB == NULL) return ; LPSTR lpDIB = (LPSTR) ::GlobalLock((HGLOBAL) pDoc->m_hDIB); LPSTR lpDIBBits=::FindDIBBits (lpDIB); int cxDIB = (int) ::DIBWidth(lpDIB); // Size of DIB - x int cyDIB = (int) ::DIBHeight(lpDIB); // Size of DIB - y long lLineBytes = WIDTHBYTES(cxDIB * 8); // 计算图像每行的字节数 // 每行 r=2; for(i = 0; i < cyDIB; i++) { // 每列 for(j = 0; j < cxDIB; j++) { // 指向DIB第i行,第j个象素的指针 lpSrc = (unsigned char*)lpDIBBits + lLineBytes * (cyDIB - 1 - i) + j; // 计算新的灰度值 c=255/pow(255,r); *(lpSrc) = BYTE(c*pow(*lpSrc,r)); } } ::GlobalUnlock((HGLOBAL) pDoc->m_hDIB); Invalidate(TRUE); } void CImgDemoView::OnPrc2562bin() { // TODO: Add your command handler code here int i,j; unsigned char *lpSrc; CImgDemoDoc* pDoc = GetDocument(); ASSERT_VALID(pDoc); if(pDoc->m_hDIB == NULL) return ; LPSTR lpDIB = (LPSTR) ::GlobalLock((HGLOBAL) pDoc->m_hDIB); LPSTR lpDIBBits=::FindDIBBits (lpDIB); int cxDIB = (int) ::DIBWidth(lpDIB); // Size of DIB - x int cyDIB = (int) ::DIBHeight(lpDIB); // Size of DIB - y long lLineBytes = WIDTHBYTES(cxDIB * 8); // 计算图像每行的字节数 const float c1=150,c2=2.5; // 每行 for(i = 0; i < cyDIB; i++) { // 每列 for(j = 0; j < cxDIB; j++) { // 指向DIB第i行,第j个象素的指针 lpSrc = (unsigned char*)lpDIBBits + lLineBytes * (cyDIB - 1 - i) + j; // 计算新的灰度值 if(*lpSrc<122) *lpSrc=BYTE(0); else *lpSrc = BYTE(255); } } ::GlobalUnlock((HGLOBAL) pDoc->m_hDIB); Invalidate(TRUE); } void CImgDemoView::OnPRC256to8() { // TODO: Add your command handler code here int i,j; unsigned char *lpSrc; CImgDemoDoc* pDoc = GetDocument(); ASSERT_VALID(pDoc); if(pDoc->m_hDIB == NULL) return ; LPSTR lpDIB = (LPSTR) ::GlobalLock((HGLOBAL) pDoc->m_hDIB); LPSTR lpDIBBits=::FindDIBBits (lpDIB); int cxDIB = (int) ::DIBWidth(lpDIB); // Size of DIB - x int cyDIB = (int) ::DIBHeight(lpDIB); // Size of DIB - y long lLineBytes = WIDTHBYTES(cxDIB * 8); // 计算图像每行的字节数 const float c1=150,c2=2.5; // 每行 for(i = 0; i < cyDIB; i++) { // 每列 for(j = 0; j < cxDIB; j++) { // 指向DIB第i行,第j个象素的指针 lpSrc = (unsigned char*)lpDIBBits + lLineBytes * (cyDIB - 1 - i) + j; // 计算新的灰度值 if(*lpSrc<32) *lpSrc=16; else if(*lpSrc<64) *lpSrc=48; else if(*lpSrc<96) *lpSrc=80; else if(*lpSrc<128) *lpSrc=112; else if(*lpSrc<160) *lpSrc=144; else if(*lpSrc<192) *lpSrc=176; else if(*lpSrc<224) *lpSrc=208; else *lpSrc=240; } } ::GlobalUnlock((HGLOBAL) pDoc->m_hDIB); Invalidate(TRUE); } void CImgDemoView::OnGrayExtention() { // TODO: Add your command handler code here int i,j; int r1=60,r2=200; double k=1.5; unsigned char *lpSrc; CImgDemoDoc* pDoc = GetDocument(); ASSERT_VALID(pDoc); if(pDoc->m_hDIB == NULL) return ; LPSTR lpDIB = (LPSTR) ::GlobalLock((HGLOBAL) pDoc->m_hDIB); LPSTR lpDIBBits=::FindDIBBits (lpDIB); int cxDIB = (int) ::DIBWidth(lpDIB); // Size of DIB - x int cyDIB = (int) ::DIBHeight(lpDIB); // Size of DIB - y long lLineBytes = WIDTHBYTES(cxDIB * 8); // 计算图像每行的字节数 // 每行 for(i = 0; i < cyDIB; i++) { // 每列 for(j = 0; j < cxDIB; j++) { // 指向DIB第i行,第j个象素的指针 lpSrc = (unsigned char*)lpDIBBits + lLineBytes * (cyDIB - 1 - i) + j; // 计算新的灰度值 if(*lpSrc m_hDIB); Invalidate(TRUE); } void CImgDemoView::OnP0() { int i,j; unsigned char *lpSrc; CImgDemoDoc* pDoc = GetDocument(); ASSERT_VALID(pDoc); if(pDoc->m_hDIB == NULL) return ; LPSTR lpDIB = (LPSTR) ::GlobalLock((HGLOBAL) pDoc->m_hDIB); int cxDIB = (int) ::DIBWidth(lpDIB); // Size of DIB - x int cyDIB = (int) ::DIBHeight(lpDIB); // Size of DIB - y LPSTR lpDIBBits=::FindDIBBits (lpDIB); // 计算图像每行的字节数 long lLineBytes = WIDTHBYTES(cxDIB * 8); // 每行 for(i = 0; i < cyDIB; i++) { // 每列 for(j = 0; j < cxDIB; j++) { // 指向DIB第i行,第j个象素的指针 lpSrc = (unsigned char*)lpDIBBits + lLineBytes * (cyDIB - 1 - i) + j; *lpSrc=*lpSrc&0xF2; } } ::GlobalUnlock((HGLOBAL) pDoc->m_hDIB); Invalidate(TRUE); } void CImgDemoView::OnP7() { int i,j; unsigned char *lpSrc; CImgDemoDoc* pDoc = GetDocument(); ASSERT_VALID(pDoc); if(pDoc->m_hDIB == NULL) return ; LPSTR lpDIB = (LPSTR) ::GlobalLock((HGLOBAL) pDoc->m_hDIB); int cxDIB = (int) ::DIBWidth(lpDIB); // Size of DIB - x int cyDIB = (int) ::DIBHeight(lpDIB); // Size of DIB - y LPSTR lpDIBBits=::FindDIBBits (lpDIB); // 计算图像每行的字节数 long lLineBytes = WIDTHBYTES(cxDIB * 8); // 每行 for(i = 0; i < cyDIB; i++) { // 每列 for(j = 0; j < cxDIB; j++) { // 指向DIB第i行,第j个象素的指针 lpSrc = (unsigned char*)lpDIBBits + lLineBytes * (cyDIB - 1 - i) + j; *lpSrc=*lpSrc&0x80; } } ::GlobalUnlock((HGLOBAL) pDoc->m_hDIB); Invalidate(TRUE); } void CImgDemoView::OnP3() { int i,j; unsigned char *lpSrc; CImgDemoDoc* pDoc = GetDocument(); ASSERT_VALID(pDoc); if(pDoc->m_hDIB == NULL) return ; LPSTR lpDIB = (LPSTR) ::GlobalLock((HGLOBAL) pDoc->m_hDIB); int cxDIB = (int) ::DIBWidth(lpDIB); // Size of DIB - x int cyDIB = (int) ::DIBHeight(lpDIB); // Size of DIB - y LPSTR lpDIBBits=::FindDIBBits (lpDIB); // 计算图像每行的字节数 long lLineBytes = WIDTHBYTES(cxDIB * 8); // 每行 for(i = 0; i < cyDIB; i++) { // 每列 for(j = 0; j < cxDIB; j++) { // 指向DIB第i行,第j个象素的指针 lpSrc = (unsigned char*)lpDIBBits + lLineBytes * (cyDIB - 1 - i) + j; *lpSrc=*lpSrc&0xE0; } } ::GlobalUnlock((HGLOBAL) pDoc->m_hDIB); Invalidate(TRUE); } void CImgDemoView::OnWT_DAU_fenjie() { int i,j; unsigned char *lpSrc; CImgDemoDoc* pDoc = GetDocument(); ASSERT_VALID(pDoc); if(pDoc->m_hDIB == NULL) return ; LPSTR lpDIB = (LPSTR) ::GlobalLock((HGLOBAL) pDoc->m_hDIB); LPSTR lpDIBBits=::FindDIBBits (lpDIB); int cxDIB = (int) ::DIBWidth(lpDIB); // Size of DIB - x int cyDIB = (int) ::DIBHeight(lpDIB); // Size of DIB - y long lLineBytes = WIDTHBYTES(cxDIB * 8); // 计算图像每行的字节数 double* imagematrix=new double[cyDIB*cxDIB]; // 每行 for(i = 0; i < cyDIB; i++) { // 每列 for(j = 0; j < cxDIB; j++) { // 指向DIB第i行,第j个象素的指针 lpSrc = (unsigned char*)lpDIBBits + lLineBytes * (cyDIB - 1 - i) + j; imagematrix[i+cxDIB*j]=*lpSrc; } } //do wavelet transform wavelet_2d(imagematrix,cyDIB,cxDIB,1,4);//4 hap daubechies,level=1 //do scale double min=1000000; double max=-100000; for(i = 0; i < cyDIB; i++) { // 每列 for(j = 0; j < cxDIB; j++) { if(imagematrix[i+cxDIB*j] max) max=imagematrix[i+cxDIB*j]; } } for(i = 0; i < cyDIB; i++) { // 每列 for(j = 0; j < cxDIB; j++) { // 指向DIB第i行,第j个象素的指针 lpSrc = (unsigned char*)lpDIBBits + lLineBytes * (cyDIB - 1 - i) + j; *lpSrc=int(255*imagematrix[i+cxDIB*j]/(max-min)+min); } } /* min=100000; max=-10000; for(i = 0; i < cyDIB; i++) { // 每列 for(j = 0; j < cxDIB; j++) { lpSrc = (unsigned char*)lpDIBBits + lLineBytes * (cyDIB - 1 - i) + j; if(*lpSrc max) max=*lpSrc; } } */ for(i = 0; i < cyDIB; i++) { // 每列 for(j = 0; j < cxDIB; j++) { // 指向DIB第i行,第j个象素的指针 lpSrc = (unsigned char*)lpDIBBits + lLineBytes * (cyDIB - 1 - i) + j; *lpSrc=int(imagematrix[i+cxDIB*j]); } } ::GlobalUnlock((HGLOBAL) pDoc->m_hDIB); Invalidate(TRUE); } void CImgDemoView::OnWTDAUfenjie2() { int i,j; unsigned char *lpSrc; CImgDemoDoc* pDoc = GetDocument(); ASSERT_VALID(pDoc); if(pDoc->m_hDIB == NULL) return ; LPSTR lpDIB = (LPSTR) ::GlobalLock((HGLOBAL) pDoc->m_hDIB); LPSTR lpDIBBits=::FindDIBBits (lpDIB); int cxDIB = (int) ::DIBWidth(lpDIB); // Size of DIB - x int cyDIB = (int) ::DIBHeight(lpDIB); // Size of DIB - y long lLineBytes = WIDTHBYTES(cxDIB * 8); // 计算图像每行的字节数 double* imagematrix=new double[cyDIB*cxDIB]; // 每行 for(i = 0; i < cyDIB; i++) { // 每列 for(j = 0; j < cxDIB; j++) { // 指向DIB第i行,第j个象素的指针 lpSrc = (unsigned char*)lpDIBBits + lLineBytes * (cyDIB - 1 - i) + j; imagematrix[i+cxDIB*j]=*lpSrc; } } //do wavelet transform wavelet_2d(imagematrix,cyDIB,cxDIB,2,4);//4 hap daubechies,level=2 //do scale double min=1000000; double max=-100000; for(i = 0; i < cyDIB; i++) { // 每列 for(j = 0; j < cxDIB; j++) { if(imagematrix[i+cxDIB*j] max) max=imagematrix[i+cxDIB*j]; } } for(i = 0; i < cyDIB; i++) { // 每列 for(j = 0; j < cxDIB; j++) { // 指向DIB第i行,第j个象素的指针 lpSrc = (unsigned char*)lpDIBBits + lLineBytes * (cyDIB - 1 - i) + j; *lpSrc=int(255*imagematrix[i+cxDIB*j]/(max-min)+min); } } for(i = 0; i < cyDIB; i++) { // 每列 for(j = 0; j < cxDIB; j++) { // 指向DIB第i行,第j个象素的指针 lpSrc = (unsigned char*)lpDIBBits + lLineBytes * (cyDIB - 1 - i) + j; *lpSrc=int(imagematrix[i+cxDIB*j]); } } ::GlobalUnlock((HGLOBAL) pDoc->m_hDIB); Invalidate(TRUE); } void CImgDemoView::OnWTDAUfenjie3() { int i,j; unsigned char *lpSrc; CImgDemoDoc* pDoc = GetDocument(); ASSERT_VALID(pDoc); if(pDoc->m_hDIB == NULL) return ; LPSTR lpDIB = (LPSTR) ::GlobalLock((HGLOBAL) pDoc->m_hDIB); LPSTR lpDIBBits=::FindDIBBits (lpDIB); int cxDIB = (int) ::DIBWidth(lpDIB); // Size of DIB - x int cyDIB = (int) ::DIBHeight(lpDIB); // Size of DIB - y long lLineBytes = WIDTHBYTES(cxDIB * 8); // 计算图像每行的字节数 double* imagematrix=new double[cyDIB*cxDIB]; // 每行 for(i = 0; i < cyDIB; i++) { // 每列 for(j = 0; j < cxDIB; j++) { // 指向DIB第i行,第j个象素的指针 lpSrc = (unsigned char*)lpDIBBits + lLineBytes * (cyDIB - 1 - i) + j; imagematrix[i+cxDIB*j]=*lpSrc; } } //do wavelet transform wavelet_2d(imagematrix,cyDIB,cxDIB,2,1);//haar //do scale double min=1000000; double max=-100000; for(i = 0; i < cyDIB; i++) { // 每列 for(j = 0; j < cxDIB; j++) { if(imagematrix[i+cxDIB*j] max) max=imagematrix[i+cxDIB*j]; } } for(i = 0; i < cyDIB; i++) { // 每列 for(j = 0; j < cxDIB; j++) { // 指向DIB第i行,第j个象素的指针 lpSrc = (unsigned char*)lpDIBBits + lLineBytes * (cyDIB - 1 - i) + j; *lpSrc=int(255*imagematrix[i+cxDIB*j]/(max-min)+min); } } for(i = 0; i < cyDIB; i++) { // 每列 for(j = 0; j < cxDIB; j++) { // 指向DIB第i行,第j个象素的指针 lpSrc = (unsigned char*)lpDIBBits + lLineBytes * (cyDIB - 1 - i) + j; *lpSrc=int(imagematrix[i+cxDIB*j]); } } ::GlobalUnlock((HGLOBAL) pDoc->m_hDIB); Invalidate(TRUE); } void CImgDemoView::OnWTDAUfenjie4() { int i,j; unsigned char *lpSrc; CImgDemoDoc* pDoc = GetDocument(); ASSERT_VALID(pDoc); if(pDoc->m_hDIB == NULL) return ; LPSTR lpDIB = (LPSTR) ::GlobalLock((HGLOBAL) pDoc->m_hDIB); LPSTR lpDIBBits=::FindDIBBits (lpDIB); int cxDIB = (int) ::DIBWidth(lpDIB); // Size of DIB - x int cyDIB = (int) ::DIBHeight(lpDIB); // Size of DIB - y long lLineBytes = WIDTHBYTES(cxDIB * 8); // 计算图像每行的字节数 double* imagematrix=new double[cyDIB*cxDIB]; // 每行 for(i = 0; i < cyDIB; i++) { // 每列 for(j = 0; j < cxDIB; j++) { // 指向DIB第i行,第j个象素的指针 lpSrc = (unsigned char*)lpDIBBits + lLineBytes * (cyDIB - 1 - i) + j; imagematrix[i+cxDIB*j]=*lpSrc; } } //do wavelet transform wavelet_2d(imagematrix,cyDIB,cxDIB,2,0);//Spline //do scale double min=1000000; double max=-100000; for(i = 0; i < cyDIB; i++) { // 每列 for(j = 0; j < cxDIB; j++) { if(imagematrix[i+cxDIB*j] max) max=imagematrix[i+cxDIB*j]; } } for(i = 0; i < cyDIB; i++) { // 每列 for(j = 0; j < cxDIB; j++) { // 指向DIB第i行,第j个象素的指针 lpSrc = (unsigned char*)lpDIBBits + lLineBytes * (cyDIB - 1 - i) + j; *lpSrc=int(255*imagematrix[i+cxDIB*j]/(max-min)+min); } } for(i = 0; i < cyDIB; i++) { // 每列 for(j = 0; j < cxDIB; j++) { // 指向DIB第i行,第j个象素的指针 lpSrc = (unsigned char*)lpDIBBits + lLineBytes * (cyDIB - 1 - i) + j; *lpSrc=int(imagematrix[i+cxDIB*j]); } } ::GlobalUnlock((HGLOBAL) pDoc->m_hDIB); Invalidate(TRUE); } void CImgDemoView::OnWTDAUfenjie5() { int i,j; unsigned char *lpSrc; CImgDemoDoc* pDoc = GetDocument(); ASSERT_VALID(pDoc); if(pDoc->m_hDIB == NULL) return ; LPSTR lpDIB = (LPSTR) ::GlobalLock((HGLOBAL) pDoc->m_hDIB); LPSTR lpDIBBits=::FindDIBBits (lpDIB); int cxDIB = (int) ::DIBWidth(lpDIB); // Size of DIB - x int cyDIB = (int) ::DIBHeight(lpDIB); // Size of DIB - y long lLineBytes = WIDTHBYTES(cxDIB * 8); // 计算图像每行的字节数 double* imagematrix=new double[cyDIB*cxDIB]; // 每行 for(i = 0; i < cyDIB; i++) { // 每列 for(j = 0; j < cxDIB; j++) { // 指向DIB第i行,第j个象素的指针 lpSrc = (unsigned char*)lpDIBBits + lLineBytes * (cyDIB - 1 - i) + j; imagematrix[i+cxDIB*j]=*lpSrc; } } //do wavelet transform wavelet_2d(imagematrix,cyDIB,cxDIB,2,4);//8 hap daubechies,level=2 //do scale double min=1000000; double max=-100000; for(i = 0; i < cyDIB; i++) { // 每列 for(j = 0; j < cxDIB; j++) { if(imagematrix[i+cxDIB*j] max) max=imagematrix[i+cxDIB*j]; } } for(i = 0; i < cyDIB; i++) { // 每列 for(j = 0; j < cxDIB; j++) { // 指向DIB第i行,第j个象素的指针 lpSrc = (unsigned char*)lpDIBBits + lLineBytes * (cyDIB - 1 - i) + j; *lpSrc=int(255*imagematrix[i+cxDIB*j]/(max-min)+min); } } for(i = 0; i < cyDIB; i++) { // 每列 for(j = 0; j < cxDIB; j++) { // 指向DIB第i行,第j个象素的指针 lpSrc = (unsigned char*)lpDIBBits + lLineBytes * (cyDIB - 1 - i) + j; *lpSrc=int(imagematrix[i+cxDIB*j]); } } ::GlobalUnlock((HGLOBAL) pDoc->m_hDIB); Invalidate(TRUE); }