www.pudn.com > Imagepro_4.rar > ImageproView.cpp


// ImageproView.cpp : implementation of the CImageproView class 
// 
 
#include "stdafx.h" 
#include "Imagepro.h" 
 
#include "ImageproDoc.h" 
#include "ImageproView.h" 
#include "MainFrm.h" 
#include  "ChildFrm.h" 
#include "GetThreshold.h" 
 
#ifdef _DEBUG 
#define new DEBUG_NEW 
#undef THIS_FILE 
static char THIS_FILE[] = __FILE__; 
#endif 
 
///////////////////////////////////////////////////////////////////////////// 
// CImageproView 
 
extern HANDLE hDIBBK1; 
extern HANDLE hDIBBK2; 
extern HANDLE hDIBBKGray; 
extern HANDLE hDIBBKGradient; 
HANDLE hDIBCurrent = NULL; 
CPoint ImportantPoint,ImportantPoint2,ImpPoiCur; 
CPoint ImportantPointSecond; 
int ImportantColorInfo[RADIUS*2+1][RADIUS*2+1][3]; 
int locax,locay; 
IMPLEMENT_DYNCREATE(CImageproView, CScrollView) 
 
BEGIN_MESSAGE_MAP(CImageproView, CScrollView) 
	//{{AFX_MSG_MAP(CImageproView) 
	ON_COMMAND(ID_SEGMENT_EDGE_LAPLACIAN, OnSegmentEdgeLaplacian) 
	ON_COMMAND(ID_SEGMENT_EDGE_LOG, OnSegmentEdgeLog) 
	ON_COMMAND(ID_SEGMENT_EDGE_ROBERTS, OnSegmentEdgeRoberts) 
	ON_COMMAND(ID_SEGMENT_EDGE_SOBEL, OnSegmentEdgeSobel) 
	ON_COMMAND(ID_SEGMET_EDGE_PREWITT, OnSegmetEdgePrewitt) 
	ON_COMMAND(ID_THRESHOLD_MESM, OnThresholdMesm) 
	ON_COMMAND(ID_THRESHOLD_JOHANNSON, OnThresholdJohannson) 
	ON_COMMAND(ID_THRESHOLD_GLOBAL, OnThresholdGlobal) 
	ON_COMMAND(ID_THRESHOLD_KAPUR, OnThresholdKapur) 
	ON_COMMAND(ID_THRESHOLD_MINCROSS, OnThresholdMincross) 
	ON_COMMAND(ID_THRESHOLD_CONCAVITY, OnThresholdConcavity) 
	ON_COMMAND(ID_THRESHOLD_OSTU, OnThresholdOstu) 
	ON_COMMAND(ID_THRESHOLD_GRADIENT, OnThresholdGradient) 
	ON_COMMAND(ID_THRESHOLD_PROSERVE, OnThresholdProserve) 
	ON_COMMAND(ID_THRESHOLD_REDDI, OnThresholdReddi) 
	ON_COMMAND(ID_REGION_THRESHOLD_BASED, OnRegionThresholdBased) 
	ON_COMMAND(GMENT_EDGE_LAPLACIAN2, OnEdgeLaplacian2) 
	ON_COMMAND(ID_SEGMET_EDGE_PREWITT2, OnSegmetEdgePrewitt2) 
	ON_COMMAND(ID_SEGMENT_EDGE_KRISCH, OnSegmentEdgeKrisch) 
	ON_COMMAND(ID_SEGMENT_EDGE_KRISCH2, OnSegmentEdgeKrisch2) 
	ON_COMMAND(ID_FILE_SAVE, OnFileSave) 
	ON_COMMAND(ID_FILE_SAVE_AS, OnFileSaveAs) 
	ON_COMMAND(ID_SUB, OnSub) 
	ON_COMMAND(ID_SEGMENT_EDGE_ROBERTS2, OnSegmentEdgeRoberts2) 
	ON_COMMAND(ID_MENU_BK_FTRST, OnMenuBkFtrst) 
	ON_COMMAND(ID_MENU_BK_GRAY, OnMenuBkGray) 
	ON_COMMAND(ID_MENU_BK_SECOND, OnMenuBkSecond) 
	ON_COMMAND(ID_MENU_GRADIENT, OnMenuGradient) 
	ON_COMMAND(ID_MENU_MEDIFILTER, OnMenuMedifilter) 
	ON_COMMAND(ID_MENU_PIPEI, OnMenuPipei) 
	ON_COMMAND(ID_MENU_PIPEIZHONGXIN, OnMenuPipeizhongxin) 
	ON_COMMAND(ID_MENU_TEZHENGQUYU, OnMenuTezhengquyu) 
	ON_COMMAND(ID_MENU_MEDIFILTER2, OnMenuMedifilter2) 
	ON_COMMAND(ID_MENU_FILELOAD, OnMenuFileload) 
	ON_COMMAND(ID_MENU_MEDFILTER, OnMenuMedfilter) 
	ON_COMMAND(ID_MENU_MARCHING, OnMenuMarching) 
	ON_COMMAND(ID_MENU_MATCHING2, OnMenuMatching2) 
	ON_COMMAND(ID_MENU_SHOWOBJECT, OnMenuShowobject) 
	//}}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() 
 
