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

📄 sobel.c

📁 适用于ti公司dm642芯片的sobel算子例程很好的资料
💻 C
字号:
/*****************************************************************
** 函数名:	SobelOnePoint	
** 输 入: 	Imagebuf,Row,Col,Length
** InImagebuf---输入图像处理前显示区指针。
** Row---	行偏移。
** Col---	列偏移。
** Length---	显示区的行长度。
** 输 出: 	OutImagebuf
** OutImagebuf---输出图像处理后的显示区指针。
** 函数返回值:	无。
** 功能描述:	单点的Sobel因子边缘检测。
** 全局变量:	SobelHorizontal[9],SobelVeltical[9]。
** SobelHorizontal--- 水平卷积因子。
** SobelVeltical---垂直卷积因子。
** 调用模块:	无。
** 作 者:	吴定明
** 日 期:	2003-11-7
** 修 改:
** 日 期:
** 版 本		v1.0
****************************************************************/
char SobelHorizontal[9] = { -1, -2, -1,
			   				 0,  0,  0,
			   				 1,  2,  1};
char SobelVeltical[9] = { -1,  0,  1,
			  			  -2,  0,  2,
			  			  -1,  0,  1};
void SobelOnePoint( InImagebuf, OutImagebuf, Row, Col, Length)
unsigned char * InImagebuf;
unsigned char * OutImagebuf;
unsigned int  Row;
unsigned int  Col;
unsigned int  Length;
{
	unsigned int i ;
	unsigned int j = (Row - 1) * Length;
	short temp1 = 0,temp2 = 0;
	unsigned char *ptr = InImagebuf + j + Col - 1;
	char *ptrh = SobelHorizontal;
	char *ptrv = SobelVeltical;
	for(i = 0; i < 3; i++)
	{
		temp1 += (unsigned short) *ptr * (short)*ptrh++;
		temp2 += (unsigned short) *ptr++ * (short)*ptrv++;
		temp1 += (unsigned short) *ptr * (short)*ptrh++;
		temp2 += (unsigned short) *ptr++ * (short)*ptrv++;
		temp1 += (unsigned short) *ptr * (short)*ptrh++;
		temp2 += (unsigned short) *ptr++ * (short)*ptrv++;
		ptr += Length-3;
	}
	if(temp1 < 0)
	{
		temp1 = 0-temp1;
	}
	if(temp2 < 0)
	{
		temp2 = 0-temp2;
	}
	if(temp1 > temp2)	
	{
		OutImagebuf[Length * Row + Col] = (unsigned char) temp1;			
	}
	else
	{
		OutImagebuf[Length * Row + Col] = (unsigned char) temp2;			
	}
	return;
}
/*****************************************************************
** 函数名:	SobelImage	
** 输 入: 	InImagebuf , Height, Width
** InImagebuf---输入图像处理前显示区指针。
** Height---	显示区的行长度。
** Width---	显示区的列长度。
** 输 出: 	OutImagebuf
** OutImagebuf---输出图像处理后的显示区指针。
** 功能描述:	整幅的Sobel因子边缘检测。
** 全局变量:	无。
** 调用模块:	SobelOnePoint。
** 作 者:	吴定明
** 日 期:	2003-11-7
** 修 改:
** 日 期:
** 版 本		v1.0
****************************************************************/
void SobelImage( InImagebuf, Height, Width, OutImagebuf)
unsigned char * InImagebuf;
volatile unsigned int  Height;
unsigned int  Width;
unsigned char * OutImagebuf;
{
	unsigned int i;
	unsigned int j;
	for( j = 1; j < Height - 1; j++)
	{
		for( i = 1; i < Width - 1; i++)	
		{
			SobelOnePoint( InImagebuf, OutImagebuf, j, i, Width);
		}
	}	
	return;
}

⌨️ 快捷键说明

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