0

Im extremely close to solve this problem, this is the result of check50

:) helpers.c exists
:) filter compiles
:) grayscale correctly filters single pixel with whole number average
:) grayscale correctly filters single pixel without whole number average
:) grayscale leaves alone pixels that are already gray
:) grayscale correctly filters simple 3x3 image
:) grayscale correctly filters more complex 3x3 image
:) grayscale correctly filters 4x4 image
:) sepia correctly filters single pixel
:) sepia correctly filters simple 3x3 image
:) sepia correctly filters more complex 3x3 image
:) sepia correctly filters 4x4 image
:) reflect correctly filters 1x2 image
:) reflect correctly filters 1x3 image
:) reflect correctly filters image that is its own mirror image
:) reflect correctly filters 3x3 image
:) reflect correctly filters 4x4 image
:) 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..."

this is my code

{
    RGBTRIPLE copy[height][width];
    for (int q = 0; q < height;q++)
    {// Creates a copy of image
        for(int w = 0; w < width;w++)
        {
            copy[q][w] = image[q][w];
        }
    }
    
    int subdivision_counter = 0;
    float all_red = 0;
    float all_green = 0;
    float all_blue = 0;

     for (int i = 0; i < height; i++)
    {
        for (int j = 0; j < width; j++)
        {// Indicates the pixel to blur

            for (int n = -1; n < 2;n++)
            {// Checks if there is a column up or belove the pixel
                if (i + n > height || i + n < 0)
                {
                    continue;
                }


                for (int u = -1; u < 2;u++)
                {// takes the rgbt values of the pixels and adds them toa variable
                    if (j + u > width || j + u < 0)
                    {
                        continue;
                    }
                    subdivision_counter += 1;
                    all_red += copy[i + n][j + u].rgbtRed;
                    all_green += copy[i + n][j + u].rgbtGreen;
                    all_blue += copy[i + n][j + u].rgbtBlue;
                }


            }
            all_red = all_red / subdivision_counter;
            all_blue = all_blue / subdivision_counter;
            all_green = all_green / subdivision_counter;
            
            image[i][j].rgbtRed = (int)round( all_red);
            image[i][j].rgbtBlue = (int)round (all_blue);
            image[i][j].rgbtGreen = (int)round (all_green);
            //resets variables
            all_red = 0;
            all_blue = 0;
            all_green = 0;
            
            subdivision_counter = 0;
            
        }   
}

    return;
}

Can you please help me understand what i am doing wrong? thank you for taking the time to read this.

1

Your algorithm works for the upper left corner, the upper and left edges, and the middle of the image, but not the bottom or right edges. The comparison of i + n to 0 makes sense, but think a bit more about the comparison of i + n to height. When doing the initial copy, is height an included value? The same statements hold true for j + u compared to width.

1
  • Thank you now it works! I changed the ">" in ">=" on i + n and j + u. – Ronny Groin Mar 11 at 9:24

You must log in to answer this question.

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