///////////////////////////////////////////////////////////////////////////// 
// CImageproView construction/destruction 
 
CImageproView::CImageproView() 
{ 
	// TODO: add construction code here 
      currentwidth = 0 ;			//图像的宽和高,即实际图像个数 
	  currentheight = 0 ; 
	   flag_binary  = 0  ; 
	   m_bk_first_width = 0 ; 
	   m_bk_first_height = 0 ; 
       isBKChonsen = false; 
	   hDIBBK1 = NULL; 
	   hDIBBK2 = NULL; 
	   hDIBBKGray = NULL; 
	   hDIBBKGradient = NULL; 
	   isTeZhengZhi = false ; 
} 
 
CImageproView::~CImageproView() 
{ 
} 
 
BOOL CImageproView::PreCreateWindow(CREATESTRUCT& cs) 
{ 
	// TODO: Modify the Window class or styles here by modifying 
	//  the CREATESTRUCT cs 
 
	return CScrollView::PreCreateWindow(cs); 
} 
 
///////////////////////////////////////////////////////////////////////////// 
// CImageproView drawing 
 
void CImageproView::OnDraw(CDC* pDC) 
{ 
	CImageproDoc* pDoc = GetDocument(); 
	ASSERT_VALID(pDoc); 
	// TODO: add draw code for native data here 
	CMainFrame *mainframe=(CMainFrame *)AfxGetApp()->m_pMainWnd; 
	CChildFrame *childframe=(CChildFrame *)mainframe->GetActiveFrame(); 
	 
	CRect rect(0,0,599+6+6+1,599+25+6+1);//6为边框宽度,25为标题栏高度 
	childframe->MoveWindow(&rect); 
 
	long scr_x=mainframe->ViewRect.Width();		//4为4个frame框架的宽度 
	long scr_y=mainframe->ViewRect.Height();	//31位视图的标题栏大小 
	 
	if(pDoc->bopendoc) 
	{	 
		pDoc->bopendoc=false; 
		if(m_Dib.ShowImage(pDC,true,pDoc->strfilename)==FALSE) 
			return; 
		currentwidth=m_Dib.m_dwWidth; 
		currentheight=m_Dib.m_dwHeight; 
		childframe->MoveWindow(0,0,(int)(currentwidth*m_Dib.scale)+12,(int)(currentheight*m_Dib.scale)+32 ); 
		mainframe->SendMessage(WM_VIEWCHANGED); 
	} 
	scr_x=600; 
	scr_y=600; 
/*	//设置滚动条	 
	CSize totalsize=CSize((int)(currentwidth*m_Dib.scale),(int)(currentheight*m_Dib.scale)); 
	//CSize totalsize=CSize((int)(currentwidth),(int)(currentheight)); 
    CSize pagesize; 
	if(scr_x=currentheight) 
			pagesize=CSize(scr_x,currentheight); 
		else 
		{ 
			if(scr_x>=currentwidth&&scr_y=currentwidth&&scr_y>=currentheight) 
					pagesize=CSize(currentwidth,currentheight); 
			} 
		} 
	} 
	CSize linesize=CSize(1,1); 
	//	CSize linesize=CSize(totalsize.cx/100,totalsize.cy/100); 
    SetScrollSizes(MM_TEXT,totalsize,pagesize,linesize); */ 
	 
	m_Dib.ShowImage(pDC,false); 
	if(hDIBBK1 && hDIBBKGray== NULL) 
		m_Dib.PaintDIBTrue(pDC->GetSafeHdc(),CRect(0,0,m_bk_first_width,m_bk_first_height), 
		hDIBBK1,CRect(0,0,m_bk_first_width,m_bk_first_height),SRCCOPY); 
	if(hDIBBKGray && hDIBBKGradient == NULL) 
		m_Dib.PaintDIBTrue(pDC->GetSafeHdc(),CRect(0,0,m_bk_first_width,m_bk_first_height), 
		hDIBBKGray,CRect(0,0,m_bk_first_width,m_bk_first_height),SRCCOPY); 
	if(hDIBBKGradient) 
		m_Dib.PaintDIBTrue(pDC->GetSafeHdc(),CRect(0,0,m_bk_first_width,m_bk_first_height), 
		hDIBBKGradient,CRect(0,0,m_bk_first_width,m_bk_first_height),SRCCOPY); 
	if(this->isTeZhengZhi) 
		m_Dib.PaintDIBTrue(pDC->GetSafeHdc(),CRect(0,m_bk_first_height+10,RADIUS*2+1,m_bk_first_height+10+RADIUS*2+1), 
		hDIBBK1,CRect(ImportantPoint.x-RADIUS,m_bk_first_height -ImportantPoint.y-RADIUS,ImportantPoint.x+RADIUS,m_bk_first_height -ImportantPoint.y +RADIUS),SRCCOPY); 
	if(hDIBBK2) 
	{		SetScrollSizes(MM_TEXT,CSize(m_bk_first_width*2+20,m_bk_first_height*2+10));	 
		//SetScrollSizes(MM_TEXT,CSize(m_bk_first_width*2+20,m_bk_first_height)); 
		m_Dib.PaintDIBTrue(pDC->GetSafeHdc(),CRect(m_bk_first_width+5,0,m_bk_first_width*2+5,m_bk_first_height), 
		hDIBBK2,CRect(0,0,m_bk_first_width,m_bk_first_height),SRCCOPY); 
	}	 
	if(hDIBCurrent) 
	{ 
		m_Dib.PaintDIBTrue(pDC->GetSafeHdc(),CRect(m_bk_first_width+5,m_bk_first_height+5,m_bk_first_width*2+5,m_bk_first_height*2+5), 
		hDIBCurrent,CRect(0,0,m_bk_first_width,m_bk_first_height),SRCCOPY); 
		SetScrollSizes(MM_TEXT,CSize(m_bk_first_width*2+20,m_bk_first_height*2+10)); 
	} 
} 
 
