Wavelet2DDlg.cpp
上传用户:whhgrj
上传日期:2013-03-18
资源大小:169k
文件大小:19k
- // Wavelet2DDlg.cpp : implementation file
- //
- #include "stdafx.h"
- #include "Wavelet2D.h"
- #include "Wavelet2DDlg.h"
- #include "ColorTable.h"
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
- /////////////////////////////////////////////////////////////////////////////
- // CAboutDlg dialog used for App About
- class CAboutDlg : public CDialog
- {
- public:
- CAboutDlg();
- // Dialog Data
- //{{AFX_DATA(CAboutDlg)
- enum { IDD = IDD_ABOUTBOX };
- //}}AFX_DATA
- // ClassWizard generated virtual function overrides
- //{{AFX_VIRTUAL(CAboutDlg)
- protected:
- virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
- //}}AFX_VIRTUAL
- // Implementation
- protected:
- //{{AFX_MSG(CAboutDlg)
- //}}AFX_MSG
- DECLARE_MESSAGE_MAP()
- };
- CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
- {
- //{{AFX_DATA_INIT(CAboutDlg)
- //}}AFX_DATA_INIT
- }
- void CAboutDlg::DoDataExchange(CDataExchange* pDX)
- {
- CDialog::DoDataExchange(pDX);
- //{{AFX_DATA_MAP(CAboutDlg)
- //}}AFX_DATA_MAP
- }
- BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
- //{{AFX_MSG_MAP(CAboutDlg)
- // No message handlers
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
- /////////////////////////////////////////////////////////////////////////////
- // CWavelet2DDlg dialog
- CWavelet2DDlg::CWavelet2DDlg(CWnd* pParent /*=NULL*/)
- : CDialog(CWavelet2DDlg::IDD, pParent)
- {
- //{{AFX_DATA_INIT(CWavelet2DDlg)
- // NOTE: the ClassWizard will add member initialization here
- m_bWavelet = FALSE;
- m_strBmpFile=_T("Sample.bmp");
- m_nDecomposeStage = 1;
- m_nFilterLen = 6;
- //}}AFX_DATA_INIT
- // Note that LoadIcon does not require a subsequent DestroyIcon in Win32
- m_strFilterFile[0]="h1.dat";
- m_strFilterFile[1]="h2.dat";
- m_strFilterFile[2]="h3.dat";
- m_strFilterFile[3]="h4.dat";
- m_strFilterFile[4]="h5.dat";
- m_strFilterFile[5]="h6.dat";
- m_strFilterFile[6]="h7.dat";
- m_strFilterFile[7]="h8.dat";
- m_strFilterFile[8]="h9.dat";
- m_strFilterFile[9]="h10.dat";
- m_pBmpInfo = (BITMAPINFO *)malloc(2048);
- if(m_pBmpInfo)
- {
- m_pBmpInfo->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
- m_pBmpInfo->bmiHeader.biWidth = m_nImageWidth;
- m_pBmpInfo->bmiHeader.biHeight = m_nImageHeight;
- m_pBmpInfo->bmiHeader.biPlanes = 1;
- m_pBmpInfo->bmiHeader.biBitCount = 8;
- m_pBmpInfo->bmiHeader.biCompression = BI_RGB;
- m_pBmpInfo->bmiHeader.biSizeImage = 0;
- m_pBmpInfo->bmiHeader.biXPelsPerMeter = 0;
- m_pBmpInfo->bmiHeader.biYPelsPerMeter = 0;
- m_pBmpInfo->bmiHeader.biClrUsed = 0;
- m_pBmpInfo->bmiHeader.biClrImportant = 0;
- for( int k = 0; k < 256; ++k){
- m_pBmpInfo->bmiColors[k].rgbBlue = (BYTE)k;
- m_pBmpInfo->bmiColors[k].rgbGreen = (BYTE)k;
- m_pBmpInfo->bmiColors[k].rgbRed = (BYTE)k;
- m_pBmpInfo->bmiColors[k].rgbReserved = 0;
- }
- }
- m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
- }
- void CWavelet2DDlg::DoDataExchange(CDataExchange* pDX)
- {
- CDialog::DoDataExchange(pDX);
- //{{AFX_DATA_MAP(CWavelet2DDlg)
- DDX_Control(pDX, IDC_EDIT_BMPFILE, m_editBmpFile);
- DDX_Control(pDX, IDC_COMBO_FILTERLEN, m_combFilterLen);
- DDX_Control(pDX, IDC_COMBO_DECOMPOSESTAGE, m_combDecomposeStage);
- //}}AFX_DATA_MAP
- }
- BEGIN_MESSAGE_MAP(CWavelet2DDlg, CDialog)
- //{{AFX_MSG_MAP(CWavelet2DDlg)
- ON_WM_SYSCOMMAND()
- ON_WM_PAINT()
- ON_WM_QUERYDRAGICON()
- ON_BN_CLICKED(IDC_BUTTON_WAVELET2D, OnBtnWavelet2D)
- ON_BN_CLICKED(IDC_BUTTON_BMPFILE, OnBtnBmpFile)
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
- /////////////////////////////////////////////////////////////////////////////
- // CWavelet2DDlg message handlers
- BOOL CWavelet2DDlg::OnInitDialog()
- {
- CDialog::OnInitDialog();
- // Add "About..." menu item to system menu.
- // IDM_ABOUTBOX must be in the system command range.
- ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
- ASSERT(IDM_ABOUTBOX < 0xF000);
- CMenu* pSysMenu = GetSystemMenu(FALSE);
- if (pSysMenu != NULL)
- {
- CString strAboutMenu;
- strAboutMenu.LoadString(IDS_ABOUTBOX);
- if (!strAboutMenu.IsEmpty())
- {
- pSysMenu->AppendMenu(MF_SEPARATOR);
- pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
- }
- }
- // Set the icon for this dialog. The framework does this automatically
- // when the application's main window is not a dialog
- SetIcon(m_hIcon, TRUE); // Set big icon
- SetIcon(m_hIcon, FALSE); // Set small icon
-
- // 初始化控件
- m_editBmpFile.SetWindowText(m_strBmpFile);
- CString strComb;
- int k=0;
- for(k=0;k<6;k++)
- {
- strComb.Format("%d",k+1);
- m_combDecomposeStage.InsertString(k,strComb);
- m_combDecomposeStage.SetItemData(k,k+1);
- m_combDecomposeStage.SetCurSel(0);
- }
- for(k=0;k<10;k++)
- {
- strComb.Format("%d",2*(k+1));
- m_combFilterLen.InsertString(k,strComb);
- m_combFilterLen.SetItemData(k,2*(k+1));
- m_combFilterLen.SetCurSel(2);
- }
-
- return TRUE; // return TRUE unless you set the focus to a control
- }
- void CWavelet2DDlg::OnSysCommand(UINT nID, LPARAM lParam)
- {
- if ((nID & 0xFFF0) == IDM_ABOUTBOX)
- {
- CAboutDlg dlgAbout;
- dlgAbout.DoModal();
- }
- else
- {
- CDialog::OnSysCommand(nID, lParam);
- }
- }
- // If you add a minimize button to your dialog, you will need the code below
- // to draw the icon. For MFC applications using the document/view model,
- // this is automatically done for you by the framework.
- void CWavelet2DDlg::OnPaint()
- {
- if (IsIconic())
- {
- CPaintDC dc(this); // device context for painting
- SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
- // Center icon in client rectangle
- int cxIcon = GetSystemMetrics(SM_CXICON);
- int cyIcon = GetSystemMetrics(SM_CYICON);
- CRect rect;
- GetClientRect(&rect);
- int x = (rect.Width() - cxIcon + 1) / 2;
- int y = (rect.Height() - cyIcon + 1) / 2;
- // Draw the icon
- dc.DrawIcon(x, y, m_hIcon);
- }
- else
- {
- if(m_bWavelet)
- OnBtnWavelet2D();
- CDialog::OnPaint();
- }
- }
- // The system calls this to obtain the cursor to display while the user drags
- // the minimized window.
- HCURSOR CWavelet2DDlg::OnQueryDragIcon()
- {
- return (HCURSOR) m_hIcon;
- }
- // 选择原始数据图像文件
- void CWavelet2DDlg::OnBtnBmpFile()
- {
- CFileDialog BmpFileDlg(TRUE,"bmp","*.bmp");
- if(BmpFileDlg.DoModal()==IDOK)
- {
- m_bWavelet=FALSE;
- m_strBmpFile=BmpFileDlg.GetPathName();
- m_editBmpFile.SetWindowText(m_strBmpFile);
- }
- }
- // “二维小波变换”按钮消息处理函数
- // 功能:打开文件,分配内存,进行变换,绘制结果
- void CWavelet2DDlg::OnBtnWavelet2D()
- {
- CFile BmpFile;
- CFileException fe;
- // 打开原始图像数据
- if(m_strBmpFile.IsEmpty())
- {
- AfxMessageBox (_T("请选择一个位图(*.bmp)文件!"),MB_ICONINFORMATION|MB_OK,NULL);
- return;
- }
- if(!BmpFile.Open(m_strBmpFile,CFile::modeRead,&fe))
- {
- AfxMessageBox (_T("打开文件失败!"),MB_ICONINFORMATION|MB_OK,NULL);
- return;
- }
- // 读取原始数据图像文件
- TRY
- {
- DIB = ::ReadDIBFile(BmpFile);
- }
- CATCH (CFileException, eLoad)
- {
- BmpFile.Abort(); // 读取失败
- AfxMessageBox (_T("读取数据失败!"),MB_ICONINFORMATION|MB_OK,NULL);
- DIB = NULL; // 设置DIB为空
- return ;
- }
- END_CATCH
-
- // 锁定DIB
- lpDIB = (LPSTR)::GlobalLock((HGLOBAL)GetHDIB());
- // 得到图像宽度和高度
- m_nImageWidth=::DIBWidth(lpDIB);
- m_nImageHeight=::DIBHeight(lpDIB);
- // 打开待处理图像
- // 判断是否是8-bpp位图
- if (::DIBNumColors(lpDIB) > 256||m_nImageWidth>400||m_nImageHeight>400)
- {
- // 提示用户
- AfxMessageBox(_T("不是256色位图或者图像过大!") , MB_ICONINFORMATION | MB_OK,NULL);
- // 解除锁定
- ::GlobalUnlock((HGLOBAL) GetHDIB());
- return;
- }
- // 更改光标形状
- BeginWaitCursor();
- // 找到DIB图像象素起始位置
- lpDIBBits = ::FindDIBBits(lpDIB);
- // 得到小波变换所需的层次、滤波器长度等参数
- GetParam();
- // 获取滤波器参数
- if(!GetHn())
- return;
- // 绘制原始图像
- DrawOriginalBmp();
- // 给image数组分配内存
- if(!GetMemory())
- return;
- // 将图像数据读入image数组
- for(int i=0;i<m_nImageHeight;i++)
- for(int j=0;j<m_nImageWidth;j++)
- image[i][j]=(unsigned char)(*((unsigned char *)lpDIBBits+m_nImageWidth*i+j));
-
- // 对图像进行二维小波变换
- Wavelet2D();
- // 绘制二维小波变换后的图像
- DrawWavelet2D();
- // 释放资源
- ReleaseMemory();
- // 解除锁定
- ::GlobalUnlock((HGLOBAL) GetHDIB());
- // 恢复光标
- EndWaitCursor();
- // 设置已进行过小波变换标志
- m_bWavelet=TRUE;
- }
- // 确定退出函数
- void CWavelet2DDlg::OnOK()
- {
- if(m_pBmpInfo)
- free(m_pBmpInfo);
- CDialog::OnOK();
- }
- // 分配小波变换所需内存
- BOOL CWavelet2DDlg::GetMemory()
- {
- BOOL flag=TRUE;
-
- image=new double *[m_nImageHeight];
- for(int n=0;n<m_nImageHeight;n++)
- {
- *(image+n)=new double[sizeof(double)*m_nImageWidth];
- if(*(image+n)==NULL)
- flag=FALSE;
- }
- tempRow=new double[sizeof(double)*m_nImageWidth];
- tempCol=new double[sizeof(double)*m_nImageHeight];
- if(tempRow==NULL||tempCol==NULL)
- flag=FALSE;
- return flag;
- }
- // 释放资源
- void CWavelet2DDlg::ReleaseMemory()
- {
- for(int k=0;k<m_nImageHeight;k++)
- delete *(image+k);
- delete []image;
- delete tempCol;
- delete tempRow;
- image=NULL;
- tempCol=NULL;
- tempRow=NULL;
- if(DIB)
- {
- ::GlobalFree((HGLOBAL) DIB);
- DIB=NULL;
- }
- }
- // 得到滤波器参数
- BOOL CWavelet2DDlg::GetHn()
- {
- int i;
- double temp1;
- FILE *fp1;
- if((fp1=fopen(m_strFilterFile[m_nFilterLen/2-1],"rb+"))==NULL)
- {
- AfxMessageBox("打开Hn数据文件失败!",MB_OK|MB_ICONINFORMATION);
- return FALSE;
- }
- for(i=0;i<30;i++)
- h[i]=0;
- for(i=0;i<m_nFilterLen;i++)
- {
- fread(&temp1,sizeof(double),1,fp1);
- h[i]=temp1;
- }
- fclose(fp1);
- return TRUE;
- }
- //返回H算子周期化后得值
- double CWavelet2DDlg::HH(int i,int m)
- {
- return h[i+m];
- }
- //返回G算子周期化后的值
- double CWavelet2DDlg::GG(int i, int m)
- {
- char flag;
- if(i%2)
- flag=-1;
- else
- flag=1;
- return HH(-1*i+1,m)*flag;
- }
- //H算子周期化过程
- BOOL CWavelet2DDlg::HHH(int level,int size)
- {
- int len,m,i;
- double temp;
- int sign;
- len=size>>level;
- m=m_nFilterLen/2;
- if((ph=new double[sizeof(double)*len])==NULL)
- {
- AfxMessageBox("H算子内存分配失败!",MB_OK|MB_ICONINFORMATION);
- return FALSE;
- }
- for(sign=0;sign<len;sign++)
- {
- temp=0;
- for(i=(-1*m+1);i<=m;i++)
- {
- if(((sign-i)%len)==0)
- temp+=HH(i-1,m);
- }
- ph[sign]=temp;
- }
- return TRUE;
- }
- // G算子周期化过程
- BOOL CWavelet2DDlg::GGG(int level,int size)
- {
- int len,m,i;
- double temp;
- int sign;
- len=size>>level;
- m=m_nFilterLen/2;
- if((pg=new double[sizeof(double)*len])==NULL)
- {
- AfxMessageBox("G算子内存分配失败!",MB_OK|MB_ICONINFORMATION);
- return FALSE;
- }
- for(sign=0;sign<len;sign++)
- {
- temp=0;
- for(i=(-1*m+3);i<=m+2;i++)
- {
- if(((sign-i)%len)==0)
- temp+=GG(i-1,m);
- }
- pg[sign]=temp;
- }
- return TRUE;
- }
- // H算子作用于行数据
- void CWavelet2DDlg::HOperatorOnRow(int filterlen, int start, int len,int row)
- {
- int i,i2,m,k,len1;
- double temp1;
- m=m_nFilterLen/2;
- len1=len>>1;
- for(i=0;i<len1;i++)
- {
- i2=2*i;
- tempRow[i+start]=0;
- if(len>filterlen)
- {
- for(k=i2-len;k<=i2-len+m;k++)
- {
- if((k>=0)&&(k<len))
- if((temp1=ph[(k-i2+len)%len])!=0)
- tempRow[i+start]+=temp1*image[row][k+start];
- }
- for(k=i2-m+1;k<=i2+m;k++)
- {
- if((k>=0)&&(k<len))
- if((temp1=ph[(k-i2+len)%len])!=0)
- tempRow[i+start]+=temp1*image[row][k+start];
- }
- for(k=i2+len-m+1;k<=i2+len;k++)
- {
- if((k>=0)&&(k<len))
- if((temp1=ph[(k-i2+len)%len])!=0)
- tempRow[i+start]+=temp1*image[row][k+start];
- }
- }
- else
- {
- for(k=0;k<len;k++)
- {
- if((temp1=ph[(k-i2+len)%len])!=0)
- tempRow[i+start]+=temp1*image[row][k+start];
- }
- }
- }
- }
- // H算子作用于列数据
- void CWavelet2DDlg::HOperatorOnCol(int filterlen, int start, int len,int col)
- {
- int i,i2,m,k,len1;
- double temp1;
- m=m_nFilterLen/2;
- len1=len>>1;
- for(i=0;i<len1;i++)
- {
- i2=2*i;
- tempCol[i+start]=0;
- if(len>filterlen)
- {
- for(k=i2-len;k<=i2-len+m;k++)
- {
- if((k>=0)&&(k<len))
- if((temp1=ph[(k-i2+len)%len])!=0)
- tempCol[i+start]+=temp1*image[k+start][col];
- }
- for(k=i2-m+1;k<=i2+m;k++)
- {
- if((k>=0)&&(k<len))
- if((temp1=ph[(k-i2+len)%len])!=0)
- tempCol[i+start]+=temp1*image[k+start][col];
- }
- for(k=i2+len-m+1;k<=i2+len;k++)
- {
- if((k>=0)&&(k<len))
- if((temp1=ph[(k-i2+len)%len])!=0)
- tempCol[i+start]+=temp1*image[k+start][col];
- }
- }
- else
- {
- for(k=0;k<len;k++)
- {
- if((temp1=ph[(k-i2+len)%len])!=0)
- tempCol[i+start]+=temp1*image[k+start][col];
- }
- }
- }
- }
- // G算子作用于行数据
- void CWavelet2DDlg::GOperatorOnRow(int filterlen, int start, int len,int row)
- {
- int i,i2,m,k,len1;
- double temp1;
- m=m_nFilterLen/2;
- len1=len>>1;
- for(i=0;i<len1;i++)
- {
- i2=2*i;
- tempRow[i+start+len1]=0;
- if(len>filterlen)
- {
- for(k=i2-len;k<=i2-len+m+2;k++)
- {
- if((k>=0)&&(k<len))
- if((temp1=pg[(k-i2+len)%len])!=0)
- tempRow[i+start+len1]+=temp1*image[row][k+start];
- }
- for(k=i2-m+3;k<=i2+m+2;k++)
- {
- if((k>=0)&&(k<len))
- if((temp1=pg[(k-i2+len)%len])!=0)
- tempRow[i+start+len1]+=temp1*image[row][k+start];
- }
- for(k=i2+len-m+3;k<=i2+len;k++)
- {
- if((k>=0)&&(k<len))
- if((temp1=pg[(k-i2+len)%len])!=0)
- tempRow[i+start+len1]+=temp1*image[row][k+start];
- }
- }
- else
- {
- for(k=0;k<len;k++)
- {
- if((temp1=pg[(k-i2+len)%len])!=0)
- tempRow[i+start]+=temp1*image[row][k+start];
- }
- }
- }
- }
- // G算子作用于列数据
- void CWavelet2DDlg::GOperatorOnCol(int filterlen, int start, int len,int col)
- {
- int i,i2,m,k,len1;
- double temp1;
- m=m_nFilterLen/2;
- len1=len>>1;
- for(i=0;i<len1;i++)
- {
- i2=2*i;
- tempCol[i+start+len1]=0;
- if(len>filterlen)
- {
- for(k=i2-len;k<=i2-len+m+2;k++)
- {
- if((k>=0)&&(k<len))
- if((temp1=pg[(k-i2+len)%len])!=0)
- tempCol[i+start+len1]+=temp1*image[k+start][col];
- }
- for(k=i2-m+3;k<=i2+m+2;k++)
- {
- if((k>=0)&&(k<len))
- if((temp1=pg[(k-i2+len)%len])!=0)
- tempCol[i+start+len1]+=temp1*image[k+start][col];
- }
- for(k=i2+len-m+3;k<=i2+len;k++)
- {
- if((k>=0)&&(k<len))
- if((temp1=pg[(k-i2+len)%len])!=0)
- tempCol[i+start+len1]+=temp1*image[k+start][col];
- }
- }
- else
- {
- for(k=0;k<len;k++)
- {
- if((temp1=pg[(k-i2+len)%len])!=0)
- tempCol[i+start+len1]+=temp1*image[k+start][col];
- }
- }
- }
- }
- // 进行第stage层行变换
- void CWavelet2DDlg::DecompStageRow(int row, int stage, int numx)
- {
- int i,start,end;
- int filterlen,len;
- filterlen=m_nFilterLen;
- len=m_nImageWidth>>stage;
- start=len*numx;
- end=start+len;
- HOperatorOnRow(filterlen,start,len,row); // H算子作用于行
- GOperatorOnRow(filterlen,start,len,row); // G算子作用于行
- for(i=start;i<end;i++)
- image[row][i]=tempRow[i];
- }
- // 进行第stage层列变换
- void CWavelet2DDlg::DecompStageCol(int col, int stage, int numx)
- {
- int i,start,end;
- int filterlen,len;
- filterlen=m_nFilterLen;
- len=m_nImageHeight>>stage;
- start=len*numx;
- end=start+len;
- HOperatorOnCol(filterlen,start,len,col); // H算子作用于列
- GOperatorOnCol(filterlen,start,len,col); // G算子作用于列
- for(i=start;i<end;i++)
- image[i][col]=tempCol[i];
- }
- // 二维小波变换
- void CWavelet2DDlg::Wavelet2D()
- {
- int row,col,stage;
- // 进行第stage层小波变换
- for(stage=0;stage<m_nDecomposeStage;stage++)
- {
- // 初始化H算子和G算子
- if((!HHH(stage,m_nImageWidth))||(!GGG(stage,m_nImageWidth)))
- break;
- else
- // 逐行变换
- for(row=0;row<(m_nImageHeight>>stage);row++)
- {
- DecompStageRow(row,stage,0);
- }
- if(ph&&pg) // 释放资源
- {
- delete ph;
- delete pg;
- ph=NULL;
- pg=NULL;
- }
- // 初始化H算子和G算子
- if((!HHH(stage,m_nImageHeight))||(!GGG(stage,m_nImageHeight)))
- break;
- else
- // 逐列变换
- for(col=0;col<(m_nImageWidth>>stage);col++)
- {
- DecompStageCol(col,stage,0);
- }
- if(ph&&pg) // 释放资源
- {
- delete ph;
- delete pg;
- ph=NULL;
- pg=NULL;
- }
- }
- }
- // 绘制原始图像
- void CWavelet2DDlg::DrawOriginalBmp()
- {
- // 得到客户区
- CDC* pDC=GetDC();
- CRect RectClient,Workarea;
- GetClientRect(RectClient);
-
- // 锁定DIB
- lpDIB = (LPSTR)::GlobalLock((HGLOBAL) GetHDIB());
- // 在对话框右上部分创建绘制原始图像区域
- Workarea.left=RectClient.left+(RectClient.right-RectClient.left)/5*2;
- Workarea.right=RectClient.right-10;
- Workarea.top=RectClient.top+10;
- Workarea.bottom=RectClient.top+(RectClient.bottom-RectClient.top-10)/2;
- // 设置区域背景色为白色
- pDC->Rectangle(Workarea);
- pDC->SetBkColor(0x00FFFFFF);
- // 绘制原始图像
- m_pBmpInfo->bmiHeader.biWidth = m_nImageWidth;
- m_pBmpInfo->bmiHeader.biHeight = m_nImageHeight;
- ::StretchDIBits(pDC->GetSafeHdc(), Workarea.left+1, Workarea.top+1, Workarea.Width(),Workarea.Height(),//m_nImageWidth, m_nImageHeight,
- 0, 0, m_nImageWidth, m_nImageHeight, (unsigned char *)lpDIBBits,
- (LPBITMAPINFO) m_pBmpInfo, DIB_RGB_COLORS, SRCCOPY);
- // 解除锁定
- ::GlobalUnlock((HGLOBAL)GetHDIB());
- }
- // 绘制二维小波变换后图像
- void CWavelet2DDlg::DrawWavelet2D()
- {
- // 找到图像变换后数据中的最大最小值
- double min=image[0][0],max=0;
- for(int a=0;a<m_nImageHeight;a++)
- for(int b=0;b<m_nImageWidth;b++)
- {
- if(image[a][b]>10000)
- image[a][b]=max;
- if(image[a][b]<-10000)
- image[a][b]=min;
- if(max<image[a][b])
- max=image[a][b];
- if(min>image[a][b])
- min=image[a][b];
- }
- // 将图像变换后数据归一化到256级灰度
- for(int m=0;m<m_nImageHeight;m++)
- for(int n=0;n<m_nImageWidth;n++)
- {
- image[m][n]=(image[m][n]-min)/(max-min)*256.0;
- *((unsigned char *)lpDIBBits+m_nImageWidth*m+n)=(unsigned char )image[m][n];
- }
-
- // 得到客户区
- CDC* pDC=GetDC();
- CRect RectClient,Workarea;
- GetClientRect(RectClient);
- // 锁定DIB
- lpDIB = (LPSTR)::GlobalLock((HGLOBAL) GetHDIB());
- // 在对话框右下部分创建绘制原始图像区域
- Workarea.left=RectClient.left+(RectClient.right-RectClient.left)/5*2;
- Workarea.right=RectClient.right-10;
- Workarea.top=RectClient.top+10+(RectClient.bottom-RectClient.top-10)/2;
- Workarea.bottom=RectClient.bottom-10;
-
- // 设置区域背景色为白色
- pDC->Rectangle(Workarea);
- pDC->SetBkColor(0x00FFFFFF);
- // 绘制原始图像
- m_pBmpInfo->bmiHeader.biWidth = m_nImageWidth;
- m_pBmpInfo->bmiHeader.biHeight = m_nImageHeight;
- ::StretchDIBits(pDC->GetSafeHdc(), Workarea.left+1, Workarea.top+1, Workarea.Width(),Workarea.Height(),//m_nImageWidth, m_nImageHeight,
- 0, 0, m_nImageWidth, m_nImageHeight, (unsigned char *)lpDIBBits,
- (LPBITMAPINFO) m_pBmpInfo, DIB_RGB_COLORS, SRCCOPY);
- // 解除锁定
- ::GlobalUnlock((HGLOBAL)GetHDIB());
- }
- // 得到小波变换所需的层次、滤波器长度等参数
- void CWavelet2DDlg::GetParam()
- {
- // 得到待分解层次信息
- if(m_combDecomposeStage.GetCurSel()==CB_ERR)
- m_nDecomposeStage=1;
- else
- m_nDecomposeStage=m_combDecomposeStage.GetItemData(m_combDecomposeStage.GetCurSel());
-
- // 得到滤波器长度
- if(m_combFilterLen.GetCurSel()==CB_ERR)
- m_nFilterLen=6;
- else
- m_nFilterLen=m_combFilterLen.GetItemData(m_combFilterLen.GetCurSel());
- }