I can't seen to find what is wrong with blur in my code. My code seems fine and it compiles too but the image doesn't get as blurred as it should. I've surfed through almost all the blur related questions here but my error is still not solved.
Please help me find the error in my code. Down below are the error messages that check50 is giving me:
:( blur correctly filters middle pixel expected "127 140 149\n", not "105 120 130\n"
:( blur correctly filters pixel on edge expected "80 95 105\n", not "76 91 101\n"
:) blur correctly filters pixel in corner
:( blur correctly filters 3x3 image expected "70 85 95\n80 9...", not "70 85 95\n76 9..."
:( blur correctly filters 4x4 image expected "70 85 95\n80 9...", not "70 85 95\n76 9..."
Here is my code so far:
// Blur image
void blur(int height, int width, RGBTRIPLE image[height][width]) { int avgred = 0, avggreen = 0, avgblue = 0; // initialzing the values float counter = 0.00; RGBTRIPLE temp[height][width];
for (int i = 0; i < height; i++) // takes care of height
{
for (int j = 0; j < width; j++) // takes care of width
{
for (int m = -1; m < 2; m++) // takes care of the columns of the 3x3 matrix
{
for (int n = -1; n < 2; n++) // takes care of the rows of the 3x3 matrix
{
if (i + m < 0 || i + m > height) // checking to see if the height matches the criteria in question
{
continue;
}
if(j + n < 0 || j + n > width) // checking for width instead of height
{
continue;
}
// blurring process begins
avgred+= image[i + m][j + n].rgbtRed;
avggreen+= image[i + m][j + n].rgbtGreen;
avgblue+= image[i + m][j + n].rgbtBlue;
counter++;
temp[i][j].rgbtRed = round(avgred / counter);
temp[i][j].rgbtGreen = round(avggreen / counter);
temp[i][j].rgbtBlue = round(avgblue / counter);
}
}
}
}
// final output
for (int i = 0; i < height; i++)
{
for (int j = 0; j < width; j++)
{
image[i][j].rgbtRed = temp[i][j].rgbtRed;
image[i][j].rgbtGreen = temp[i][j].rgbtGreen;
image[i][j].rgbtBlue = temp[i][j].rgbtBlue;
}
}
return;
}