void CImageproView::OnInitialUpdate() 
{ 
	CScrollView::OnInitialUpdate(); 
 
	CSize sizeTotal; 
	// TODO: calculate the total size of this view 
	sizeTotal.cx = sizeTotal.cy = 100; 
	SetScrollSizes(MM_TEXT, sizeTotal); 
} 
 
///////////////////////////////////////////////////////////////////////////// 
// CImageproView printing 
 
BOOL CImageproView::OnPreparePrinting(CPrintInfo* pInfo) 
{ 
	// default preparation 
	return DoPreparePrinting(pInfo); 
} 
 
void CImageproView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/) 
{ 
	// TODO: add extra initialization before printing 
} 
 
void CImageproView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/) 
{ 
	// TODO: add cleanup after printing 
} 
 
///////////////////////////////////////////////////////////////////////////// 
// CImageproView diagnostics 
 
#ifdef _DEBUG 
void CImageproView::AssertValid() const 
{ 
	CScrollView::AssertValid(); 
} 
 
void CImageproView::Dump(CDumpContext& dc) const 
{ 
	CScrollView::Dump(dc); 
} 
 
CImageproDoc* CImageproView::GetDocument() // non-debug version is inline 
{ 
	ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CImageproDoc))); 
	return (CImageproDoc*)m_pDocument; 
} 
#endif //_DEBUG 
 
