基于不同模板的高斯滤波函数
VS2008
int GuassSmooth(unsigned char *ptrSrc, unsigned char *ptrDst, int iWidth, int iHeight, int templateSize)
{
int guassTemp3[9] = { 1, 2, 1,
2, 4, 2,
1, 2, 1 };
/*int guassTemp5[25] = { 1, 2, 3, 2, 1,
2, 5, 6, 5, 2,
3, 6, 8, 6, 3,
2, 5, 6, 5, 2,
1, 2, 3, 2, 1 };*/
int guassTemp5[25] = { 1, 4, 7, 4, 1,
4, 16, 26, 16, 4,
7, 26, 41, 26, 7,
4, 16, 26, 16, 4,
1, 4, 7, 4, 1 };
int guassTemp7[49] = { 1, 4, 7, 10, 7, 4, 1,
4, 12, 26, 33, 26, 12, 4,
7, 26, 55, 71, 55, 26, 7,
10, 33, 71, 91, 71, 33, 10,
7, 26, 55, 71, 55, 26, 7,
4, 12, 26, 33, 26, 12, 4,
1, 4, 7, 10, 7, 4, 1,};
int i,j;
int step;
int tmp;
int weigth;
int index;
step = iWidth*iHeight*3*sizeof(unsigned char);
memcpy(ptrDst,ptrSrc,iWidth*iHeight*3*sizeof(unsigned char));
if (3 == templateSize)
{
weigth = 0;
for (i = 0;i<9;i++)
{
weigth +=guassTemp3[i];
}
for (i = 1; i<iHeight-1;i++)
{
for (j = 1;j<iWidth-1;j++)
{
tmp = guassTemp3[0]*(*(ptrSrc+(i-1)*iWidth*3+(j-1)*3))
+guassTemp3[1]*(*(ptrSrc+(i-1)*iWidth*3+(j)*3))
+guassTemp3[2]*(*(ptrSrc+(i-1)*iWidth*3+(j+1)*3))
+guassTemp3[3]*(*(ptrSrc+(i)*iWidth*3+(j-1)*3))
+guassTemp3[4]*(*(ptrSrc+(i)*iWidth*3+(j)*3))
+guassTemp3[5]*(*(ptrSrc+(i)*iWidth*3+(j+1)*3))
+guassTemp3[6]*(*(ptrSrc+(i+1)*iWidth*3+(j-1)*3))
+guassTemp3[7]*(*(ptrSrc+(i+1)*iWidth*3+(j)*3))
+guassTemp3[8]*(*(ptrSrc+(i+1)*iWidth*3+(j+1)*3));
tmp = tmp/weigth;
tmp = tmp > 255? 255:tmp;
tmp = tmp < 0? 0:tmp;
*(ptrDst+i*iWidth*3+j*3) = tmp;
}
}
//给边界行和列赋值;
//...
}
else if (5 == templateSize)
{
weigth = 0;
for (i = 0;i<25;i++)
{
weigth +=guassTemp5[i];
}
for (i = 2; i<iHeight-2;i++)
{
for (j = 2;j<iWidth-2;j++)
{
tmp = 0;
index = 0;
for (int m = i-2;m<i+3;m++)
{
for (int n = j-2;n<j+3;n++)
{
tmp += *(ptrSrc+m*iWidth*3+n*3)*guassTemp5[index++];
}
}
tmp = tmp/weigth;
tmp = tmp > 255? 255:tmp;
tmp = tmp < 0? 0:tmp;
*(ptrDst+i*iWidth*3+j*3) = tmp;
}
}
}
else if (7 == templateSize)
{
weigth = 0;
for (i = 0;i<49;i++)
{
weigth +=guassTemp7[i];
}
for (i = 3; i<iHeight-3;i++)
{
for (j = 3;j<iWidth-3;j++)
{
tmp = 0;
index = 0;
for (int m = i-3;m<i+4;m++)
{
for (int n = j-3;n<j+4;n++)
{
tmp += *(ptrSrc+m*iWidth*3+n*3)*guassTemp7[index++];
}
}
tmp = tmp/weigth;
tmp = tmp > 255? 255:tmp;
tmp = tmp < 0? 0:tmp;
*(ptrDst+i*iWidth*3+j*3) = tmp;
}
}
}
return 0;
}
你可能喜欢
- 高斯滤波
- 平滑滤波
- 世界500强企业
- 工程电路
- matlab实例教程
- 中值滤波
- 高斯函数竞赛
- 4 平滑, 锐化滤波48页
- KNN平滑滤波2页
- 图像高斯平滑滤波分析(转)6页
- 平滑与数字滤波实验4页
- 保持边缘的高斯平滑滤波算法研究3页
- 实验四 图像的空域平滑滤波7页
- 西乡世界500强企业5页
- 世界500强企业20111页
- 世界500强企业优秀员工的12条核心标准2页
- 2011年世界500强企业(全部)22页
- 2008年世界500强企业排名12页
- 2011世界500强企业名单12页
- 电气工程师_电路基础91页
- 电气工程师_电路的分析方法81页
- 20种工程电路7页
- 工程电路分析答案(英文版)15页
- 工程电路分析答案(英文版)34页
- 工程电路分析答案(英文版)19页
- matlab_简明实例教程72页
- matlab实例教程19页
- matlab实用实例教程72页
- matlab_简明实例教程72页
- matlab_简明实例教程72页
- matlab_简明实例教程72页