DSPRelated.com
Forums

2D image gauss smoothing problem.

Started by aszi...@hotmail.com July 17, 2006
Hi Guys

I am trying to implement a gaussian smoothing function but i am having some problems that when i recover the image, the image is black instead of a gaussian image. I am implementing the 2D Gaussian euqaition. I am enclosing the code that i wrote in C. I would appreciate if anyone could help me where i am going wrong in the program.

void gaussian_smooth(sigma,float_image)
float sigma; float float_image[412][257];
{
float S,radius,nexpixel;
int x,y,x0,y0,a;
//float **weight; this is a global array.
int maxrows,maxcols;

radius = 2 * sigma *sigma;
maxrows = input_image.width;
maxcols = input_image.height;
nexpixel = 0;

for(y = -3*sigma; y < 3*sigma; y++)
for(x = -3*sigma; y < 3*sigma; y++)
{
a = (x*x) + (y*y) / radius ;
weight[x][y] = (0.5 * 3.142 * sigma) * exp((-1.0*x*x)+(y*y)/radius);
S = S + weight[x][y];

}
/*Calculating the Gaussian filter now*/
for(y0 = 3*sigma; y0<= maxcols - 3*sigma; y0++)
for(x0 = 3*sigma; x0<= maxrows - 3*sigma; x0++)
{
for(y = -3*sigma; y < 3*sigma; y++)
for(x = -3*sigma; y < 3*sigma; y++)
{
nexpixel = nexpixel + weight[x][y] * float_image[x+x0][y+y0];
}
nexpixel = nexpixel/S;
float_image[x0][y0] = nexpixel;
}
}