0

My blur function looks like it is working when I output files and it passes check50 on everything except the last two checks. Looking at the message below, it appears my values are correct ( "70 85 95). Any idea what might be going on here? Thanks.

:( blur correctly filters 3x3 image
    expected "70 85 95\n80 9...", not "70 85 95\n80 9..."
:( blur correctly filters 4x4 image
    expected "70 85 95\n80 9...", not "70 85 95\n80 9..."

Function:

void blur(int height, int width, RGBTRIPLE image[height][width])
{

    float redTotal = 0;
    float greenTotal = 0;
    float blueTotal = 0;
    float counter = 0;

    RGBTRIPLE tmp[height][width];

    //iterate through each row of the image h times
    for (int i = 0; i < height; i++)
    {
        //loop copying ith image row into tmp
        for (int j = 0; j < width; j++)
        {
            //assign image at ith & jth index to tmp variable
            tmp[i][j] = image[i][j];
        }
    }

        for(int i = 0; i < height; i++)
        {

         for (int j = 0; j < width; j++)
        {
            //middle row
            //mid mid
            redTotal = tmp[i][j].rgbtRed;
            greenTotal = tmp[i][j].rgbtGreen;
            blueTotal = tmp[i][j].rgbtBlue;
            counter = 1;

                //mid left
                if (j-1 >= 0)
                {
                    redTotal += tmp[i][j-1].rgbtRed;
                    greenTotal += tmp[i][j-1].rgbtGreen;
                    blueTotal += tmp[i][j-1].rgbtBlue;
                    counter++;
                }

                // mid right
                if ( j < width - 1)
                {
                redTotal += tmp[i][j+1].rgbtRed;
                greenTotal += tmp[i][j+1].rgbtGreen;
                blueTotal += tmp[i][j+1].rgbtBlue;
                counter++;
                }

                //upper row
                if ( i - 1 >= 0)
                {
                    //upper mid
                    redTotal += tmp[i-1][j].rgbtRed;
                    greenTotal += tmp[i-1][j].rgbtGreen;
                    blueTotal += tmp[i-1][j].rgbtBlue;
                    counter++;

                    //upper left
                    if (j - 1 >= 0)
                    {
                        redTotal += tmp[i-1][j-1].rgbtRed;
                        greenTotal += tmp[i-1][j-1].rgbtGreen;
                        blueTotal += tmp[i-1][j-1].rgbtBlue;
                        counter++;
                    }

                    //upper right
                    if (j < width - 1)
                    {
                        redTotal += tmp[i-1][j+1].rgbtRed;
                        greenTotal += tmp[i-1][j+1].rgbtGreen;
                        blueTotal += tmp[i-1][j+1].rgbtBlue;
                        counter++;
                    }
                }

                //lower row
                if ( i + 1 <= height)
                {
                    //lower mid
                    redTotal += tmp[i+1][j].rgbtRed;
                    greenTotal += tmp[i+1][j].rgbtGreen;
                    blueTotal += tmp[i+1][j].rgbtBlue;
                    counter++;

                    //lower left
                    if (j - 1 >= 0)
                    {
                        redTotal += tmp[i+1][j-1].rgbtRed;
                        greenTotal += tmp[i+1][j-1].rgbtGreen;
                        blueTotal += tmp[i+1][j-1].rgbtBlue;
                        counter++;
                    }

                    //lower right
                    if (j < width -1)
                    {
                        redTotal += tmp[i+1][j+1].rgbtRed;
                        greenTotal += tmp[i+1][j+1].rgbtGreen;
                        blueTotal += tmp[i+1][j+1].rgbtBlue;
                        counter++;
                    }
                }


            //assign avg values to RGB of pixel
            image[i][j] = (RGBTRIPLE){.rgbtBlue = round((int)blueTotal / counter), .rgbtGreen = round((int)greenTotal / counter), .rgbtRed = round((int)redTotal / counter)};

            }
        }

1 Answer 1

1

At the end fo your check50 messages, there should be a line that says

To see the results in your browser go to https://submit.cs50.io/check50/...

If you click on the link, you will notice your code doesn't give the correct output for some pixels (I tried running your code). Fix your code and you should be good.

1
  • 1
    Thanks for the response. Knowing about that functionality on check50 was really helpful and made it a lot easier to find my mistake. Apr 1, 2020 at 15:21

You must log in to answer this question.

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