I am trying to implement the Gaussian Filter in C. My output layout keeps coming out wrong, I tried playing with the rows and columns in my for loops but it didn't work. The output layout should look like this:
0.0161464 0.0294206 0.0359344 0.0294206 0.0161464
0.0294206 0.0536078 0.0654768 0.0536078 0.0294206
0.0359344 0.0654768 0.0799735 0.0654768 0.0359344
0.0294206 0.0536078 0.0654768 0.0536078 0.0294206
0.0161464 0.0294206 0.0359344 0.0294206 0.0161464
(This is just an example of of a Gaussian filter layout).
Here the output layout I am getting in my program:
0.114986 0.101475 0.069743 0.037331 0.015562
0.101475 0.089551 0.061548 0.032944 0.013733
0.069743 0.061548 0.042301 0.022642 0.009439
0.037331 0.032944 0.022642 0.012119 0.005052
0.015562 0.013733 0.009439 0.005052 0.002106
Here is the code segment of my program:
for (i = 0; i < smooth_kernel_size; i++) {
for (j = -0; j < smooth_kernel_size; j++) {
gauss[i][j] = K * exp(((pow((i), 2) + pow((j), 2)) / ((2 * pow(sigma, 2)))) * (-1));
sum += gauss[i][j];
}
}
for (i = 0; i < smooth_kernel_size; i++) {
for (j = 0; j < smooth_kernel_size; j++) {
gauss[i][j] /= sum;
}
}
for (i = 0; i < smooth_kernel_size; i++) {
for (j = 0; j < smooth_kernel_size; j++) {
printf("%f ", gauss[i][j]);
}
printf("\n");
}
Will appreciate any advice!