⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 filterdlg.cpp

📁 c语言实现的遥感图像处理的一些基本操作
💻 CPP
字号:
// FilterDlg.cpp : implementation file
//

#include "stdafx.h"
#include "RSImageStar.h"
#include "FilterDlg.h"
#include "MainFrm.h"
#include "RSImageStarDoc.h"
#include "RSImageStarView.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CFilterDlg dialog


CFilterDlg::CFilterDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CFilterDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CFilterDlg)
	m_edit1 = 0;
	m_edit2 = 0;
	m_edit3 = 0;
	m_edit4 = 0;
	m_edit5 = 0;
	m_edit6 = 0;
	m_edit7 = 0;
	m_edit8 = 0;
	m_edit9 = 0;
	m_check = FALSE;
	//}}AFX_DATA_INIT
}


void CFilterDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CFilterDlg)
	DDX_Control(pDX, IDC_COMBO1, m_ComboBox);
	DDX_Text(pDX, IDC_EDIT1, m_edit1);
	DDV_MinMaxInt(pDX, m_edit1, -100, 100);
	DDX_Text(pDX, IDC_EDIT2, m_edit2);
	DDV_MinMaxInt(pDX, m_edit2, -100, 100);
	DDX_Text(pDX, IDC_EDIT3, m_edit3);
	DDV_MinMaxInt(pDX, m_edit3, -100, 100);
	DDX_Text(pDX, IDC_EDIT4, m_edit4);
	DDV_MinMaxInt(pDX, m_edit4, -100, 100);
	DDX_Text(pDX, IDC_EDIT5, m_edit5);
	DDV_MinMaxInt(pDX, m_edit5, -100, 100);
	DDX_Text(pDX, IDC_EDIT6, m_edit6);
	DDV_MinMaxInt(pDX, m_edit6, -100, 100);
	DDX_Text(pDX, IDC_EDIT7, m_edit7);
	DDV_MinMaxInt(pDX, m_edit7, -100, 100);
	DDX_Text(pDX, IDC_EDIT8, m_edit8);
	DDV_MinMaxInt(pDX, m_edit8, -100, 100);
	DDX_Text(pDX, IDC_EDIT9, m_edit9);
	DDV_MinMaxInt(pDX, m_edit9, -100, 100);
	DDX_Check(pDX, IDC_CHECK1, m_check);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CFilterDlg, CDialog)
	//{{AFX_MSG_MAP(CFilterDlg)
	ON_WM_DESTROY()
	ON_BN_CLICKED(IDC_CHECK1, OnCheck1)
	ON_EN_CHANGE(IDC_EDIT1, OnChangeEdit1)
	ON_EN_CHANGE(IDC_EDIT2, OnChangeEdit2)
	ON_EN_CHANGE(IDC_EDIT3, OnChangeEdit3)
	ON_EN_CHANGE(IDC_EDIT4, OnChangeEdit4)
	ON_EN_CHANGE(IDC_EDIT5, OnChangeEdit5)
	ON_EN_CHANGE(IDC_EDIT6, OnChangeEdit6)
	ON_EN_CHANGE(IDC_EDIT7, OnChangeEdit7)
	ON_EN_CHANGE(IDC_EDIT8, OnChangeEdit8)
	ON_EN_CHANGE(IDC_EDIT9, OnChangeEdit9)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CFilterDlg message handlers

void CFilterDlg::OnDestroy() 
{
	CDialog::OnDestroy();
	
	// TODO: Add your message handler code here
	num[0]=m_edit1;
	num[1]=m_edit2;
	num[2]=m_edit3;
	num[3]=m_edit4;
	num[4]=m_edit5;
	num[5]=m_edit6;
	num[6]=m_edit7;
	num[7]=m_edit8;
	num[8]=m_edit9;
    if(m_hDib!=NULL)
	{
		GlobalUnlock(m_hDib);
		GlobalFree(m_hDib);
		m_hDib=NULL;
	}	
	CFrameWnd* lpFrameWnd = STATIC_DOWNCAST(CFrameWnd, AfxGetMainWnd());
	if( lpFrameWnd == NULL ) return;
    CRSImageStarView* lpView = (CRSImageStarView*)lpFrameWnd->GetActiveFrame()->GetActiveView();
    lpView->m_PreView=true;
}

