0

I know that the edges and corners are supposed to read errors, because I haven't fixed them yet. What I don't understand is why check50 reads errors for middle pixels.

// Blur image
void blur(int height, int width, RGBTRIPLE image[height][width])
{
    RGBTRIPLE tmpimage[height][width];
    // Copy each pixel of image[i][j] to tmpimage[i][j]
    for (int i = 0; i < height; i++)
    {
        for (int j = 0; j < width; j++)
        {
            tmpimage[i][j].rgbtBlue = image[i][j].rgbtBlue;
            tmpimage[i][j].rgbtGreen = image[i][j].rgbtGreen;
            tmpimage[i][j].rgbtRed = image[i][j].rgbtRed;
        }
    }

    for (int i = 1; i + 1 < height; i++)
    {
        for (int j = 1; j + 1 < width; j++)
        {
            int averageBlue = round((tmpimage[i][j].rgbtBlue + tmpimage[i - 1][j].rgbtBlue + tmpimage[i + 1][j].rgbtBlue + tmpimage[i - 1][j - 1].rgbtBlue + tmpimage[i][j - 1].rgbtBlue + tmpimage[i + 1][j - 1].rgbtBlue + tmpimage[i - 1][j + 1].rgbtBlue + tmpimage[i][j + 1].rgbtBlue + tmpimage[i + 1][j + 1].rgbtBlue) / 9);
            int averageGreen = round((tmpimage[i][j].rgbtGreen + tmpimage[i - 1][j].rgbtGreen + tmpimage[i + 1][j].rgbtGreen + tmpimage[i - 1][j - 1].rgbtGreen + tmpimage[i][j - 1].rgbtGreen + tmpimage[i + 1][j - 1].rgbtGreen + tmpimage[i - 1][j + 1].rgbtGreen + tmpimage[i][j + 1].rgbtGreen + tmpimage[i + 1][j + 1].rgbtGreen) / 9);
            int averageRed = round((tmpimage[i][j].rgbtRed + tmpimage[i - 1][j].rgbtRed + tmpimage[i + 1][j].rgbtRed + tmpimage[i - 1][j - 1].rgbtRed + tmpimage[i][j - 1].rgbtRed + tmpimage[i + 1][j - 1].rgbtRed + tmpimage[i - 1][j + 1].rgbtRed + tmpimage[i][j + 1].rgbtRed + tmpimage[i + 1][j + 1].rgbtRed) / 9);
            image[i][j].rgbtBlue = averageBlue;
            image[i][j].rgbtGreen = averageGreen;
            image[i][j].rgbtRed = averageRed;
        }
    }
    return;
}
2
  • The specific error that I am receiving is :( blur correctly filters middle pixel expected "127 140 149\n", not "126 140 149\n"
    – lucidcloud
    May 12 '20 at 7:14
  • if I had to guess, I'd say that it's doing integer division before rounding, so it's just a little off. Maybe try dividing by 9,0 instead of 9. Just a guess.
    – Cliff B
    May 12 '20 at 9:03
1

You're doing integer division it disregards the remainder, simple fix would be to just divide by 9.0 as it will become a float division, integer division is like 11 / 2 = 5.5, oh the data type is int so let's just throw away the .5 so 11 / 2 = 5. so when it reaches your round function it does nothing since it's already a whole number.

0

I would also suggest to add a "float" to the division calculation "round(((float)(tmpimg... ) / 9)) - or something like that.

0

the code looks verbose. tmpimage[i][j] = image[i][j] would be enough to do a copy

You must log in to answer this question.

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