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

📄 linjunjuandoc.cpp

📁 图像处理软件,功能比较基础
💻 CPP
📖 第 1 页 / 共 5 页
字号:

	// 指向DIB象素指针
	LPSTR   lpDIBBits;
	
	// 锁定DIB
	lpDIB = (LPSTR) ::GlobalLock((HGLOBAL) ChangeToHDIB(orgpic));
	
	// 判断是否是8-bpp位图(这里为了方便,只处理8-bpp位图的腐蚀,其它的可以类推)
	if (::DIBNumColors(lpDIB) != 256)
	{
		// 提示用户
		AfxMessageBox("目前只支持256色位图的腐蚀!", /*"系统提示" ,*/ MB_ICONINFORMATION | MB_OK);

		// 解除锁定
		::GlobalUnlock((HGLOBAL)ChangeToHDIB(orgpic));
		
		// 返回
		return;
	}
	
	
	// 更改光标形状
	BeginWaitCursor();

	// 找到DIB图像象素起始位置
	lpDIBBits = ::FindDIBBits(lpDIB);
	int bmpWidth=WIDTHBYTES(::DIBWidth(lpDIB) * 8);
	
	// 调用ErosionDIB()函数腐蚀DIB
	if (ContourDIB(lpDIBBits, WIDTHBYTES(::DIBWidth(lpDIB) * 8), ::DIBHeight(lpDIB)))
	{
		
		// 设置脏标记
		for (int i=dealpic.row-1;i>=0;i--)
			for (int j=0;j<dealpic.col;j++)
			{
				dealpic.p[dealpic.row-i-1][j]=*(lpDIBBits+i*bmpWidth+j);
			}
		
		// 更新视图
			dspace_2d(orgpic.p,orgpic.row,orgpic.col);
			orgpic=dealpic;
			if ((m_hDIB=ChangeToHDIB(dealpic))==NULL)
			{
				AfxMessageBox("不能显示!");		
				return ;
			}
			SaveHistory();
			InitDIBData();
			UpdateAllViews(NULL);
		
	}
	else
	{
		// 提示用户
		AfxMessageBox("分配内存失败或者图像中含有0和255之外的像素值!",/* "系统提示" , */MB_ICONINFORMATION | MB_OK);
	}
	
	// 解除锁定
	::GlobalUnlock((HGLOBAL) ChangeToHDIB(orgpic));

	// 恢复光标
	EndWaitCursor();
	
}

void CLinjunjuanDoc::OnEdgeFill2() 
{
			//腐蚀运算

	// 获取文档
	if (!flagpic)
	{
		AfxMessageBox("没有输入图象!");
		return;
	}
		dealpic.row=orgpic.row;
		dealpic.col=orgpic.col;
		if (!(dealpic.p=fspace_2d(dealpic.row,dealpic.col)))
		{
			AfxMessageBox("分配空间错误!");
			return;
		}

	
	// 指向DIB的指针
	LPSTR	lpDIB;

	// 指向DIB象素指针
	LPSTR   lpDIBBits;
	
	// 锁定DIB
	lpDIB = (LPSTR) ::GlobalLock((HGLOBAL) ChangeToHDIB(orgpic));
	
	// 判断是否是8-bpp位图(这里为了方便,只处理8-bpp位图的腐蚀,其它的可以类推)
	if (::DIBNumColors(lpDIB) != 256)
	{
		// 提示用户
		AfxMessageBox("目前只支持256色位图的腐蚀!", /*"系统提示" ,*/ MB_ICONINFORMATION | MB_OK);

		// 解除锁定
		::GlobalUnlock((HGLOBAL)ChangeToHDIB(orgpic));
		
		// 返回
		return;
	}
	
	
	// 更改光标形状
	BeginWaitCursor();

	// 找到DIB图像象素起始位置
	lpDIBBits = ::FindDIBBits(lpDIB);
	int bmpWidth=WIDTHBYTES(::DIBWidth(lpDIB) * 8);
	
	// 调用ErosionDIB()函数腐蚀DIB
	if (Fill2DIB(lpDIBBits, WIDTHBYTES(::DIBWidth(lpDIB) * 8), ::DIBHeight(lpDIB)))
	{
		
		// 设置脏标记
		for (int i=dealpic.row-1;i>=0;i--)
			for (int j=0;j<dealpic.col;j++)
			{
				dealpic.p[dealpic.row-i-1][j]=*(lpDIBBits+i*bmpWidth+j);
			}
		
		// 更新视图
			dspace_2d(orgpic.p,orgpic.row,orgpic.col);
			orgpic=dealpic;
			if ((m_hDIB=ChangeToHDIB(dealpic))==NULL)
			{
				AfxMessageBox("不能显示!");		
				return ;
			}
			SaveHistory();
			InitDIBData();
			UpdateAllViews(NULL);
		
	}
	else
	{
		// 提示用户
		AfxMessageBox("分配内存失败或者图像中含有0和255之外的像素值!",/* "系统提示" , */MB_ICONINFORMATION | MB_OK);
	}
	
	// 解除锁定
	::GlobalUnlock((HGLOBAL) ChangeToHDIB(orgpic));

	// 恢复光标
	EndWaitCursor();
	
	
}

void CLinjunjuanDoc::OnEdgeFill() 
{			//腐蚀运算

	// 获取文档
	if (!flagpic)
	{
		AfxMessageBox("没有输入图象!");
		return;
	}
		dealpic.row=orgpic.row;
		dealpic.col=orgpic.col;
		if (!(dealpic.p=fspace_2d(dealpic.row,dealpic.col)))
		{
			AfxMessageBox("分配空间错误!");
			return;
		}

	
	// 指向DIB的指针
	LPSTR	lpDIB;

	// 指向DIB象素指针
	LPSTR   lpDIBBits;
	
	// 锁定DIB
	lpDIB = (LPSTR) ::GlobalLock((HGLOBAL) ChangeToHDIB(orgpic));
	
	// 判断是否是8-bpp位图(这里为了方便,只处理8-bpp位图的腐蚀,其它的可以类推)
	if (::DIBNumColors(lpDIB) != 256)
	{
		// 提示用户
		AfxMessageBox("目前只支持256色位图的腐蚀!", /*"系统提示" ,*/ MB_ICONINFORMATION | MB_OK);

		// 解除锁定
		::GlobalUnlock((HGLOBAL)ChangeToHDIB(orgpic));
		
		// 返回
		return;
	}
	
	
	// 更改光标形状
	BeginWaitCursor();

	// 找到DIB图像象素起始位置
	lpDIBBits = ::FindDIBBits(lpDIB);
	int bmpWidth=WIDTHBYTES(::DIBWidth(lpDIB) * 8);
	
	// 调用ErosionDIB()函数腐蚀DIB
	if (FillDIB(lpDIBBits, WIDTHBYTES(::DIBWidth(lpDIB) * 8), ::DIBHeight(lpDIB)))
	{
		
		// 设置脏标记
		for (int i=dealpic.row-1;i>=0;i--)
			for (int j=0;j<dealpic.col;j++)
			{
				dealpic.p[dealpic.row-i-1][j]=*(lpDIBBits+i*bmpWidth+j);
			}
		
		// 更新视图
			dspace_2d(orgpic.p,orgpic.row,orgpic.col);
			orgpic=dealpic;
			if ((m_hDIB=ChangeToHDIB(dealpic))==NULL)
			{
				AfxMessageBox("不能显示!");		
				return ;
			}
			SaveHistory();
			InitDIBData();
			UpdateAllViews(NULL);
		
	}
	else
	{
		// 提示用户
		AfxMessageBox("分配内存失败或者图像中含有0和255之外的像素值!",/* "系统提示" , */MB_ICONINFORMATION | MB_OK);
	}
	
	// 解除锁定
	::GlobalUnlock((HGLOBAL) ChangeToHDIB(orgpic));

	// 恢复光标
	EndWaitCursor();
}