BOOL CFilterDlg::OnInitDialog() 
{
	CDialog::OnInitDialog();
	
	// TODO: Add extra initialization here
    m_ComboBox.SetWindowText("3x3");
	num[0]=m_edit1=0;
	num[1]=m_edit2=0;
	num[2]=m_edit3=0;
	num[3]=m_edit4=0;
	num[4]=m_edit5=1;
	num[5]=m_edit6=0;
	num[6]=m_edit7=0;
	num[7]=m_edit8=0;
	num[8]=m_edit9=0;	
	m_check=true;
    UpdateData(false);
	CButton* button= (CButton*)GetDlgItem(IDC_CHECK1);
	CFrameWnd* lpFrameWnd = STATIC_DOWNCAST(CFrameWnd, AfxGetMainWnd());
	if( lpFrameWnd == NULL ) return 0;
    CRSImageStarView* lpView = (CRSImageStarView*)lpFrameWnd->GetActiveFrame()->GetActiveView();
    if(lpView->m_pDoc->m_Dib->m_hPreDib==NULL)
		return false;
	DWORD dwSize = GlobalSize(lpView->m_pDoc->m_Dib->m_hPreDib);
    ASSERT(dwSize);
  	LPBYTE lpDib = (LPBYTE) ::GlobalLock(lpView->m_pDoc->m_Dib->m_hPreDib);
    ASSERT(lpDib);
    lpView->m_PreView=true;
	if( m_hDib != NULL )
    {
		GlobalUnlock( m_hDib );
        GlobalFree( m_hDib );
        m_hDib = NULL;
    }
	m_hDib      = ::GlobalAlloc(GMEM_MOVEABLE | GMEM_ZEROINIT, dwSize);
   	LPBYTE lpfile = (LPBYTE) ::GlobalLock(m_hDib);
	memcpy(lpfile,lpDib,dwSize); 
    ::GlobalUnlock(lpView->m_pDoc->m_Dib->m_hPreDib);
    ::GlobalUnlock(m_hDib);
    button->SetCheck(m_check);
	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}

void CFilterDlg::OnCheck1() 
{
	// TODO: Add your control notification handler code here
  CFrameWnd* lpFrameWnd = STATIC_DOWNCAST(CFrameWnd, AfxGetMainWnd());
  if( lpFrameWnd == NULL ) return ;
  CRSImageStarView* lpView = (CRSImageStarView*)lpFrameWnd->GetActiveFrame()->GetActiveView();
 
   LPBYTE lpDib = (LPBYTE) ::GlobalLock(lpView->m_pDoc->m_Dib->m_hPreDib);
   ASSERT(lpDib);
   LPBITMAPINFO lpbmi=(LPBITMAPINFO)lpDib;
   int numcolor=lpView->m_pDoc->m_Dib->GetColorMapNum(lpbmi->bmiHeader.biBitCount);
   int DibInfoSize = sizeof(BITMAPINFOHEADER) + numcolor*sizeof(RGBQUAD);
   LPBYTE lpdata=lpDib+DibInfoSize;

	m_check=m_check?false:true;
	if(m_check)
	{
       lpView->m_PreView=true;
		Filter();
	   lpView->Invalidate();
	}
	else
	{
       lpView->m_PreView=false;
	   lpView->Invalidate();
	}
}