///////////////////////////////////////////////////////////////////////////// 
// CImageproView message handlers 
 
void CImageproView::OnSegmentEdgeLaplacian()  
{ 
	// TODO: Add your command handler code here 
	m_Dib.BeginStunt(); 
	m_Dib.Laplacian_filter8(m_Dib.m_pTempBits,currentwidth,currentheight,m_Dib.m_pDibBits); 
	//bStunt=true; 
//	m_Dib.bLoadHistab=false; 
	Invalidate(); 
	 
} 
 
void CImageproView::OnSegmentEdgeLog()  
{ 
	// TODO: Add your command handler code here 
	 
} 
 
void CImageproView::OnSegmentEdgeRoberts()  
{ 
	// TODO: Add your command handler code here 
	m_Dib.BeginStunt(); 
	m_Dib.Roberts_Edge(m_Dib.m_pTempBits,currentwidth,currentheight,m_Dib.m_pDibBits); 
	//bStunt=true; 
//	m_Dib.bLoadHistab=false; 
	Invalidate(); 
	 
} 
 
void CImageproView::OnSegmentEdgeSobel()  
{ 
	// TODO: Add your command handler code here 
	m_Dib.BeginStunt(); 
	m_Dib.Sobel_Edge(m_Dib.m_pTempBits,currentwidth,currentheight,m_Dib.m_pDibBits); 
	//bStunt=true; 
//	m_Dib.bLoadHistab=false; 
	Invalidate(); 
	 
} 
 
void CImageproView::OnSegmetEdgePrewitt()  
{ 
	// TODO: Add your command handler code here 
	m_Dib.BeginStunt(); 
	m_Dib.Prewitt1(m_Dib.m_pTempBits,currentwidth,currentheight,m_Dib.m_pDibBits); 
	//bStunt=true; 
//	m_Dib.bLoadHistab=false; 
	Invalidate(); 
	 
} 
 
void CImageproView::OnThresholdMesm()  
{ 
	// TODO: Add your command handler code here 
	flag_binary=1; 
	Binary(); 
	 
} 
 
void CImageproView::OnThresholdJohannson()  
{ 
	// TODO: Add your command handler code here 
	flag_binary=2; 
	Binary(); 
	 
} 
 
void CImageproView::OnThresholdGlobal()  
{ 
	// TODO: Add your command handler code here 
	flag_binary=10; 
	Binary();	 
	 
} 
 
void CImageproView::OnThresholdKapur()  
{ 
	// TODO: Add your command handler code here 
	flag_binary=3; 
	Binary();	 
	 
} 
 
void CImageproView::OnThresholdMincross()  
{ 
	// TODO: Add your command handler code here 
	flag_binary=9; 
	Binary(); 
	 
} 
 
void CImageproView::Binary() 
{ 
	if(!m_Dib.bLoadHistab) 
		m_Dib.GetHistab(currentwidth,currentheight,m_Dib.m_iBitCount); 
	int threshold; 
	switch(flag_binary) 
	{ 
	case 1:		//最大熵和法对图象二值化处理 
		threshold=m_Dib.MESM(m_Dib.probability); 
		break; 
	case 2:		//G. Johannson提出的基于熵的阈值选取 
		threshold=m_Dib.entropy_thresh_sel1(m_Dib.probability); 
		break; 
	case 3:		//J.N.Kapur提出的基于熵的阈值选取 
		threshold=m_Dib.entropy_thresh_sel2(m_Dib.probability);	 
		break; 
	case 4:		//Nobuyuki Ostu提出的基于矩的阈值选取 
		threshold=m_Dib.moment_shresh_sel1(m_Dib.probability);	 
		break; 
	case 5:		//S. S. Reddi提出的基于矩的阈值选取 
		threshold=m_Dib.moment_shresh_sel2(m_Dib.probability);	 
		break; 
	case 6:		//R. Rosenfield提出的基于凹度分析的阈值选取 
		threshold=m_Dib.concavity_shresh_sel(m_Dib.probability);	 
		break; 
	case 7:		//W. H. Tsai提出的矩保持的阈值选取方法 
		threshold=m_Dib.moment_preserve_shresh_sel(m_Dib.probability);	 
		break; 
	case 8:		//L. Y. Li提出的梯度均值的阈值选取方法 
		threshold=m_Dib.gradient_mean_shresh_sel(m_Dib.probability);	 
		break; 
	case 9:		//C. H. Li提出的最小交叉熵的阈值选取方法 
		threshold=m_Dib.min_cross_entropy_shresh_sel(m_Dib.probability);	 
		break; 
	case 10:	//Nikhil R. Pal提出的全局熵的阈值选取方法 
		threshold=m_Dib.global_entropy_shresh_sel(m_Dib.probability);	 
		break; 
	default: 
		return; 
	} 
	m_Dib.Binarization(threshold,m_Dib.m_iBitCount,m_Dib.m_pDibBits); 
	m_Dib.bLoadHistab=false; 
	Invalidate(); 
} 
 
void CImageproView::OnThresholdConcavity()  
{ 
	// TODO: Add your command handler code here 
	flag_binary=6; 
	Binary();	 
	 
	 
} 
 
void CImageproView::OnThresholdOstu()  
{ 
	// TODO: Add your command handler code here 
	flag_binary=4; 
	Binary();	 
	 
	 
} 
 
void CImageproView::OnThresholdGradient()  
{ 
	// TODO: Add your command handler code here 
	flag_binary=8; 
	Binary();	 
	 
	 
} 
 
void CImageproView::OnThresholdProserve()  
{ 
	// TODO: Add your command handler code here 
	flag_binary=7; 
	Binary();	 
	 
	 
} 
 
void CImageproView::OnThresholdReddi()  
{ 
	// TODO: Add your command handler code here 
	flag_binary=5; 
	Binary();	 
	 
	 
} 
 