void CLinjunjuanDoc::OnMathAnd() 
{
	unsigned char ** anotherImg=NULL;
	int anotherRow,anotherCol;
   
	MessageBox(NULL,"请输入另一幅图象!","逻辑与",MB_OK);

	if (!orgpic.p)
		return;
	char ext[] = "picture types (*.bmp)|*.bmp|picture types (*.pic)|*.pic||";
	CFileDialog dlg(TRUE,"bmp" ,"*.bmp",OFN_OVERWRITEPROMPT|OFN_FILEMUSTEXIST|OFN_HIDEREADONLY ,ext, NULL);
	if(dlg.DoModal() == IDOK)
	{		
		anotherImg=InputImageWithName(dlg.GetPathName(),anotherRow ,anotherCol);	
		if ((anotherRow!=orgpic.row)||(anotherCol!=orgpic.col))
		{
			MessageBox(NULL,"输入图象与原图大小不符!","Error",MB_OK);
			dspace_2d(anotherImg,anotherRow,anotherCol);
			anotherImg=NULL;
		}else
		{
			dealpic.row=orgpic.row;
			dealpic.col=orgpic.col;
			if (!(dealpic.p=fspace_2d(dealpic.row,dealpic.col)))
			{
				AfxMessageBox("分配空间错误!");
				return;
			}
			for (int i=0;i<dealpic.row;i++)
				for (int j=0;j<dealpic.col;j++)
				{
					if (orgpic.p[i][j]==255)
					{
						dealpic.p[i][j]=128;
					}
					else
						dealpic.p[i][j]=anotherImg[i][j];
				}				
			dspace_2d(orgpic.p,orgpic.row,orgpic.col);
			dspace_2d(anotherImg,anotherRow,anotherCol);
			orgpic=dealpic;
			if ((m_hDIB=ChangeToHDIB(dealpic))==NULL)
			{
				AfxMessageBox("不能显示!");		
				return ;
			}
			SaveHistory();
			InitDIBData();
			UpdateAllViews(NULL);
		}

	}
	else return ;
	
	
}

void CLinjunjuanDoc::OnMathNot() 
{
	unsigned char ** anotherImg=NULL;
	int anotherRow,anotherCol;
   
	MessageBox(NULL,"请输入另一幅图象!","逻辑非",MB_OK);

	if (!orgpic.p)
		return;
	char ext[] = "picture types (*.bmp)|*.bmp|picture types (*.pic)|*.pic||";
	CFileDialog dlg(TRUE,"bmp" ,"*.bmp",OFN_OVERWRITEPROMPT|OFN_FILEMUSTEXIST|OFN_HIDEREADONLY ,ext, NULL);
	if(dlg.DoModal() == IDOK)
	{		
		anotherImg=InputImageWithName(dlg.GetPathName(),anotherRow ,anotherCol);	
		if ((anotherRow!=orgpic.row)||(anotherCol!=orgpic.col))
		{
			MessageBox(NULL,"输入图象与原图大小不符!","Error",MB_OK);
			dspace_2d(anotherImg,anotherRow,anotherCol);
			anotherImg=NULL;
		}else
		{
			dealpic.row=orgpic.row;
			dealpic.col=orgpic.col;
			if (!(dealpic.p=fspace_2d(dealpic.row,dealpic.col)))
			{
				AfxMessageBox("分配空间错误!");
				return;
			}
			for (int i=0;i<dealpic.row;i++)
				for (int j=0;j<dealpic.col;j++)
				{
			//		dealpic.p[i][j]=
				}
				
			dspace_2d(orgpic.p,orgpic.row,orgpic.col);
			dspace_2d(anotherImg,anotherRow,anotherCol);
			orgpic=dealpic;
			if ((m_hDIB=ChangeToHDIB(dealpic))==NULL)
			{
				AfxMessageBox("不能显示!");		
				return ;
			}
			SaveHistory();
			InitDIBData();
			UpdateAllViews(NULL);
		}

	}
	else return ;
	
}

void CLinjunjuanDoc::OnMathOr() 
{
	unsigned char ** anotherImg=NULL;
	int anotherRow,anotherCol;
   
	MessageBox(NULL,"请输入另一幅图象!","逻辑或",MB_OK);

	if (!orgpic.p)
		return;
	char ext[] = "picture types (*.bmp)|*.bmp|picture types (*.pic)|*.pic||";
	CFileDialog dlg(TRUE,"bmp" ,"*.bmp",OFN_OVERWRITEPROMPT|OFN_FILEMUSTEXIST|OFN_HIDEREADONLY ,ext, NULL);
	if(dlg.DoModal() == IDOK)
	{		
		anotherImg=InputImageWithName(dlg.GetPathName(),anotherRow ,anotherCol);	
		if ((anotherRow!=orgpic.row)||(anotherCol!=orgpic.col))
		{
			MessageBox(NULL,"输入图象与原图大小不符!","Error",MB_OK);
			dspace_2d(anotherImg,anotherRow,anotherCol);
			anotherImg=NULL;
		}else
		{
			dealpic.row=orgpic.row;
			dealpic.col=orgpic.col;
			if (!(dealpic.p=fspace_2d(dealpic.row,dealpic.col)))
			{
				AfxMessageBox("分配空间错误!");
				return;
			}
			for (int i=0;i<dealpic.row;i++)
				for (int j=0;j<dealpic.col;j++)
				{
			//		dealpic.p[i][j]=
				}
				
			dspace_2d(orgpic.p,orgpic.row,orgpic.col);
			dspace_2d(anotherImg,anotherRow,anotherCol);
			orgpic=dealpic;
			if ((m_hDIB=ChangeToHDIB(dealpic))==NULL)
			{
				AfxMessageBox("不能显示!");		
				return ;
			}
			SaveHistory();
			InitDIBData();
			UpdateAllViews(NULL);
		}

	}
	else return ;
}

void CLinjunjuanDoc::OnMathXor() 
{
	unsigned char ** anotherImg=NULL;
	int anotherRow,anotherCol;
   
	MessageBox(NULL,"请输入另一幅图象!","异或",MB_OK);

	if (!orgpic.p)
		return;
	char ext[] = "picture types (*.bmp)|*.bmp|picture types (*.pic)|*.pic||";
	CFileDialog dlg(TRUE,"bmp" ,"*.bmp",OFN_OVERWRITEPROMPT|OFN_FILEMUSTEXIST|OFN_HIDEREADONLY ,ext, NULL);
	if(dlg.DoModal() == IDOK)
	{		
		anotherImg=InputImageWithName(dlg.GetPathName(),anotherRow ,anotherCol);	
		if ((anotherRow!=orgpic.row)||(anotherCol!=orgpic.col))
		{
			MessageBox(NULL,"输入图象与原图大小不符!","Error",MB_OK);
			dspace_2d(anotherImg,anotherRow,anotherCol);
			anotherImg=NULL;
		}else
		{
			dealpic.row=orgpic.row;
			dealpic.col=orgpic.col;
			if (!(dealpic.p=fspace_2d(dealpic.row,dealpic.col)))
			{
				AfxMessageBox("分配空间错误!");
				return;
			}
			for (int i=0;i<dealpic.row;i++)
				for (int j=0;j<dealpic.col;j++)
				{
					if (orgpic.p[i][j]==anotherImg[i][j]&&anotherImg[i][j]==0)
						dealpic.p[i][j]=255;
					else
						dealpic.p[i][j]=orgpic.p[i][j];
				}
				
			dspace_2d(orgpic.p,orgpic.row,orgpic.col);
			dspace_2d(anotherImg,anotherRow,anotherCol);
			orgpic=dealpic;
			if ((m_hDIB=ChangeToHDIB(dealpic))==NULL)
			{
				AfxMessageBox("不能显示!");		
				return ;
			}
			SaveHistory();
			InitDIBData();
			UpdateAllViews(NULL);
		}

	}
	else return ;
	
}

void CLinjunjuanDoc::OnExtraDigimg() 
{
	if (!flagpic)
	{
		AfxMessageBox("没有输入图象!");
		return;
	}
	char fileName[]="d:\\pic\\11.000";
	DigRectImage(orgpic,fileName);

	
}



void CLinjunjuanDoc::OnProcess() 
{
	RadonResult *result=NULL;
	int rect_num;
	int theta=20;
	if (!flagpic)
	{
		AfxMessageBox("没有输入图象!");
		return;
	}	
	
	result=RandonPic(orgpic.p,orgpic.row,orgpic.col,theta,rect_num);
	int truetheta=160;
	unsigned char **input=NULL;
	int Row,Col;
	CString FileName="d:\\pic\\11.000";
	input=InputImageWithName(FileName,Row,Col);
	int newrect_length=40;
	ResultPoint resultpoint=RandonPic_sin(input,Row,Col,result[0].theta,result[0].coordinatex,result[0].centre_x,result[0].centre_y,newrect_length,truetheta);
	POINT firstpoint,endpoint;
	firstpoint.x=result[0].centre_y-result[0].rect_length/2+resultpoint.first.x;
	firstpoint.y=result[0].centre_x-result[0].rect_length/2+resultpoint.first.y;
	endpoint.x=result[0].centre_y-result[0].rect_length/2+resultpoint.end.x;
	endpoint.y=result[0].centre_x-result[0].rect_length/2+resultpoint.end.y;
	unsigned char **input1=NULL;
	int Row1,Col1;
	CString FileName1="d:\\pic\\sar\\5.bmp";
	CString FileName11="d:\\pic\\sar\\5_5.bmp";
	input1=InputImageWithName(FileName1,Row1,Col1);
	for (int i=0;i<3;i++)
		for (int j=0;j<3;j++)
		{
			//input1[firstpoint.y-1+i][firstpoint.x-1+j]=255;
			input1[endpoint.y-1+i][endpoint.x-1+j]=255;
		}
		OutputImageWithName(input1,Row1,Col1,FileName11);
		dspace_2d(input1,Row1,Col1);
		dspace_2d(input,Row,Col);


	/*
	
	

	int min=10;
	int tempi;
	Picture outpic;
	outpic.p = fspace_2d(500,500);
	for (int f=0;f<500;f++)
		for (int j=0;j<500;j++)
		{
			outpic.p[f][j]=0;
		}
	for (int i=0;i<rect_num;i++)
	{/*
		int temp;
		temp=abs(result[i].theta-truetheta);
		if(temp<min)
		{
			min=temp;
			tempi=i;
		}
	}
	*//*
		int temp;
		temp=abs(result[i].theta-truetheta);
		if(temp<3)
			tempi=i;
		else 
			continue;	


    int row,col;
	row=col=500;
	int rowx,colx;
	double ta;
	int centre_x,centre_y,rect_length;
	centre_x=result[tempi].centre_x;
	centre_y=result[tempi].centre_y;
	rect_length=result[tempi].rect_length;
	int left_toppointx=centre_x-rect_length/2;
	int left_toppointy=centre_y-rect_length/2;
    
	ta=PI*(result[tempi].theta)/180.0;
	int rhoMax=(int)(sqrt((rect_length)*(rect_length)*2));
	int max_rhoMaxnum=(int)(result[tempi].coordinatex-(rhoMax)/2);
	if (ta<0.0001&&ta>-0.0001)
	{
		colx=(int)(result[tempi].centre_x-result[tempi].rect_length/2+(result[tempi].coordinatex));
	//	if (colx<col&&colx>=0)
		{
			for (int RowNum=result[tempi].centre_y-result[tempi].rect_length/2;RowNum<result[tempi].rect_length/2+result[tempi].centre_y;RowNum++)
			{
				outpic.p[RowNum][colx]=255;
			}
		}
	}
	else
	{
		for (int i=0;i<rect_length;i++)
			for (int j=0;j<rect_length;j++)
			{
				outpic.p[i+left_toppointx][j+left_toppointy]=128;
			}
		/*
		for (int RowNum=0;RowNum<result[tempi].rect_length;RowNum++)
		{
			rowx=(int)( (RowNum-sin(PI-ta)*max_rhoMaxnum)/tan(PI/2-ta)+max_rhoMaxnum*cos(PI-ta) );
			rowx=(int)(rowx+(rect_length)/2);
			if (rowx<rect_length&&rowx>=0)
				outpic.p[RowNum+left_toppointx][rowx+left_to

⌨️ 快捷键说明

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