I'm having an issue with the blur filter; when working with Duck to understand how to structure my code, I was able to come up with a solution, but the output image was darkened and blurred up until the last row or two. Here's the original:
And here's the blurred:
I tried using the 3x3 image for debugging too but I'm not sure how to understand what's happening:
I'll share my code here too, but if it's inappropriate for me to do so, I'll adjust my question accordingly, so as to observe academic honesty. Do you have any suggestions as to what I should try and change/look at more closely?
void blur(int height, int width, RGBTRIPLE image[height][width])
{
// Create a copy of image
RGBTRIPLE copy[height][width];
for (int i = 0; i < height; i++)
{
for (int j = 0; j < width; j++)
{
copy[i][j] = image[i][j];
float pixel_count = 0.0;
int blue_sum = 0;
int green_sum = 0;
int red_sum = 0;
for(int k = i-1; k < height && k <= i + 1; k++)
{
for(int l = j-1; l < width && l <= j + 1 ; l++)
{
if (k >= 0 && l >= 0)
{
blue_sum += copy[k][l].rgbtBlue;
green_sum += copy[k][l].rgbtGreen;
red_sum += copy[k][l].rgbtRed;
pixel_count += 1;
}
}
}
float blue_avg = (blue_sum / pixel_count);
float green_avg = (green_sum / pixel_count);
float red_avg = (red_sum / pixel_count);
int average_blue = round(blue_avg);
int average_green = round(green_avg);
int average_red = round(red_avg);
image[i][j].rgbtBlue = average_blue;
image[i][j].rgbtGreen = average_green;
image[i][j].rgbtRed = average_red;
// For debugging to compare to expected output
printf("%i %i %i\n", image[i][j].rgbtRed,
image[i][j].rgbtGreen, image[i][j].rgbtBlue);
}
}
return;
}