BOOL CFilterDlg::Filter() 
{
	if (m_hDib == NULL)
		return false;
	
	CFrameWnd* lpFrameWnd = STATIC_DOWNCAST(CFrameWnd, AfxGetMainWnd());
	if( lpFrameWnd == NULL ) return false;
	CRSImageStarView* lpView = (CRSImageStarView*)lpFrameWnd->GetActiveFrame()->GetActiveView();
	
	LPBYTE lpDib = (LPBYTE) ::GlobalLock(lpView->m_pDoc->m_Dib->m_hPreDib);
	ASSERT(lpDib);
	LPBITMAPINFO lpbmi=(LPBITMAPINFO)lpDib;
	int numcolor=lpView->m_pDoc->m_Dib->GetColorMapNum(lpbmi->bmiHeader.biBitCount);
	int DibInfoSize = sizeof(BITMAPINFOHEADER) + numcolor*sizeof(RGBQUAD);
	LPBYTE lpdata=lpDib+DibInfoSize;
	
	int width=lpbmi->bmiHeader.biWidth;
	int width1=(lpbmi->bmiHeader.biWidth*lpbmi->bmiHeader.biBitCount/8+3)&~3;
	int height=lpbmi->bmiHeader.biHeight;
	CRect r;
	r.left=r.top=0;
	r.right=width;
	r.bottom=height;

	LPBYTE lpfile = (LPBYTE) ::GlobalLock(m_hDib);
	LPBITMAPINFO lpbmi1=(LPBITMAPINFO)lpfile;
	
	LPBYTE lpdata1=lpfile+DibInfoSize;   
    
    UpdateData(TRUE);
    int scale=0;
	char  Matr[3][3];
	Matr[0][0]=m_edit1;
	Matr[0][1]=m_edit2;
	Matr[0][2]=m_edit3;
	Matr[1][0]=m_edit4;
	Matr[1][1]=m_edit5;
	Matr[1][2]=m_edit6;
	Matr[2][0]=m_edit7;
	Matr[2][1]=m_edit8;
	Matr[2][2]=m_edit9;
	scale+=m_edit1;	
	scale+=m_edit2;	
	scale+=m_edit3;	
	scale+=m_edit4;	
	scale+=m_edit5;	
	scale+=m_edit6;	
	scale+=m_edit7;	
	scale+=m_edit8;	
	scale+=m_edit9;	

    LPBYTE out[3];
	out[0]=(BYTE *)malloc(width1);
	out[1]=(BYTE *)malloc(width1);
	out[2]=(BYTE *)malloc(width1);
    
    memcpy(out[0],lpdata1,width1);
	lpdata1+=width1;
    memcpy(out[1],lpdata1,width1);
	lpdata1+=width1;
    memcpy(out[2],lpdata1,width1);
	lpdata1+=width1;

    BYTE data[3][3];
    int iDiff;
	for (int y=r.top;y<r.bottom; y++)
	{
		RGBTRIPLE *pixptr =(RGBTRIPLE *)out[0];
		RGBTRIPLE *pixptr1 =(RGBTRIPLE *)out[1];
		RGBTRIPLE *pixptr2 =(RGBTRIPLE *)out[2];
		LPBYTE lpfile=lpdata+width1*y;
		for (int x=r.left;x<r.right; x++)
		{
			data[1][1]=pixptr1[x].rgbtBlue;
			if(x==r.left)
			{
				data[0][0]=pixptr[x].rgbtBlue;
				data[0][1]=pixptr[x].rgbtBlue;
				data[0][2]=pixptr[x+1].rgbtBlue;
				data[1][0]=pixptr1[x].rgbtBlue;
				data[1][2]=pixptr1[x+1].rgbtBlue;
				data[2][0]=pixptr2[x].rgbtBlue;
				data[2][1]=pixptr2[x].rgbtBlue;
				data[2][2]=pixptr2[x+1].rgbtBlue;
            }
			else if(x==(r.right-1))
			{
				data[0][0]=pixptr[x-1].rgbtBlue;
				data[0][1]=pixptr[x].rgbtBlue;
				data[0][2]=pixptr[x].rgbtBlue;
				data[1][0]=pixptr1[x-1].rgbtBlue;
				data[1][2]=pixptr1[x].rgbtBlue;
				data[2][0]=pixptr2[x-1].rgbtBlue;
				data[2][1]=pixptr2[x].rgbtBlue;
				data[2][2]=pixptr2[x].rgbtBlue;
			}
            else
			{
				data[0][0]=pixptr[x-1].rgbtBlue;
				data[0][1]=pixptr[x].rgbtBlue;
				data[0][2]=pixptr[x+1].rgbtBlue;
				data[1][0]=pixptr1[x-1].rgbtBlue;
				data[1][2]=pixptr1[x+1].rgbtBlue;
				data[2][0]=pixptr2[x-1].rgbtBlue;
				data[2][1]=pixptr2[x].rgbtBlue;
				data[2][2]=pixptr2[x+1].rgbtBlue;
			}
			iDiff=ComputeMatrix(data,Matr);
			iDiff=iDiff/scale;
            *lpfile++=iDiff;
			
			data[1][1]=pixptr1[x].rgbtGreen;
			if(x==r.left)
			{
				data[0][0]=pixptr[x].rgbtGreen;
				data[0][1]=pixptr[x].rgbtGreen;
				data[0][2]=pixptr[x+1].rgbtGreen;
				data[1][0]=pixptr1[x].rgbtGreen;
				data[1][2]=pixptr1[x+1].rgbtGreen;
				data[2][0]=pixptr2[x].rgbtGreen;
				data[2][1]=pixptr2[x].rgbtGreen;
				data[2][2]=pixptr2[x+1].rgbtGreen;
            }
			else if(x==(r.right-1))
			{
				data[0][0]=pixptr[x-1].rgbtGreen;
				data[0][1]=pixptr[x].rgbtGreen;
				data[0][2]=pixptr[x].rgbtGreen;
				data[1][0]=pixptr1[x-1].rgbtGreen;
				data[1][2]=pixptr1[x].rgbtGreen;
				data[2][0]=pixptr2[x-1].rgbtGreen;
				data[2][1]=pixptr2[x].rgbtGreen;
				data[2][2]=pixptr2[x].rgbtGreen;
			}
            else
			{
				data[0][0]=pixptr[x-1].rgbtGreen;
				data[0][1]=pixptr[x].rgbtGreen;
				data[0][2]=pixptr[x+1].rgbtGreen;
				data[1][0]=pixptr1[x-1].rgbtGreen;
				data[1][2]=pixptr1[x+1].rgbtGreen;
				data[2][0]=pixptr2[x-1].rgbtGreen;
				data[2][1]=pixptr2[x].rgbtGreen;
				data[2][2]=pixptr2[x+1].rgbtGreen;
			}
			iDiff=ComputeMatrix(data,Matr);
			iDiff=iDiff/scale;
            *lpfile++=iDiff;
			
			data[1][1]=pixptr1[x].rgbtRed;
			if(x==r.left)
			{
				data[0][0]=pixptr[x].rgbtRed;
				data[0][1]=pixptr[x].rgbtRed;
				data[0][2]=pixptr[x+1].rgbtRed;
				data[1][0]=pixptr1[x].rgbtRed;
				data[1][2]=pixptr1[x+1].rgbtRed;
				data[2][0]=pixptr2[x].rgbtRed;
				data[2][1]=pixptr2[x].rgbtRed;
				data[2][2]=pixptr2[x+1].rgbtRed;
            }
			else if(x==(r.right-1))
			{
				data[0][0]=pixptr[x-1].rgbtRed;
				data[0][1]=pixptr[x].rgbtRed;
				data[0][2]=pixptr[x].rgbtRed;
				data[1][0]=pixptr1[x-1].rgbtRed;
				data[1][2]=pixptr1[x].rgbtRed;
				data[2][0]=pixptr2[x-1].rgbtRed;
				data[2][1]=pixptr2[x].rgbtRed;
				data[2][2]=pixptr2[x].rgbtRed;
			}
            else
			{
				data[0][0]=pixptr[x-1].rgbtRed;
				data[0][1]=pixptr[x].rgbtRed;
				data[0][2]=pixptr[x+1].rgbtRed;
				data[1][0]=pixptr1[x-1].rgbtRed;
				data[1][2]=pixptr1[x+1].rgbtRed;
				data[2][0]=pixptr2[x-1].rgbtRed;
				data[2][1]=pixptr2[x].rgbtRed;
				data[2][2]=pixptr2[x+1].rgbtRed;
			}
			iDiff=ComputeMatrix(data,Matr);
			iDiff=iDiff/scale;
            *lpfile++=iDiff;
		}
        memcpy(out[0],out[1],width1);
        memcpy(out[1],out[2],width1);
		if(y<(r.bottom-3))
		{
			memcpy(out[2],lpdata1,width1);
			lpdata1+=width1;
		}
	  }
	free(out[0]);
	free(out[1]);
	free(out[2]);
	lpView->Invalidate();
	return true;
}

int CFilterDlg::ComputeMatrix(BYTE Matr1[3][3],char Matr2[3][3])
{
    int sum=0;
	for(int i=0;i<3;i++)
		for(int j=0;j<3;j++)
          sum+=Matr1[i][j]*Matr2[i][j];
	return sum;
}

void CFilterDlg::OnChangeEdit1() 
{
	// TODO: If this is a RICHEDIT control, the control will not
	// send this notification unless you override the CDialog::OnInitDialog()
	// function and call CRichEditCtrl().SetEventMask()
	// with the ENM_CHANGE flag ORed into the mask.

	// TODO: Add your control notification handler code here
    if(m_check)
		Filter();	
}

void CFilterDlg::OnChangeEdit2() 
{
	// TODO: If this is a RICHEDIT control, the control will not
	// send this notification unless you override the CDialog::OnInitDialog()
	// function and call CRichEditCtrl().SetEventMask()
	// with the ENM_CHANGE flag ORed into the mask.
	
	// TODO: Add your control notification handler code here
    if(m_check)
		Filter();	
}

void CFilterDlg::OnChangeEdit3() 
{
	// TODO: If this is a RICHEDIT control, the control will not
	// send this notification unless you override the CDialog::OnInitDialog()
	// function and call CRichEditCtrl().SetEventMask()
	// with the ENM_CHANGE flag ORed into the mask.
	
	// TODO: Add your control notification handler code here
    if(m_check)
		Filter();	
}

