following is my code for Blur. It works mathematically when I step through the loops for a given pixel using Tower, Yard, etc. But when running Check50, it fails every test except the corner test.

Here is the 3X3 detail error info: Error Log results

Following is my code...any hints on where I'm going wrong is greatly appreciated. I've been staring at this for days.

// Blur image
void blur(int height, int width, RGBTRIPLE image[height][width])
    int totalRed, totalGreen, totalBlue;
    double averageRed, averageGreen, averageBlue, counter;
    int minrow, maxrow, mincol, maxcol;
    for (int i = 0; i < height; i++)
            if (i == 0)
                    minrow = 0;
                    minrow = i - 1;
            if (i == height - 1)
                    maxrow = i;
                    maxrow = i + 1;
            for (int j = 0; j < width; j++)
                if (j == 0)
                        mincol = 0;
                        mincol = j - 1;
                if (j == width - 1)
                        maxcol = j;
                        maxcol = j + 1;
                counter = 0;
                totalRed = 0;
                totalGreen = 0;
                totalBlue = 0;
                for (int x = minrow; x <= maxrow; x++)
                    for (int y = mincol; y <= maxcol; y++)
                        counter = counter + 1;
                        totalRed = image[x][y].rgbtRed + totalRed;
                        totalGreen = image[x][y].rgbtGreen + totalGreen;
                        totalBlue = image[x][y].rgbtBlue + totalBlue;
                averageRed = totalRed / counter;
                averageGreen = totalGreen / counter;
                averageBlue = totalBlue / counter;
                image[i][j].rgbtRed = round(averageRed);
                image[i][j].rgbtGreen = round(averageGreen);
                image[i][j].rgbtBlue = round(averageBlue);

1 Answer 1


This is an interesting one! It took me a bit to realize what was happening. As you probably did, I spent a lot of time, looking for an error in the math, in the logic, in something that was in the code. Only after I stepped through the code watching every value change, was I able to find the issue. (Mostly because yesterday was the first day that I did this pset myself. ;-) I haven't debugged this one very often yet.)

Note that the first row is correct, but the following rows weren't. Further, there was a pattern to the difference between the correct values and the values from your program's result. It's a clue.

Think about this. The way to get the values for the blur is to average the values from the surrounding pixels in the original image. So, what happens when you're updating the original image as you go??? Are the original values still available in the pixels that have already been processed?

If this answers your question, please click on the check mark to acccept. Let's keep up on forum maintenance. ;-)

  • Now why would someone downvote this? Leave a comment and I'll respond.
    – Cliff B
    Commented May 12, 2020 at 23:41
  • Thank you Cliff! This was very helpful and did indeed help! I walked through a 3x3 and saw what you described. I appreciate your thorough explanation!
    – DaveS
    Commented May 13, 2020 at 3:01

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .