0

The blur image seems to be working and according to the error I am seeing, it looks like it is getting the right values, so I thought it might be a rounding error, but I have tried every combination of turning things from ints to floats to casting and none of it seems to be working. I appreciate any advice. (Sorry for the code length - I am new at this...) The code and error I am getting are below:

check 50 response

:) blur correctly filters middle pixel
:) blur correctly filters pixel on edge
:) blur correctly filters pixel in corner
:( 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..."

Code:

void blur(int height, int width, RGBTRIPLE image[height][width])
{
    int i = 0;
    int j = 0;
    RGBTRIPLE origimage[height][width];
    int avgr = 0;
    int avgg = 0;
    int avgb = 0;


    for (i = 0; i < height; i++)
    {
        for (j = 0; j < width; j++)
        {
            origimage[i][j] = image[i][j];
        }
    }

    for (i = 0; i < height; i++)
    {
        for (j = 0; j < width; j++)
        {
            int red = 0;
            int green = 0;
            int blue = 0;
            float counter = 0;

            if (i >= 0 && j >= 0)
            {
                red += origimage[i][j].rgbtRed;
                green += origimage[i][j].rgbtGreen;
                blue += origimage[i][j].rgbtBlue;
                counter++;
            }

            if (i >= 0 && i <= height && (j - 1) >= 0 && (j - 1) <= width)
            {
                red += origimage[i][j - 1].rgbtRed;
                green += origimage[i][j - 1].rgbtGreen;
                blue += origimage[i][j - 1].rgbtBlue;
                counter++;
            }

            if (i >= 0 && i <= height && (j + 1) >= 0 && (j + 1) < width)
            {
                red += origimage[i][j + 1].rgbtRed;
                green += origimage[i][j + 1].rgbtGreen;
                blue += origimage[i][j + 1].rgbtBlue;
                counter++;
            }

            if ((i - 1) >= 0 && (i - 1) <= height && (j - 1) >= 0 && (j - 1) <= width)
            {
                red += origimage[i - 1][j - 1].rgbtRed;
                green += origimage[i - 1][j - 1].rgbtGreen;
                blue += origimage[i - 1][j - 1].rgbtBlue;
                counter++;
            }

            if ((i + 1) >= 0 && (i + 1) <= height && (j - 1) >= 0 && (j - 1) <= width)
            {
                red += origimage[i + 1][j - 1].rgbtRed;
                green += origimage[i + 1][j - 1].rgbtGreen;
                blue += origimage[i + 1][j - 1].rgbtBlue;
                counter++;
            }

            if ((i + 1) >= 0 && (i + 1) <= height && (j + 1) >= 0 && (j + 1) < width)
            {
                red += origimage[i + 1][j + 1].rgbtRed;
                green += origimage[i + 1][j + 1].rgbtGreen;
                blue += origimage[i + 1][j + 1].rgbtBlue;
                counter++;
            }

            if ((i - 1) >= 0 && (i - 1) <= height && (j + 1) >= 0 && (j + 1) < width)
            {
                red += origimage[i - 1][j + 1].rgbtRed;
                green += origimage[i - 1][j + 1].rgbtGreen;
                blue += origimage[i - 1][j + 1].rgbtBlue;
                counter++;
            }

            if ((i - 1) >= 0 && (i - 1) <= height && j >= 0 && j <= width)
            {
                red += origimage[i - 1][j].rgbtRed;
                green += origimage[i - 1][j].rgbtGreen;
                blue += origimage[i - 1][j].rgbtBlue;
                counter++;
            }

            if ((i + 1) >= 0 && (i + 1) <= height && j >= 0 && j <= width)
            {
                red += origimage[i + 1][j].rgbtRed;
                green += origimage[i + 1][j].rgbtGreen;
                blue += origimage[i + 1][j].rgbtBlue;
                counter++;
            }


            avgr = round(red / counter);
            avgg = round(green / counter);
            avgb = round(blue / counter);

            image[i][j].rgbtRed = avgr;
            image[i][j].rgbtGreen = avgg;
            image[i][j].rgbtBlue = avgb;

        }


    }
0

If you click on the link in the check50 results, you can see more detailed results. Check50 is showing that the two tests, 3x3 and 4x4, are failing.

If you look at the detailed results, you will see that the last row of each image is incorrect. Are your test conditions for the code that handles the bottom edge and corners correct?

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

1
  • Thanks! I changed the parameters on the +1/-1 lines and that worked. Appreciate the help! – sar2082 Jul 22 '20 at 15:22

You must log in to answer this question.

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