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

📄 dipdoc.cpp

📁 用C++实现的数字图像处理各个算法源代码 我精心整理的 很难的啊 希望可以给大家带来帮助
💻 CPP
📖 第 1 页 / 共 3 页
字号:

void CDipDoc::OnUpdateChannelGreen(CCmdUI* pCmdUI) 
{
	pCmdUI->Enable(m_pDibObject->GetNumBits() >= 8);
}

void CDipDoc::OnUpdateChannelMixed(CCmdUI* pCmdUI) 
{
	pCmdUI->Enable(m_pDibObject->GetNumBits() >= 8);
}

void CDipDoc::OnUpdateChannelRed(CCmdUI* pCmdUI) 
{
	pCmdUI->Enable(m_pDibObject->GetNumBits() >= 8);
}

void CDipDoc::OnUpdateChannelBlue(CCmdUI* pCmdUI) 
{
	pCmdUI->Enable(m_pDibObject->GetNumBits() >= 8);
}

void CDipDoc::OnUpdateChannelSplit(CCmdUI* pCmdUI) 
{
	pCmdUI->Enable(m_pDibObject->GetNumBits() >= 8);
}

void CDipDoc::OnUpdatePointThre(CCmdUI* pCmdUI) 
{
	//判断当前是否有图像对象
	if( m_pDibObject == NULL ) return;
	
	//在点处理CPointPro类中创建用来绘制直方图的数据
	CPointPro PointOperation( m_pDibObject );

	//判断是否为256色灰度图像
	pCmdUI->Enable(PointOperation.IsGray256());
}

void CDipDoc::OnUpdatePointPseudocolor(CCmdUI* pCmdUI) 
{
	//判断当前是否有图像对象
	if( m_pDibObject == NULL ) return;
	
	//在点处理CPointPro类中创建用来绘制直方图的数据
	CPointPro PointOperation( m_pDibObject );

	//判断是否为256色灰度图像
	pCmdUI->Enable(PointOperation.IsGray256());
}
void CDipDoc::OnDetectProject() 
{
	//创建投影模式选择对话框
	CDlgProject projectmode;
	if(projectmode.DoModal() == IDOK)
	{
		//创建点处理CPointPro类对象
		CAreaPro AreaPro( m_pDibObject );
		// 更改光标形状
		BeginWaitCursor();
		//选择投影模式
		if(projectmode.m_iProjectMode == 0)
			AreaPro.ProjectH();
		else
			AreaPro.ProjectV();
		// 恢复光标
		EndWaitCursor();
		
		// 更新视图
		UpdateAllViews(NULL);
	}
}

void CDipDoc::OnUpdateDetectProject(CCmdUI* pCmdUI) 
{
	//创建点处理CPointPro类对象
	CPointPro PointOperation( m_pDibObject );
	//只对8位二值图像起作用
	pCmdUI->Enable(PointOperation.IsBlackandWhite256());
}

void CDipDoc::OnEdgeFill() 
{
	//创建种子填充方式选择对话框
	CDlgSeedFill seedfill;
	if(seedfill.DoModal() == IDOK)
	{
		//创建点处理CPointPro类对象
		CAreaPro AreaPro( m_pDibObject );
		// 更改光标形状
		BeginWaitCursor();
		//选择种子填充方法
		if(seedfill.m_iSeedMethod == 0)
			AreaPro.Feeding1();
		else
			AreaPro.Feeding2();
		// 恢复光标
		EndWaitCursor();
		
		// 更新视图
		UpdateAllViews(NULL);
	}
}

void CDipDoc::OnUpdateEdgeFill(CCmdUI* pCmdUI) 
{
	//创建点处理CPointPro类对象
	CPointPro PointOperation( m_pDibObject );
	//只对8位二值图像起作用
	pCmdUI->Enable(PointOperation.IsBlackandWhite256());
}

