www.pudn.com > DigtalImageProc.rar > DigtalImageProcDlg.cpp
// DigtalImageProcDlg.cpp : implementation file
//
#include "stdafx.h"
#include "DigtalImageProc.h"
#include "DigtalImageProcDlg.h"
#include "membitmap.h"
#include "dft.h"
#include "ImageCT.h"
#include "FilterDialog.h"
#include "FilterMask.h"
#include "HistoGramDialog.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CDigtalImageProcDlg dialog
CDigtalImageProcDlg::CDigtalImageProcDlg(CWnd* pParent /*=NULL*/)
: CDialog(CDigtalImageProcDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CDigtalImageProcDlg)
m_Angle = 0;
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
m_ByteData = NULL;
}
void CDigtalImageProcDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CDigtalImageProcDlg)
DDX_Text(pDX, IDC_ANGLE, m_Angle);
DDV_MinMaxUInt(pDX, m_Angle, 0, 90);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CDigtalImageProcDlg, CDialog)
//{{AFX_MSG_MAP(CDigtalImageProcDlg)
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(IDC_DFT, OnDft)
ON_BN_CLICKED(IDC_IDFT, OnIdft)
ON_BN_CLICKED(IDC_DFFT, OnDfft)
ON_BN_CLICKED(IDC_IDFFT, OnIdfft)
ON_BN_CLICKED(IDC_HMIRROR, OnHmirror)
ON_BN_CLICKED(IDC_VMIRROR, OnVmirror)
ON_BN_CLICKED(IDC_ZOOMOUT, OnZoomout)
ON_BN_CLICKED(IDC_ZOOMIN, OnZoomin)
ON_BN_CLICKED(IDC_GRAY, OnGray)
ON_BN_CLICKED(IDC_ROTATE, OnRotate)
ON_BN_CLICKED(IDC_OPEN, OnOpen)
ON_BN_CLICKED(IDC_SAVE, OnSave)
ON_BN_CLICKED(IDC_HISTO, OnHistoGram)
ON_BN_CLICKED(IDC_HISTOEQ, OnHistoeq)
ON_BN_CLICKED(IDC_NAGATIVE, OnNagative)
ON_BN_CLICKED(IDC_EXCHANGE, OnExchange)
ON_BN_CLICKED(IDC_PEPPERNOISE, OnPeppernoise)
ON_BN_CLICKED(IDC_GAUSSNOISE, OnGaussnoise)
ON_BN_CLICKED(IDC_GARKEN, OnGarken)
ON_BN_CLICKED(IDC_LIGHTEN, OnLighten)
ON_BN_CLICKED(IDC_SPACELPF, OnSpacelpf)
ON_BN_CLICKED(IDC_MEDIANFILTER, OnMedianfilter)
ON_BN_CLICKED(IDC_IDEALPF, OnIdealpf)
ON_BN_CLICKED(IDC_IDEAHPF, OnIdeahpf)
ON_BN_CLICKED(IDC_IDEABANDPF, OnIdeabandpf)
ON_WM_DESTROY()
ON_BN_CLICKED(IDC_BUTTLP, OnLPButterworth)
ON_BN_CLICKED(IDC_BUTTHP, OnHPButterworth)
ON_BN_CLICKED(IDC_SOBEL, OnSobel)
ON_BN_CLICKED(IDC_PREWITT, OnPrewitt)
ON_BN_CLICKED(IDC_ROBERT, OnRobert)
ON_BN_CLICKED(IDC_BIVALUE, OnBivalue)
ON_BN_CLICKED(IDC_LAPLAS, OnLaplas)
ON_BN_CLICKED(IDC_EROSION, OnErosion)
ON_BN_CLICKED(IDC_CUT, OnCut)
ON_BN_CLICKED(IDOK2, OnOk2)
ON_BN_CLICKED(IDC_EXCHANGE3, OnView)
ON_BN_CLICKED(IDC_Hide, OnHide)
ON_BN_CLICKED(IDC_View2, OnView2)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CDigtalImageProcDlg message handlers
BOOL CDigtalImageProcDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// 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
Rect1.SubclassDlgItem(IDC_PIC1,this);
Rect2.SubclassDlgItem(IDC_PIC2,this);
return TRUE; // return TRUE unless you set the focus to a control
}
// 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 CDigtalImageProcDlg::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
{
CDialog::OnPaint();
}
}
// The system calls this to obtain the cursor to display while the user drags
// the minimized window.
HCURSOR CDigtalImageProcDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
void CDigtalImageProcDlg::OnDft()
{
// TODO: Add your control notification handler code here
if(!pic1.flag)
{
AfxMessageBox("图象文件未打开!");
return;
}
pic2 = pic1;
ImageGray(pic2,pic1);
Rect1.SetBitmap(pic1);
int width=pic1.GetWidth();
int height=pic1.GetHeight();
if(m_ByteData)delete[] m_ByteData;
m_ByteData=new BYTE[(long)width*height*sizeof(wComplex)];
m_Data=(wComplex *)m_ByteData;
if(!m_Data)
{
AfxMessageBox("内存不够");
return;
}
int i,j;
for(i=0;itotal)total=data[i];
if(rdata[i]>rtotal)rtotal=rdata[i];
if(gdata[i]>gtotal)gtotal=gdata[i];
if(bdata[i]>btotal)btotal=bdata[i];
}
for(i=0;i<256;i++)
{
CDigtalImageProcApp *app=(CDigtalImageProcApp *)AfxGetApp();
app->GrayData[i]=(float)data[i]/total;
app->RedData[i]=(float)rdata[i]/rtotal;
app->GreenData[i]=(float)gdata[i]/gtotal;
app->BlueData[i]=(float)bdata[i]/btotal;
}
HistoGramDialog dlg;
dlg.DoModal();
}
void CDigtalImageProcDlg::OnHistoeq()
{
// TODO: Add your control notification handler code here
}
void CDigtalImageProcDlg::OnNagative()
{
// TODO: Add your control notification handler code here
if(!pic1.flag)
{
AfxMessageBox("图象文件未打开!");
return;
}
pic2 = pic1;
int width=pic1.GetWidth();
int height=pic1.GetHeight();
int i,j;
for(i=0;i31500)
pic2.SetPixel(x,y,RGB(0,0,0));
}
}
Rect2.SetBitmap(pic2);
}
void CDigtalImageProcDlg::OnGaussnoise()
{
// TODO: Add your control notification handler code here
if(!pic1.flag)
{
AfxMessageBox("图象文件未打开!");
return;
}
int x,y,Point;
int w = pic1.GetWidth(),h = pic1.GetHeight();
pic2 = pic1;
srand((unsigned)time(NULL));
for(y=0;yRadius*Radius)
*(m_Data+j*width+i)=wComplex(0.0,0.0);
}
}
memBitmap temp(width,height,pic2);
ImageNFFT(m_Data,temp);
pic2 = temp;
Rect2.SetBitmap(pic2);
EndWaitCursor();
}
bool CDigtalImageProcDlg::IsMiOf2(UINT var)
{
UINT i=0;
UINT a=var;
while(a)
{
a>>=1;
i++;
}
i--;
a=1;
if(a<Radius2*Radius2)
*(m_Data+j*width+i)=wComplex(0.0,0.0);
}
}
memBitmap temp(width,height,pic2);
ImageNFFT(m_Data,temp);
pic2 = temp;
Rect2.SetBitmap(pic2);
EndWaitCursor();
}
void CDigtalImageProcDlg::OnDestroy()
{
CDialog::OnDestroy();
// TODO: Add your message handler code here
if(m_ByteData)delete m_ByteData;
}
void CDigtalImageProcDlg::OnLPButterworth()
{
// TODO: Add your control notification handler code here
}
void CDigtalImageProcDlg::OnHPButterworth()
{
// TODO: Add your control notification handler code here
if(!pic1.flag)
{
AfxMessageBox("图象文件未打开!");
return;
}
CFilterDialog fd;
fd.SetFilterMode(2);
if(fd.DoModal() != IDOK)return;
int Radius = fd.m_min;
BeginWaitCursor();
int width=pic1.GetWidth();
int height=pic1.GetHeight();
pic2 = pic1;
ImageGray(pic2,pic1);
Rect1.SetBitmap(pic1);
if(!IsMiOf2(width)|!IsMiOf2(height))
{
AfxMessageBox("图象的长和宽为2的幂时频域滤波才可以使用FFT");
return;
}
if(m_ByteData)delete m_ByteData;
m_ByteData=new BYTE[(long)width*height*sizeof(wComplex)];
m_Data=(wComplex *)m_ByteData;
if(!m_Data)
{
AfxMessageBox("内存不够");
return;
}
int i,j;
for(i=0;imax) max=d;
}
if (max>255) max=255;
pic2.SetPixel(x,y,RGB(max,max,max));
}
}
Rect2.SetBitmap(pic2);
EndWaitCursor();
}
void CDigtalImageProcDlg::OnRobert()
{
// TODO: Add your control notification handler code here
}
void CDigtalImageProcDlg::OnBivalue()
{
// TODO: Add your control notification handler code here
int x,y;
if(!pic1.flag)
{
AfxMessageBox("图象文件未打开!");
return;
}
int h = pic1.GetHeight(),w = pic1.GetWidth();
BeginWaitCursor();
pic2 = pic1;
memBitmap temp(w,h,pic2);
ImageGray(pic2,temp);
for(x = 0; x < w; x++)
for(y = 0; y < h; y++)
{
if(GetRValue(temp.GetPixel(x,y)) > 127)
pic2.SetPixel(x,y,RGB(255,255,255));
else
pic2.SetPixel(x,y,RGB(0,0,0));
}
Rect2.SetBitmap(pic2);
EndWaitCursor();
}
void CDigtalImageProcDlg::OnLaplas()
{
// TODO: Add your control notification handler code here
}
void CDigtalImageProcDlg::OnErosion()
{
// TODO: Add your control notification handler code here
int x,y;
if(!pic1.flag)
{
AfxMessageBox("图象文件未打开!");
return;
}
int h = pic1.GetHeight(),w = pic1.GetWidth();
BeginWaitCursor();
pic2 = pic1;
memBitmap temp(w,h,pic2);
ImageGray(pic2,temp);
for(x = 0; x < w; x++)
for(y = 0; y < h; y++)
{
if(GetRValue(temp.GetPixel(x,y)) > 127)
pic2.SetPixel(x,y,RGB(255,255,255));
else
pic2.SetPixel(x,y,RGB(0,0,0));
}
temp = pic2;
for(y = 1; y < h-1; y++)
for(x = 1; x < w-1; x++)
{
if(!pic2.GetPixel(x,y))
{
temp.SetPixel(x,y,RGB(0,0,0));
if(pic2.GetPixel(x,y-1)||pic2.GetPixel(x,y+1))
temp.SetPixel(x,y,RGB(255,255,255));
}
}
for(x = 1; x < w-1; x++)
for(y = 1; y < h-1; y++)
{
if(!pic2.GetPixel(x,y))
{
temp.SetPixel(x,y,RGB(0,0,0));
if(pic2.GetPixel(x-1,y)||pic2.GetPixel(x+1,y))
temp.SetPixel(x,y,RGB(255,255,255));
}
}
pic2 = temp;
temp.Release();
Rect2.SetBitmap(pic2);
EndWaitCursor();
}
void CDigtalImageProcDlg::OnCut()
{
// TODO: Add your control notification handler code here
if(!pic1.flag)
{
AfxMessageBox("图象文件未打开!");
return;
}
BeginWaitCursor();
int w=pic1.GetWidth(),h=pic1.GetHeight(),i,j;
double w1=w*0.33;
pic2.CreateDirect(w,h);
for(i=0;i>3)&0x7;
b3=(gr>>3)&0x3;
r|=b3;
g|=b2;
b|=b1;
pic2.SetPixel(i,j,RGB(r,g,b));
}
Rect2.SetBitmap(pic2);
}
void CDigtalImageProcDlg::OnView2()
{
// TODO: Add your control notification handler code here
if(!pic1.flag)
{
AfxMessageBox("图象文件未打开!");
return;
}
UINT i,j,w=pic1.GetWidth(),h=pic1.GetHeight(),r,g,b,gr,b1,b2;
BeginWaitCursor();
pic2.CreateDirect(w,h);
for(i=0;i