高斯滤波——图像处理

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/guanyuqiu/article/details/52980899
</pre><pre name="code" class="cpp">void GaussianFilter(unsigned char* data, int width, int height)
{
	int				i,j,index,sum;
	unsigned char	*tmpdata;
	int		templates[9]={1,2,1,
		2,4,2,
		1,2,1};
	tmpdata = (unsigned char*)malloc(sizeof(unsigned char) * width * height);
	memcpy(tmpdata, data, sizeof(unsigned char) * width * height);
	for (i=1; i<height-1; i++)
	{
		for (j=1; j<width-1; j++)
		{
			index = 0;
			sum = 0;
			for (int m=i-1; m<i+2; m++)
			{
				for (int n=j-1; n<j+2; n++)
				{
					sum += tmpdata[m*width+n]*templates[index++];
				}
			}
			data[i*width+j] = sum/16;
		}
	}
	free(tmpdata);

}

猜你喜欢

转载自blog.csdn.net/guanyuqiu/article/details/52980899