void CFilterDlg::OnChangeEdit4() 
{
	// TODO: If this is a RICHEDIT control, the control will not
	// send this notification unless you override the CDialog::OnInitDialog()
	// function and call CRichEditCtrl().SetEventMask()
	// with the ENM_CHANGE flag ORed into the mask.
	
	// TODO: Add your control notification handler code here
    if(m_check)
		Filter();	
}

void CFilterDlg::OnChangeEdit5() 
{
	// TODO: If this is a RICHEDIT control, the control will not
	// send this notification unless you override the CDialog::OnInitDialog()
	// function and call CRichEditCtrl().SetEventMask()
	// with the ENM_CHANGE flag ORed into the mask.
	
	// TODO: Add your control notification handler code here
    if(m_check)
		Filter();	
}

void CFilterDlg::OnChangeEdit6() 
{
	// TODO: If this is a RICHEDIT control, the control will not
	// send this notification unless you override the CDialog::OnInitDialog()
	// function and call CRichEditCtrl().SetEventMask()
	// with the ENM_CHANGE flag ORed into the mask.
	
	// TODO: Add your control notification handler code here
    if(m_check)
		Filter();	
}

void CFilterDlg::OnChangeEdit7() 
{
	// TODO: If this is a RICHEDIT control, the control will not
	// send this notification unless you override the CDialog::OnInitDialog()
	// function and call CRichEditCtrl().SetEventMask()
	// with the ENM_CHANGE flag ORed into the mask.
	
	// TODO: Add your control notification handler code here
    if(m_check)
		Filter();	
}

void CFilterDlg::OnChangeEdit8() 
{
	// TODO: If this is a RICHEDIT control, the control will not
	// send this notification unless you override the CDialog::OnInitDialog()
	// function and call CRichEditCtrl().SetEventMask()
	// with the ENM_CHANGE flag ORed into the mask.
	
	// TODO: Add your control notification handler code here
    if(m_check)
		Filter();	
}

void CFilterDlg::OnChangeEdit9() 
{
	// TODO: If this is a RICHEDIT control, the control will not
	// send this notification unless you override the CDialog::OnInitDialog()
	// function and call CRichEditCtrl().SetEventMask()
	// with the ENM_CHANGE flag ORed into the mask.
	
	// TODO: Add your control notification handler code here
    if(m_check)
		Filter();	
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -