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

📄 laplac.c

📁 适用于ti公司dm642芯片的拉普拉斯算子例程很好的资料
💻 C
字号:
/*****************************************************************
** 函数名:	LaplacSharp
**		LaplacRGB	
**		LaplacYUV
** 输 入: 	InImagebuf , Height, Width
** InImagebuf---输入图像处理前显示区指针。
** Height---	显示区的行长度。
** Width---	显示区的列长度。
** 输 出: 	OutImagebuf
** OutImagebuf---输出图像处理后的显示区指针。
** 功能描述:	整幅的Laplac锐化图像处。
** 全局变量:	无。
** 调用模块:	LaplacSharpOnePoint。
** 作 者:	wdm
** 日 期:	2003-11-7
** 修 改:
** 日 期:
** 版 本		v1.0
****************************************************************/
// 检测模版
char LaplacVolList[9] = { -1, -1, -1,
			  -1,  9, -1,
			  -1, -1, -1
			};
void LaplacSharpOnePoint( 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;
	unsigned char *ptr = InImagebuf + j + Col - 1;
	char *ptrh = LaplacVolList;

	for(i = 0; i < 3; i++)
	{
		temp1 += (unsigned short) *ptr++ * (short)*ptrh++;
		temp1 += (unsigned short) *ptr++ * (short)*ptrh++;
		temp1 += (unsigned short) *ptr++ * (short)*ptrh++;
		ptr += Length-3;
	}
	if(temp1 < 0)
	{
		temp1 = 0-temp1;
	}
	OutImagebuf[Length * Row + Col] = (unsigned char) temp1;				
	return;
}

void LaplacSharp( 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++)	
		{
			LaplacSharpOnePoint( InImagebuf, OutImagebuf, j, i, Width);
		}
	}	
	return;
}
void LaplacRGB( InImagebuf, OutImagebuf, Height, Width)
unsigned char * InImagebuf;
unsigned char * OutImagebuf;
unsigned int  Height;
unsigned int  Width;
{
	int i;
	int j;
	int k;
	int l;
	
	// DIB的宽度
	int lWidth = Width;
	// DIB的高度
	int lHeight = Height;
	int lLineBytes = lWidth * 3;
	// 中间变量
	int v_r, v_g, v_b, p_g;

	// 3X3 模版
	for (i = 0; i < lWidth; i++)		//被处理像素在i列
	{
		for (j = 0; j < lHeight; j++)	//被处理像素在j行
		{
			v_r = v_g = v_b = p_g = 0;

			for (k = i - 1; k < i + 2; k++)	//3*3模版
			{
				for (l = j - 1; l < j + 2; l++)
				{
					// 防止内存溢出
					if (k >= 0  && l >= 0 && k < lWidth && l < lHeight)
					{
							v_r += *(InImagebuf + l * lLineBytes + k * 3) * LaplacVolList[p_g];
							v_g += *(InImagebuf + l * lLineBytes + k * 3 + 1) * LaplacVolList[p_g];
							v_b += *(InImagebuf + l * lLineBytes + k * 3 + 2) * LaplacVolList[p_g];
							p_g++;
					}
				}
			}
			
			if (v_r < 0)
				v_r = 0;
			if (v_g < 0)
				v_g = 0;
			if (v_b < 0)
				v_b = 0;

			OutImagebuf[j * lLineBytes + i * 3] = v_r;
			OutImagebuf[j * lLineBytes + i * 3 + 1] = v_g;
			OutImagebuf[j * lLineBytes + i * 3 + 2] = v_b;
		}
	}
}
void LaplacYUV( InImagebuf, OutImagebuf, Height, Width)
unsigned char * InImagebuf;
unsigned char * OutImagebuf;
unsigned int  Height;
unsigned int  Width;
{
	int i;
	int j;
	int k;
	int l;
	
	// DIB的宽度
	int lWidth = Width;
	// DIB的高度
	int lHeight = Height;
	int lLineBytes = lWidth * 2;
	// 中间变量
	int v_y,v_u,v_v,  p_g;
	
	// 3X3 模版
	for (i = 0; i < lWidth; i++)		//被处理像素在i列
	{
		for (j = 0; j < lHeight; j++)	//被处理像素在j行
		{
			v_y  = p_g = 0;

			for (k = i - 1; k < i + 2; k++)	//3*3模版
			{
				for (l = j - 1; l < j + 2; l++)
				{
					// 防止内存溢出
					if (k >= 0  && l >= 0 && k < lWidth && l < lHeight)
					{
							v_y += *(InImagebuf + l * lLineBytes + k * 2) * LaplacVolList[p_g];
							p_g++;
					}
				}
			}
			
			if (v_y < 0)
				v_y = 0;
			OutImagebuf[j * lLineBytes + i * 2] = v_y;
		}
	}
	for (i = 0; i < lWidth; i+=2)		//被处理像素在i列
	{
		for (j = 0; j < lHeight; j++)	//被处理像素在j行
		{
			v_u = v_v  = p_g = 0;

			for (k = i - 2; k < i + 4; k += 2)	//3*3模版
			{
				for (l = j - 1; l < j + 2; l++)
				{
					// 防止内存溢出
					if (k >= 0  && l >= 0 && k < lWidth && l < lHeight)
					{
							v_u += *(InImagebuf + l * lLineBytes + k * 2) * LaplacVolList[p_g];
							v_v += *(InImagebuf + l * lLineBytes + k * 2 + 1) * LaplacVolList[p_g];
							p_g++;
					}
				}
			}
			
			if (v_u < 0)
				v_u = 0;
			if (v_v < 0)
				v_v = 0;	
			OutImagebuf[j * lLineBytes + i * 2] = v_u;
			OutImagebuf[j * lLineBytes + i * 2 + 1] = v_v;
		}
	}

}

⌨️ 快捷键说明

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