</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);
}
高斯滤波——图像处理
最新推荐文章于 2024-06-23 18:30:48 发布