void CImageproView::RegionGrow(CDib * pDib, unsigned char * pUnRegion, int nThreshold) 
{ 
	static int nDx[]={-1,0,1,0}; 
	static int nDy[]={0,1,0,-1}; 
 
	// 遍历图象的纵坐标 
//	int y; 
 
	// 遍历图象的横坐标 
//	int x; 
 
	// 图象的长宽大小 
//	CSize sizeImage		= pDib->GetDimensions(); 
	int nWidth			= 	pDib->m_dwWidth	; 
	int nHeight			=  pDib->m_dwHeight	; 
 
 
 
	// 图像在内存中每一行象素占用的实际空间 
	int nSaveWidth = pDib-> m_dwLine; 
 
	// 初始化 
	memset(pUnRegion,0,sizeof(unsigned char)*nWidth*nHeight); 
 
	// 种子点 
	int nSeedX, nSeedY; 
 
	// 设置种子点为图像的中心 
	nSeedX = nWidth /2 ; 
	nSeedY = nHeight/2 ; 
 
	// 定义堆栈,存储坐标 
	int * pnGrowQueX ; 
	int * pnGrowQueY ; 
	 
	// 分配空间 
	pnGrowQueX = new int [nWidth*nHeight]; 
	pnGrowQueY = new int [nWidth*nHeight]; 
 
	// 图像数据的指针 
	unsigned char *  pUnchInput =(unsigned char * )pDib->m_pTempBits; 
	 
	// 定义堆栈的起点和终点 
	// 当nStart=nEnd, 表示堆栈中只有一个点 
	int nStart ; 
	int nEnd   ; 
 
	//初始化 
	nStart = 0 ; 
	nEnd   = 0 ; 
 
	// 把种子点的坐标压入栈 
	pnGrowQueX[nEnd] = nSeedX; 
	pnGrowQueY[nEnd] = nSeedY; 
 
	// 当前正在处理的象素 
	int nCurrX ; 
	int nCurrY ; 
 
	// 循环控制变量 
	int k ; 
 
	// 图象的横纵坐标,用来对当前象素的4邻域进行遍历 
	int xx; 
	int yy; 
 
	while (nStart<=nEnd) 
	{ 
		// 当前种子点的坐标 
		nCurrX = pnGrowQueX[nStart]; 
		nCurrY = pnGrowQueY[nStart];					 
 
		// 对当前点的4邻域进行遍历 
		for (k=0; k<4; k++)	 
		{	 
			// 4邻域象素的坐标 
			xx = nCurrX+nDx[k]; 
			yy = nCurrY+nDy[k]; 
			 
			// 判断象素(xx,yy) 是否在图像内部 
			// 判断象素(xx,yy) 是否已经处理过 
			// pUnRegion[yy*nWidth+xx]==0 表示还没有处理 
 
			// 生长条件:判断象素(xx,yy)和当前象素(nCurrX,nCurrY) 象素值差的绝对值 
			if (	(xx < nWidth) && (xx>=0) && (yy=0)  
				    && (pUnRegion[yy*nWidth+xx]==0)  
					&& abs(pUnchInput[yy*nSaveWidth+xx] - pUnchInput[nCurrY*nSaveWidth+nCurrX])m_bk_first_width = lpbi->biWidth; 
		this->m_bk_first_height = lpbi->biHeight; 
		GlobalUnlock(hDIBBK1); 
		Invalidate(); 
	} 
	 
} 
 
void CImageproView::OnMenuBkGray()  
{ 
	// TODO: Add your command handler code here 
	hDIBBKGray =m_Dib.ToGray(hDIBBK1); 
	Invalidate(); 
} 
 
void CImageproView::OnMenuBkSecond()  
{ 
	// TODO: Add your command handler code here 
	CFileDialog dlg(TRUE,NULL,NULL,OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,NULL,NULL); 
	if(dlg.DoModal() == IDOK) 
	{ 
		hDIBBK2 = 	m_Dib.LoadDIB(dlg.GetPathName()); 
		if(!hDIBBK2) 
		{	 
			AfxMessageBox("open file error"); 
			return; 
		} 
			 
		Invalidate(); 
	} 
} 
 
void CImageproView::OnMenuGradient()  
{ 
	// TODO: Add your command handler code here 
	hDIBBKGradient = m_Dib.Gradient(hDIBBKGray); 
	Invalidate(); 
} 
 
void CImageproView::OnMenuMedifilter()  
{ 
	// TODO: Add your command handler code here 
	if(hDIBBK1) 
	    m_Dib.MedianFilterDIB(hDIBBK1); 
	if(hDIBBK2) 
	    m_Dib.MedianFilterDIB(hDIBBK2); 
	Invalidate(); 
	 
} 
 
void CImageproView::OnMenuPipei()  
{ 
	// TODO: Add your command handler code here 
	   m_Dib.MatchImportantPoint(hDIBBK2,ImportantColorInfo,&ImportantPoint2);  
	if( m_Dib.ComPareImg(hDIBBK1,hDIBBK2,ImportantPoint,ImportantPoint2)) 
	{ 
		AfxMessageBox("match successed"); 
		this->isBKChonsen = true; 
	} 
	else 
		AfxMessageBox("match failed"); 
	Invalidate(); 
	 
} 
 
void CImageproView::OnMenuPipeizhongxin()  
{ 
//	TODO: Add your command handler code here 
	m_Dib.LocateImporntPoint(hDIBBKGradient,RADIUS,&ImportantPoint); 
	Invalidate(); 
	 
} 
 
void CImageproView::OnMenuTezhengquyu()  
{ 
	// TODO: Add your command handler code here 
 
	long  lOffset; 
	WORD wBytesPerLine; 
	LPBYTE lpData; 
	GlobalLock(hDIBBK1); 
	wBytesPerLine = m_Dib.BytePerLine(hDIBBK1); 
	lpData = m_Dib.FindDIBBits(hDIBBK1); 
	for(int i=-RADIUS;i<=RADIUS;i++) 
		for(int j=-RADIUS;j<=RADIUS;j++) 
		{ 
			lOffset = m_Dib.PixelOffset(i+ImportantPoint.y,j+ImportantPoint.x,wBytesPerLine); 
			ImportantColorInfo[i+RADIUS][j+RADIUS][0] = *(lpData+lOffset++); 
			ImportantColorInfo[i+RADIUS][j+RADIUS][1] = *(lpData+lOffset++); 
			ImportantColorInfo[i+RADIUS][j+RADIUS][2] = *(lpData+lOffset++); 
		} 
	this->isTeZhengZhi = true; 
	GlobalUnlock(hDIBBK1); 
	Invalidate(); 
 
 
	 
} 
 
void CImageproView::OnMenuMedifilter2()  
{ 
	// TODO: Add your command handler code here 
	OnMenuMedifilter() ; 
	 
} 
 
 
void CImageproView::OnMenuFileload()  
{ 
	// TODO: Add your command handler code here 
	CFileDialog dlg(TRUE,NULL,NULL,OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,NULL,NULL); 
	if(dlg.DoModal() == IDOK) 
	{ 
		CString a; 
		a = dlg.GetPathName(); 
		hDIBCurrent = m_Dib.LoadDIB(a); 
		if(!hDIBCurrent) 
		{	 
			AfxMessageBox("open file error"); 
			return; 
		} 
			 
	 
	} 
	 
} 
 
void CImageproView::OnMenuMedfilter()  
{ 
	// TODO: Add your command handler code here 
	if(hDIBCurrent) 
	{ 
    	m_Dib.MedianFilterDIB(hDIBCurrent); 
		Invalidate(); 
	} 
	 
} 
 
void CImageproView::OnMenuMarching()  
{ 
	// TODO: Add your command handler code here 
	bool kk = m_Dib.MatchImportantPoint(hDIBCurrent,ImportantColorInfo,&ImportantPoint2); 
	 
	if(m_Dib.ComPareImg(hDIBBK1,hDIBCurrent,ImportantPoint,ImportantPoint2)) 
	{ 
		AfxMessageBox("match successed"); 
		this->isBKChonsen = true; 
	} 
	else 
		AfxMessageBox("match failed"); 
		 
	Invalidate(); 
	 
	 
} 
 
void CImageproView::OnMenuMatching2()  
{ 
	// TODO: Add your command handler code here 
	LPBITMAPINFOHEADER lpbi; 
		LPBYTE lpData; 
		WORD wBytesPerLine; 
		int height1,width1,height2,width2; 
		lpbi = (LPBITMAPINFOHEADER)GlobalLock(hDIBBK1); 
		//下面的一段代码设定第二个特征区域的查找范围 
		//第一个特征区域的纵坐标大于原图高度的一半 
		if(lpbi->biHeight/2 < ImportantPoint.y) 
		{ 
		    //设定考察的两个纵坐标位置 
			height2 = lpbi->biHeight/2; 
			height1 = 0; 
		} 
		else//第一个特征区域的坐标小于等于原图高度的一半 
		{   //设定纵坐标位置 
			height2 = lpbi->biHeight; 
			height1 = lpbi->biHeight/2; 
		} 
		//如果第一个特征区域的横坐标大于原来图片的一半 
		if(lpbi->biWidth/2 < ImportantPoint.x) 
		{  //设定考察区域横坐标的两个值 
			width1 = 0; 
			width2 = lpbi->biWidth/2; 
		} 
		else //第一个特征区域的横坐标小于等于原来图片的一半 
		{  //设定考察区域的横坐标的两个值 
			width1 = lpbi->biWidth/2; 
			width2 = lpbi->biWidth; 
		} 
		 
	lpData = m_Dib.FindDIBBits(hDIBBK1); 
	//得到每行象素的字节数 
	wBytesPerLine = m_Dib.BytePerLine(hDIBBK1); 
	int tempsum=0,sum=0; 
	long lOffset; 
	//在设定的区域内部查找第二个特征区域 
	for(int i=height1+RADIUS;isum)//当前区域特征更明显 
				{ 
					sum = tempsum; 
					//设定区域中心点坐标 
					ImportantPointSecond.x = j; 
					ImportantPointSecond.y = i; 
								 
 
				} 
		} 
		GlobalUnlock(hDIBBK1); 
   //按照新找到的特征区域,再次匹配中心点 
	bool kk = m_Dib.MatchImportantPoint(hDIBCurrent,ImportantColorInfo,&ImportantPoint2); 
	//比较图片的相似度 
	if(m_Dib.ComPareImg(hDIBBK1,hDIBCurrent,ImportantPoint,ImportantPoint2)) 
		AfxMessageBox("match successed"); 
	else 
		AfxMessageBox("match failed"); 
		 
	Invalidate(); 
	 
} 
 
void CImageproView::OnMenuShowobject()  
{ 
	// TODO: Add your command handler code here 
    m_Dib.CompareImg2(hDIBBK1,hDIBCurrent,ImportantPoint,ImportantPoint2); 
	LPBITMAPFILEHEADER lpbi; 
	lpbi = (LPBITMAPFILEHEADER)GlobalLock(hDIBCurrent); 
	LPBYTE lpData = m_Dib.FindDIBBits(hDIBCurrent); 
	long lOffset; 
	WORD wBytesPerLine = m_Dib.BytePerLine(hDIBCurrent); 
	 
	for(int i= -RADIUS;i<=RADIUS;i++) 
		{ 
			lOffset = m_Dib.PixelOffset(i+ImportantPoint2.y,RADIUS+ImportantPoint2.x,wBytesPerLine); 
			*(lpData+lOffset++) = 0; 
			*(lpData+lOffset++) = 0; 
			*(lpData+lOffset++) = 0; 
		} 
	for( i= -RADIUS;i<=RADIUS;i++) 
		{ 
			lOffset = m_Dib.PixelOffset(i+ImportantPoint2.y,ImportantPoint2.x-RADIUS,wBytesPerLine); 
			*(lpData+lOffset++) = 0; 
			*(lpData+lOffset++) = 0; 
			*(lpData+lOffset++) = 0; 
		} 
	for( i= -RADIUS;i<=RADIUS;i++) 
		{ 
			lOffset = m_Dib.PixelOffset(ImportantPoint2.y-RADIUS,i+ImportantPoint2.x,wBytesPerLine); 
			*(lpData+lOffset++) = 0; 
			*(lpData+lOffset++) = 0; 
			*(lpData+lOffset++) = 0; 
		} 
	for( i= -RADIUS;i<=RADIUS;i++) 
		{ 
			lOffset = m_Dib.PixelOffset(RADIUS+ImportantPoint2.y,i+ImportantPoint2.x,wBytesPerLine); 
			*(lpData+lOffset++) = 0; 
			*(lpData+lOffset++) = 0; 
			*(lpData+lOffset++) = 0; 
		} 
	GlobalUnlock(hDIBCurrent); 
	Invalidate(); 
	 
}