求助:如何用C语言编写将高斯噪声,均匀分布噪声,椒盐噪声加入图像
希望哪位高手帮我分析一下,有一小段的代码,但是不知道问题在哪,无法正常运行,说是无法读入程序。很是纠结。有没有哪位有完整的源代码,不胜感激!
程序代码:
/***************************************************************
函数: gaussmooth
描述: 实现图像的高斯平滑滤波(模板取σ=2和n=5)
输入参数说明:
w——图像矩阵的宽(int)
h——图像矩阵的高(int)
gray——指向图像矩阵的指针(int*)
***************************************************************/
void gaussmooth(int *gray,int w, int h)
{
//generate gauss model
int maxtry[]={1,2,3,2,1,
2,4,6,4,2,
3,6,7,6,3,
2,4,6,4,2,
1,2,3,2,1};//sigma^2=2,n=5 gauss model
int *Gauss=new int[25];
Gauss=maxtry;
long *grtemp;//the gray vaule after smoothing
grtemp=new long[w*h];
for(long j=0;j<h;j++)
{
for(long i=0;i<w;i++)
{
grtemp[j*w+i]=0;
for(int countj=j-2;countj<j+3;countj++)
{
if(countj>=0 && countj<h)
{
for(int counti=i-2;counti<i+3;counti++)
{ if (counti>=0 && counti<w)
grtemp[j*w+i]+=Gauss[(countj-(j-2))*5+(counti-(i-2))]*gray[countj*w+counti];
}
}
}
}
}
//normalization
int sumgauss=0;
for(int m=0;m<25;m++)
sumgauss+=Gauss[m];
for(j=0; j<h;j++)
{
for (long i=0;i<w;i++)
{
grtemp[j*w+i]=grtemp[j*w+i]/sumgauss;
}
}
for(j=0; j<h;j++)
{
for (long i=0;i<w;i++)
{
gray[j*w+i]=grtemp[j*w+i];
}
}
delete[] grtemp;
}







