0

See my check50 results here


// Blur image
void blur(int height, int width, RGBTRIPLE image[height][width])
{
    RGBTRIPLE tmp_image[height][width];

    for (int y = 0; y < height; y++)
        for (int x = 0; x < width; x++)
        {
            // averages
            int av_red = 0;
            int av_green = 0;
            int av_blue = 0;

            int dividor = 0;

            for (int _y = -1; _y < 1; _y++)
                 for (int _x = -1; _x < 1; _x++)
                 {
                    // if inside images bounds
                    if ((y + _y) < height && (y + _y) >= 0 && (x + _x) < width  && (x + _x) >= 0)
                    {
                        av_red   += image[y + _y][x + _x].rgbtRed;
                        av_green += image[y + _y][x + _x].rgbtGreen;
                        av_blue  += image[y + _y][x + _x].rgbtBlue;

                        dividor++;
                    }
                 }

            if (dividor > 0)
            {
                av_red   = (int) round((double)av_red   / (double)dividor);
                if (av_red > 255)
                    av_red = 255;

                av_green = (int) round((double)av_green / (double)dividor);
                if (av_green > 255)
                    av_green = 255;

                av_blue  = (int) round((double)av_blue  / (double)dividor);
                if (av_blue > 255)
                    av_blue = 255;

                // set tmp_images colors
                tmp_image[y][x].rgbtRed   = av_red;
                tmp_image[y][x].rgbtGreen = av_green;
                tmp_image[y][x].rgbtBlue  = av_blue;
            }
        }

    // set current image to tmp_image
    for (int y = 0; y < height; y++)
        for (int x = 0; x < width; x++)
        {
            image[y][x] = tmp_image[y][x];
        }
}

The image blurs correctly but the numbers are slightly off.

the errors

:( blur correctly filters middle pixel
    expected "127 140 149\n",       not "70 85 95\n"

:( blur correctly filters pixel on edge
    expected "80  95  105\n",       not "25 35 45\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\n25 3..."

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

Have a close look at the conditionals for your inner for loops. Is < 1 the right test?

-1

YES! ok so the nested for loop of _x _y was wrong it should be

for (int _y = -1; _y <= 1; _y++)

my logic in < should have been <=

Shout out to Blauelf for pointing that out! (in Discord)

You must log in to answer this question.

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