0

Please help with what i did wrong, i cannot seem to find where my logic was wrong and been staring at it for weeks. I've tried to change my approach a few times but does not seem closer at all and unable to pass any of the check 50

RGBTRIPLE newimage[height][width]; //create variables to store the manipulated values of the image int red, green, blue, counter;

for (int i = 0; i < height; i++)
{
    for (int j = 0; j < width; j++)
    {
        //assign original value of the image into the replacement array for manipulation  
        newimage[i][j] = image[i][j];

        //reset values of red,green,blue,counter for this pixel into 0
        red = green = blue = counter = 0;

        //access the 8 pixels round the piel that you are looking at, continue if the the pixels are outside of the grid
        for (int h = -1; h < 2; h++)
        {

            for (int w = -1; w < 2; w++)
            {
                if((i + h) > -1 && (i + h) < height && (j + w) > -1 && (j + w) < width)
                {
                    red += newimage[i + h][j + w].rgbtRed;
                    green += newimage[i + h][j + w].rgbtGreen;
                    blue += newimage[i + h][j + w].rgbtBlue;
                    counter++;
                }

            }
        }

        image[i][j].rgbtRed = round (red / counter);
        image[i][j].rgbtGreen = round (green / counter);
        image[i][j].rgbtBlue = round (blue / counter);


    }    

}
return;

:( blur correctly filters middle pixel expected "127 140 149\n", not "115 119 118\n" :( blur correctly filters pixel on edge expected "80 95 105\n", not "35 43 15\n" :( blur correctly filters pixel in corner expected "70 85 95\n", not "2 5 7\n" :( blur correctly filters 3x3 image expected "70 85 95\n80 9...", not "2 5 7\n22 19 1..." :( blur correctly filters 4x4 image expected "70 85 95\n80 9...", not "34 52 29\n45 3..."

1 Answer 1

1

It's the same problem here: https://cs50.stackexchange.com/a/38197/27433

Also by doing the division for the averaging with 'int' types, will result in a number that will be truncated. i.e. if the result of the division is 1.99 you'll get 1, and the decimal part will be lost. You can get around it by declaring ne or both of the operators to a decimal point capable type (float or double).

1
  • Thank you so much! i saw that but i thought i had resolved that issue, i didn't really understand before your comment...
    – Daryl
    Jun 17, 2020 at 9:36

You must log in to answer this question.

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