0
void edges(int height, int width, RGBTRIPLE image[height][width])
{
    RGBTRIPLE copy[height][width];
    for (int i = 0; i < height; i++)
    {
        for (int j = 0; j < width; j++)
        {
            copy[i][j] = image[i][j];
        }
    }

    int Gx[3][3] =
    {
        {-1, 0, 1},
        {-2, 0, 2},
        {-1, 0, 1},
    };
    int Gy[3][3] =
    {
        {-1, -2, -1},
        {0, 0, 0},
        {1, 2, 1},
    };
    for (int i = 0; i < height; i++)
    {
        long redx = 0, redy = 0;
        long greenx = 0, greeny = 0;
        long bluex = 0, bluey = 0;

        for (int j = 0; j < height; j++)
        {
            for (int h = -1; h < 2; h++)
            {
                for (int k = -1; k < 2; k++)
                {
                    if (i + h < 0 || i + h > width - 1 || j + k < 0 || j + k > height - 1)
                    {
                        continue;
                    }
                    redx = image[i + h][j + k].rgbtRed * Gx[h + 1][k + 1];
                    greenx = image[i + h][j + k].rgbtGreen * Gx[h + 1][k + 1];
                    bluex = image[i + h][j + k].rgbtBlue * Gx[h + 1][k + 1];
                    redy = image[i + h][j + k].rgbtRed * Gy[h + 1][k + 1];
                    greeny = image[i + h][j + k].rgbtGreen * Gy[h + 1][k + 1];
                    bluey = image[i + h][j + h].rgbtBlue * Gy[h + 1][k + 1];

                    int red = round(fmin(255, sqrt((redx^2) + (redy^2))));
                    int green = round (fmin(255, sqrt((greenx^2) + (greeny^2))));
                    int blue = round (fmin(255, sqrt((bluex^2) + (bluey^2))));
 
                    copy[i][j].rgbtRed = red;
                    copy[i][j].rgbtGreen = green;
                    copy[i][j].rgbtBlue = blue;
                }
            }
            image[i][j].rgbtRed = copy[i][j].rgbtRed;
            image[i][j].rgbtGreen = copy[i][j].rgbtGreen;
            image[i][j].rgbtBlue = copy[i][j].rgbtBlue;
        }
    }
    return;
}

on running check50

:( edges correctly filters middle pixel
    expected "210 150 60\n", not "10 9 4\n"
:( edges correctly filters pixel on edge
    expected "213 228 255\n", not "13 12 13\n"
:( edges correctly filters pixel in corner
    expected "76 117 255\n", not "7 9 14\n"
:( edges correctly filters 3x3 image
    expected "76 117 255\n21...", not "7 9 14\n13 12 ..."
:( edges correctly filters 4x4 image
    expected "76 117 255\n21...", not "7 9 14\n13 12 ..."

the code compiles fine and my math should be right but but fails all the check50 tests.

0
redx = image[i + h][j + k].rgbtRed * Gx[h + 1][k + 1];

In this line, you should be making a sum of all the values for all 9 pixels, but you're resetting redx every time. (Same for the other 5 lines below this one.) That's why all your values are much lower than they should be.

| improve this answer | |

You must log in to answer this question.

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