void CDipDoc::OnDetectTemplate() 
{
	CDibObject *pTemplate;
	static int nIndex = 1;

	CFileDialog FileDlg( TRUE, NULL, NULL, OFN_HIDEREADONLY, szFilter );
	FileDlg.m_ofn.nFilterIndex = (DWORD) nIndex;

	if( FileDlg.DoModal() == IDOK )
	{
		CString strPathName = FileDlg.GetPathName();
		nIndex = (int) FileDlg.m_ofn.nFilterIndex;

		//设置等待光标
		BeginWaitCursor();

		pTemplate = new CDibObject( strPathName.GetBuffer(3) );

		//取消等待光标
		EndWaitCursor();

		//读入图像文件失败
		if( pTemplate == NULL )
		{
			AfxMessageBox("无法创建匹配模板图像类对象!");
			//返回FALSE
			return;
		}

		//在点处理CPointPro类中创建用来绘制直方图的数据
		CPointPro PointOperation( pTemplate );
		
		//判断是否为256色灰度图像
		if(!PointOperation.IsGray256())
		{
			AfxMessageBox("匹配模板图像不是256级灰度图像,无法进行操作!");
			//返回FALSE
			return;
		}

		//原始图像大小
		int nOldWidth = m_pDibObject->GetWidth();
		int nOldHeight = m_pDibObject->GetHeight();
		
		//模板图像大小
		int nTempWidth = pTemplate->GetWidth();
		int nTempHeight = pTemplate->GetHeight();
		
		//两个图像的大小应一致
		if (nTempWidth > nOldWidth || nTempHeight > nOldHeight)
		{
			AfxMessageBox("模板图像太大,无法完成操作!");
			return;
		}

		//创建点处理CPointPro类对象
		CAreaPro AreaPro( m_pDibObject );
		// 更改光标形状
		BeginWaitCursor();
		
		AreaPro.TemplateMatch(pTemplate);
		
		// 恢复光标
		EndWaitCursor();
		
		// 更新视图
		UpdateAllViews(NULL);
	}	
}

void CDipDoc::OnUpdateDetectTemplate(CCmdUI* pCmdUI) 
{
	//判断当前是否有图像对象
	if( m_pDibObject == NULL ) return;
	
	//在点处理CPointPro类中创建用来绘制直方图的数据
	CPointPro PointOperation( m_pDibObject );

	//判断是否为256色灰度图像
	pCmdUI->Enable(PointOperation.IsGray256());
}

void CDipDoc::OnEdgeTrace() 
{
	//创建点处理CPointPro类对象
	CAreaPro AreaPro( m_pDibObject );
	// 更改光标形状
	BeginWaitCursor();

	AreaPro.EdgeTracing();

	// 恢复光标
	EndWaitCursor();
	
	// 更新视图
	UpdateAllViews(NULL);
}

void CDipDoc::OnUpdateEdgeTrace(CCmdUI* pCmdUI) 
{
	//创建点处理CPointPro类对象
	CPointPro PointOperation( m_pDibObject );	
	pCmdUI->Enable(PointOperation.IsBlackandWhite256());
}

void CDipDoc::OnEdgeContour() 
{
	//创建点处理CPointPro类对象
	CAreaPro AreaPro( m_pDibObject );
	// 更改光标形状
	BeginWaitCursor();

	AreaPro.ContourPickUp();

	// 恢复光标
	EndWaitCursor();
	
	// 更新视图
	UpdateAllViews(NULL);
}

void CDipDoc::OnUpdateEdgeContour(CCmdUI* pCmdUI) 
{
	//创建点处理CPointPro类对象
	CPointPro PointOperation( m_pDibObject );	
	pCmdUI->Enable(PointOperation.IsBlackandWhite256());
}

void CDipDoc::OnDetectMinus() 
{
	//模板图像数据指针
	unsigned char *pBitsTemp;

	static int nIndex = 1;

	CFileDialog FileDlg( TRUE, NULL, NULL, OFN_HIDEREADONLY, szFilter );
	FileDlg.m_ofn.nFilterIndex = (DWORD) nIndex;

	if( FileDlg.DoModal() == IDOK )
	{
		CString strPathName = FileDlg.GetPathName();
		nIndex = (int) FileDlg.m_ofn.nFilterIndex;

		//设置等待光标
		BeginWaitCursor();

		CDibObject *pTemplate = new CDibObject( strPathName.GetBuffer(3) );

		//取消等待光标
		EndWaitCursor();

		//读入图像文件失败
		if( pTemplate == NULL )
		{
			AfxMessageBox("无法创建差影模板图像类对象!");
			//返回FALSE
			return;
		}

		//在点处理CPointPro类中创建用来绘制直方图的数据
		CPointPro PointOperation( pTemplate );
		
		//判断是否为256色灰度图像
		if(!PointOperation.IsGray256())
		{
			AfxMessageBox("差影模板图像不是256级灰度图像,无法进行操作!");
			//返回FALSE
			return;
		}

		//原始图像大小
		int nOldWidth = m_pDibObject->GetWidth();
		int nOldHeight = m_pDibObject->GetHeight();
		
		//模板图像大小
		int nTempWidth = pTemplate->GetWidth();
		int nTempHeight = pTemplate->GetHeight();
		
		CRect rectOld(0, 0, nOldWidth, nOldHeight);
		CRect rectTemp(0, 0, nTempWidth, nTempHeight);
		
		//两个图像的大小应一致
		if (rectOld != rectTemp)
		{
			AfxMessageBox("模板图像和原图像大小不一致,无法完成操作!");
			return;
		}

		//创建点处理CPointPro类对象
		CAreaPro AreaPro1( pTemplate );
		// 更改光标形状
		BeginWaitCursor();
		
		pBitsTemp = AreaPro1.GetBitsPointer();
		
		// 恢复光标
		EndWaitCursor();

		//创建点处理CPointPro类对象
		CAreaPro AreaPro2( m_pDibObject );

		// 更改光标形状
		BeginWaitCursor();
		
		AreaPro2.Minusing(pBitsTemp);
		
		// 恢复光标
		EndWaitCursor();
		
		// 更新视图
		UpdateAllViews(NULL);
		
	}
}

void CDipDoc::OnUpdateDetectMinus(CCmdUI* pCmdUI) 
{
	//判断当前是否有图像对象
	if( m_pDibObject == NULL ) return;
	
	//在点处理CPointPro类中创建用来绘制直方图的数据
	CPointPro PointOperation( m_pDibObject );

	//判断是否为256色灰度图像
	pCmdUI->Enable(PointOperation.IsGray256());
}

void CDipDoc::OnGeomMirh() 
{
	//创建点处理CImageGeoTrans类对象
	CGeoTrans GeoTrans( m_pDibObject );

	// 更改光标形状
	BeginWaitCursor();

	//调用Mirror()函数进行垂直镜像
	GeoTrans.Mirror(TRUE);

	// 设置脏标记
	//	SetModifiedFlag(TRUE);

	// 更新视图
	UpdateAllViews(NULL);
	
	// 恢复光标
	EndWaitCursor();
}

void CDipDoc::OnGeomMirv() 
{
	//创建点处理CImageGeoTrans类对象
	CGeoTrans GeoTrans( m_pDibObject );

	// 更改光标形状
	BeginWaitCursor();

	//调用Mirror()函数进行水平镜像
	GeoTrans.Mirror(FALSE);

	// 设置脏标记
	//	SetModifiedFlag(TRUE);

	// 更新视图
	UpdateAllViews(NULL);
	
	// 恢复光标
	EndWaitCursor();
}

void CDipDoc::OnGeomRota() 
{
	//旋转角度
	int nRotateAngle;
	int nIntorType;
	BOOL bIntorType;
	
	//创建对话框
	CDlgGeoRota dlgPara;
	
	//初始化变量值
	dlgPara.m_iRotateAngle = 90;
	dlgPara.m_nIntorType = 0;
	
	//显示对话框,提示用户设定旋转角度
	if(dlgPara.DoModal() != IDOK)
	{
		//返回
		return;
	}
	
	//获取用户设定的角度
	nRotateAngle = dlgPara.m_iRotateAngle;
	nIntorType = dlgPara.m_nIntorType;
	
	//删除对话框
	delete dlgPara;	

	if(nIntorType == 0)
	{
		bIntorType = FALSE;
	}
	else
	{
		bIntorType = TRUE;
	}

	//创建点处理CImageGeoTrans类对象
	CGeoTrans GeoTrans( m_pDibObject );

	// 更改光标形状
	BeginWaitCursor();

	//调用Mirror()函数进行垂直镜像
	GeoTrans.Rotate(nRotateAngle, bIntorType);

	// 设置脏标记
	//	SetModifiedFlag(TRUE);
	
	// 更新视图
	UpdateAllViews(NULL);
	
	// 恢复光标
	EndWaitCursor();
}

void CDipDoc::OnGeomTran() 
{
	// 创建对话框
	CDlgGeoTran dlgPara;
	
	// 初始化变量值
	dlgPara.m_XOffset = 0;
	dlgPara.m_YOffset = 0;
	dlgPara.m_nTransType = 0;
	
	// 显示对话框,提示用户设定平移量
	if (dlgPara.DoModal() != IDOK)
	{
		// 返回
		return;
	}
	
	// 获取用户设定的平移量
	LONG lXOffset = dlgPara.m_XOffset;
	LONG lYOffset = dlgPara.m_YOffset;
	int nTransType = dlgPara.m_nTransType;
	// 删除对话框
	delete dlgPara;	
	
	//创建点处理CImageGeoTrans类对象
	CGeoTrans GeoTrans( m_pDibObject );

	// 更改光标形状
	BeginWaitCursor();

	if(nTransType == 0)
	{
		// 调用TranslationPixel()函数进行平移
		GeoTrans.TranslationPixel(lXOffset, lYOffset);
	}
	else if(nTransType == 1)
	{
		// 调用TranslationLine()函数进行平移
		GeoTrans.TranslationLine(lXOffset, lYOffset);
	}

	// 设置脏标记
	//	SetModifiedFlag(TRUE);

	// 更新视图
	UpdateAllViews(NULL);
	
	// 恢复光标
	EndWaitCursor();
}

void CDipDoc::OnGeomTrpo() 
{
	//创建点处理CImageGeoTrans类对象
	CGeoTrans GeoTrans( m_pDibObject );

	// 更改光标形状
	BeginWaitCursor();

	//调用Mirror()函数进行垂直镜像
	GeoTrans.Transpose();

	// 设置脏标记
	//	SetModifiedFlag(TRUE);

	// 更新视图
	UpdateAllViews(NULL);
	
	// 恢复光标
	EndWaitCursor();
}

void CDipDoc::OnGeomZoom() 
{
// 缩放比率
	float fXZoomRatio;
	float fYZoomRatio;
	int nIntorType;
	BOOL bIntorType;
	
	// 创建对话框
	CDlgGeoZoom dlgPara;
	
	// 初始化变量值
	dlgPara.m_XZoom = 4.0;
	dlgPara.m_YZoom = 4.0;
	dlgPara.m_nIntorType = 0;
	
	// 显示对话框,提示用户设定平移量
	if (dlgPara.DoModal() != IDOK)
	{
		// 返回
		return;
	}
	
	// 获取用户设定的平移量
	fXZoomRatio = dlgPara.m_XZoom;
	fYZoomRatio = dlgPara.m_YZoom;
	nIntorType = dlgPara.m_nIntorType;
	
	// 删除对话框
	delete dlgPara;	
	
	if(nIntorType == 0)
	{
		bIntorType = FALSE;
	}
	else
	{
		bIntorType = TRUE;
	}
	
	//创建点处理CImageGeoTrans类对象
	CGeoTrans GeoTrans( m_pDibObject );

	// 更改光标形状
	BeginWaitCursor();
	
	//调用Mirror()函数进行垂直镜像
	GeoTrans.ZoomImage(fXZoomRatio, fYZoomRatio, bIntorType);
	
	// 设置脏标记
	//	SetModifiedFlag(TRUE);
	
	// 更新视图
	UpdateAllViews(NULL);
	
	// 恢复光标
	EndWaitCursor();
}

//以下六个命令更新消息映射,保证图像几何变换只对8位以上的图像进行操作。
void CDipDoc::OnUpdateGeomMirh(CCmdUI* pCmdUI) 
{
	pCmdUI->Enable(m_pDibObject->GetNumBits() >= 8);
}

void CDipDoc::OnUpdateGeomMirv(CCmdUI* pCmdUI) 
{
	pCmdUI->Enable(m_pDibObject->GetNumBits() >= 8);
}

void CDipDoc::OnUpdateGeomRota(CCmdUI* pCmdUI) 
{
	pCmdUI->Enable(m_pDibObject->GetNumBits() >= 8);
}

void CDipDoc::OnUpdateGeomTran(CCmdUI* pCmdUI) 
{
	pCmdUI->Enable(m_pDibObject->GetNumBits() >= 8);
}

void CDipDoc::OnUpdateGeomTrpo(CCmdUI* pCmdUI) 
{
	pCmdUI->Enable(m_pDibObject->GetNumBits() >= 8);
}

void CDipDoc::OnUpdateGeomZoom(CCmdUI* pCmdUI) 
{
	pCmdUI->Enable(m_pDibObject->GetNumBits() >= 8);
}

⌨️ 快捷键说明

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