0
// Blur image
void blur(int height, int width, RGBTRIPLE image[height][width])
{
    //Temp array
    RGBTRIPLE temp[height][width];

    for (int i = 0; i < height; i++)
    {
        for (int j = 0; j < width; j++)
        {
            temp[i][j].rgbtRed = image[i][j].rgbtRed;
            temp[i][j].rgbtGreen = image[i][j].rgbtGreen;
            temp[i][j].rgbtBlue = image[i][j].rgbtBlue;
        }
    }


    for (int i = 1; i < height - 2; i++)
    {
        for (int j = 1; j < width - 2; j++)
        {
            float totalR = 0;
            float totalG = 0;
            float totalB = 0;
            int count = 0;

            for (int a = -1; a < 2; a++)
            {
                for (int b = -1; b < 2; b++)
                {
                    //if (image[i + a][j + b].rgbtRed != NULL)
                    //{
                        totalR += image[i + a][j + b].rgbtRed;
                        totalG += image[i + a][j + b].rgbtGreen;
                        totalB += image[i + a][j + b].rgbtBlue;
                        count ++;
                    //}
                }
            }

            temp[i][j].rgbtRed = round(totalR / count);
            temp[i][j].rgbtGreen = round(totalG / count);
            temp[i][j].rgbtBlue = round(totalB / count);

        }
    }

    //copy temp -> original image array
    for (int i = 0; i < height; i++)
    {
        for (int j = 0; j < width; j++)
        {
            image[i][j] = temp[i][j];
        }
    }

    return;
}

I did this and the logic seems correct to me, even when I give it an image the output is blurred, but this is what i am getting after doing check50

:( blur correctly filters middle pixel expected "127 140 149\n", not "120 140 150\n"

:( blur correctly filters pixel on edge expected "80 95 105\n", not "40 50 60\n"

:( blur correctly filters pixel in corner expected "70 85 95\n", not "10 20 30\n"

:( blur correctly filters 3x3 image expected "70 85 95\n80 9...", not "10 20 30\n40 5..."

:( blur correctly filters 4x4 image expected "70 85 95\n80 9...", not "10 20 30\n40 5..."

You must log in to answer this question.

Browse other questions tagged .