模糊图像恢复处理程序实例
//本程序对真彩色由水平(或垂直)运动造成的模糊图像的恢复处理。
图像尺寸:192X192X24bit
①图像参数初始化:BOOL CAntifilterDlg::OnInitDialog();
②图像数据读取: void CAntifilterDlg::OnOpenButton();
③图像退化处理: void CAntifilterDlg::OnFilterButton();
④图像逆滤波恢复:void CAntifilterDlg::OnRefilterButton();
⑤图像显示: void CAntifilterDlg::OnPaint();//
// antifilterDlg.h : header file//
#if !defined(AFX_ANTIFILTERDLG_H__5BD6C507_3B2B_11D2_8AE6_444553540000__INCLUDED_)
#define AFX_ANTIFILTERDLG_H__5BD6C507_3B2B_11D2_8AE6_444553540000__INCLUDED_
#if _MSC_VER >= 1000
#pragma once
#endif // _MSC_VER >= 1000
/////////////////////////////////////////////////////////////////////////////
// CAntifilterDlg dialog
class CAntifilterDlg : public CDialog
{
// Construction
public:
CAntifilterDlg(CWnd* pParent = NULL);// standard constructor
//////////////////////////
//My Code Start Here!
/////////////////////////
LPSTR m_lpDIBBit1;
LPSTR m_lpDIBBit2;
LPSTR m_lpDIBBit3;
LPSTR m_lpBMPBit;
BYTE * m_BMPBYTE;
BYTE * m_DIBBYTE1;
BYTE * m_DIBBYTE2;
BYTE * m_DIBBYTE3;
LPBITMAPINFOHEADER m_lpDIBHdr;
BYTE RedArray[192][192];
BYTE GreenArray[192][192];
BYTE BlueArray[192][192];
BYTE gRedArray[192][192];
BYTE gGreenArray[192][192];
BYTE gBlueArray[192][192];
BYTE rRedArray[192][192];
BYTE rGreenArray[192][192];
BYTE rBlueArray[192][192];
int a;
int A;
int T;
int Bb;
////////////////////////////////
//My Code End Here!
////////////////////////////////
// Dialog Data
//{{AFX_DATA(CAntifilterDlg)
enum { IDD = IDD_ANTIFILTER_DIALOG };
//}}AFX_DATA
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CAntifilterDlg)
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
//}}AFX_VIRTUAL
// Implementation
protected:
HICON m_hIcon;
// Generated message map functions
//{{AFX_MSG(CAntifilterDlg)
virtual BOOL OnInitDialog();
afx_msg void OnSysCommand(UINT nID, LPARAM lParam);
afx_msg void OnPaint();
afx_msg HCURSOR OnQueryDragIcon();
afx_msg void OnOpenButton();
afx_msg void OnFilterButton();
afx_msg void OnRefilterButton();
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
//{{AFX_INSERT_LOCATION}}
// Microsoft Developer Studio will insert additional declarations immediately before the previous line.
#endif // !defined(AFX_ANTIFILTERDLG_H__5BD6C507_3B2B_11D2_8AE6_444553540000__INCLUDED_)
// antifilterDlg.cpp : implementation file
//
#include "stdafx.h"
#include "antifilter.h"
#include "antifilterDlg.h"
#include "math.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()
/////////////////////////////////////////////////////////////////////////////
// CAntifilterDlg dialog
CAntifilterDlg::CAntifilterDlg(CWnd* pParent /*=NULL*/)
: CDialog(CAntifilterDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CAntifilterDlg)
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CAntifilterDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CAntifilterDlg)
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CAntifilterDlg, CDialog)
//{{AFX_MSG_MAP(CAntifilterDlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(IDC_OPEN_BUTTON, OnOpenButton)
ON_BN_CLICKED(IDC_FILTER_BUTTON, OnFilterButton)
ON_BN_CLICKED(IDC_REFILTER_BUTTON, OnRefilterButton)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CAntifilterDlg message handlers
BOOL CAntifilterDlg::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
// TODO: Add extra initialization here
//////////////////
//My Code Start Here!
//////////////////
/*Function:
Initialize the parametre!
*/
m_lpDIBBit1 = NULL;
m_lpDIBBit2 = NULL;
m_lpDIBHdr = new BITMAPINFOHEADER;
m_lpDIBHdr->biSize = (DWORD)sizeof(BITMAPINFOHEADER);
m_lpDIBHdr->biWidth = 192L;
m_lpDIBHdr->biHeight = 192L;
m_lpDIBHdr->biPlanes = 1;
m_lpDIBHdr->biBitCount = 24;
m_lpDIBHdr->biCompression = BI_RGB ;
m_lpDIBHdr->biSizeImage = 0L;
m_lpDIBHdr->biXPelsPerMeter = 0L;
m_lpDIBHdr->biYPelsPerMeter = 0L;
m_lpDIBHdr->biClrUsed = 0L;
m_lpDIBHdr->biClrImportant = 0L;
T=100;
A=122;
Bb=10;
a=8;
////////////////
//My Code Ends Here!
////////////////
return TRUE; // return TRUE unless you set the focus to a control
}
void CAntifilterDlg::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 CAntifilterDlg::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
{
CPaintDC dc(this);
///////////////////
//My Code Start Here!
///////////////////
//Display the original Image!
::SetDIBitsToDevice(dc.m_hDC,10,10,192,192,
0,0,0,192,m_lpDIBBit1,(LPBITMAPINFO)m_lpDIBHdr,
DIB_RGB_COLORS );
//Display the Filtering Image!
::SetDIBitsToDevice(dc.m_hDC,10,260,192,192,
0,0,0,192,m_lpDIBBit2,(LPBITMAPINFO)m_lpDIBHdr,
DIB_RGB_COLORS );
//Display the Recovery Image!
::SetDIBitsToDevice(dc.m_hDC,260,260,192,192,
0,0,0,192,m_lpDIBBit3,(LPBITMAPINFO)m_lpDIBHdr,
DIB_RGB_COLORS );
//////////////////
//My Code Ends Here!
//////////////////
CDialog::OnPaint();
}
}
HCURSOR CAntifilterDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
void CAntifilterDlg::OnOpenButton()
{
/*
Function:
read Bmp Data into the buff!