0

this is my code for Edge, and it's not passing check50. below are the errors I got. any help is appreciated.

:( edges correctly filters middle pixel expected "210 150 60\n", not "28 202 211\n"

:( edges correctly filters pixel on edge expected "213 228 255\n", not "160 195 5\n"

:( edges correctly filters pixel in corner expected "76 117 255\n", not "76 117 66\n"

:( edges correctly filters 3x3 image expected "76 117 255\n21...", not "76 117 66\n160..."

:( edges correctly filters 4x4 image expected "76 117 255\n21...", not "76 117 66\n160..."

void edges(int height, int width, RGBTRIPLE image[height][width])
{
    RGBTRIPLE temp[height][width];

    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++)
    {
        for (int j = 0; j < width; j++)
        {
            int gxBlue = 0;
            int gyBlue = 0;
            int gxGreen = 0;
            int gyGreen = 0;
            int gxRed = 0;
            int gyRed = 0;

            for (int r = -1; r < 2; r++)
            {
                for (int c = -1; c < 2; c++)
                {
                    if (i + r < 0 || i + r > height - 1)
                    {
                        continue;
                    }
                    if (j + c < 0 || j + c > width - 1)
                    {
                        continue;
                    }

                    gxBlue += image[i + r][j + c].rgbtBlue * gx[r + 1][c + 1];
                    gyBlue += image[i + r][j + c].rgbtBlue * gy[r + 1][c + 1];
                    gxGreen += image[i + r][j + c].rgbtGreen * gx[r + 1][c + 1];
                    gyGreen += image[i + r][j + c].rgbtGreen * gy[r + 1][c + 1];
                    gxRed += image[i + r][j + c].rgbtRed * gx[r + 1][c + 1];
                    gyRed += image[i + r][j + c].rgbtRed * gy[r + 1][c + 1];
                }
            }

            int blue = round(sqrt(gxBlue * gxBlue + gyBlue * gyBlue));
            int green = round(sqrt(gxGreen * gxGreen + gyGreen * gyGreen));
            int red = round(sqrt(gxRed * gxRed + gyRed * gyRed));

            image[i][j].rgbtBlue = (blue > 255) ? 255 : blue;
            image[i][j].rgbtGreen = (green > 255) ? 255 : green;
            image[i][j].rgbtRed = (red > 255) ? 255 : red;

            temp[i][j].rgbtBlue = blue;
            temp[i][j].rgbtGreen = green;
            temp[i][j].rgbtRed = red;
        }
    }

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

    return;
}

1 Answer 1

1

This is the advanced version of the program, so help is just more questions.


Why do you store the blue/green/red values in temp, but store the upper saturated values in the original image array?


Why do you transfer from temp to image at the end?

1
  • thank you so much, that was the problem and I just fixed it.. it was me being careless, I did both less & more so I did a lot of copy&paste~~
    – YMeng
    Commented Mar 6, 2021 at 21:01

You must log in to answer this question.

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