0

My function kind of works but the result is too white.
I saw some people having the same issue because they didn't store the new pixels in a temporary image, but I already did that.

void edges(int height, int width, RGBTRIPLE image[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} };
    int matb[3][3], matg[3][3], matr[3][3];
    long bx, by, gx, gy, rx, ry, blue, green, red;
    RGBTRIPLE new_image[height][width];
    
    for (int i = 0; i < height; i++)
    {
        for (int j = 0; j < width; j++)
        {
            bx = by = gx = gy = rx = ry = 0;
            for (int h = i - 1; h <= i + 1; h++)
            {
                for (int w = j - 1; w <= j + 1; w++)
                {
                    if (h >= 0 && h < height && w >= 0 && w < width)
                    {
                        matb[i-h+1][j-w+1] = image[h][w].rgbtBlue;
                        matg[i-h+1][j-w+1] = image[h][w].rgbtGreen;
                        matr[i-h+1][j-w+1] = image[h][w].rgbtRed;
                    }
                    else
                    {
                        matb[i-h+1][j-w+1] = matg[i-h+1][j-w+1] = matr[i-h+1][j-w+1] = 0;
                    }
                }
            }
            for (int x = 0; x < 3; x++)
            {
                for (int y = 0; y < 3; y++)
                {
                    bx += matb[x][y] * Gx[x][y];
                    by += matb[x][y] * Gy[x][y];
                    gx += matg[x][y] * Gx[x][y];
                    gy += matg[x][y] * Gy[x][y];
                    rx += matr[x][y] * Gx[x][y];
                    ry += matr[x][y] * Gy[x][y];
                }
            }
    
            blue = bx^2 + by^2;
            green = gx^2 + gy^2;
            red = rx^2 + ry^2;
    
            if (blue > 255) {blue = 255;}
            if (green > 255) {green = 255;}
            if (red > 255) {red = 255;}
    
            new_image[i][j].rgbtBlue = blue;
            new_image[i][j].rgbtGreen = green;
            new_image[i][j].rgbtRed = red;
    
        }
    }
    
    for (int i = 0; i < height; i++)
    {
        for (int j = 0; j < width; j++)
        {
            image[i][j] = new_image[i][j];
        }
    }
    
    return; 
}

1 Answer 1

0

You appear to be using the exclusive OR operator in the following lines when you might be wanting to square them.

blue = bx^2 + by^2;
green = gx^2 + gy^2;
red = rx^2 + ry^2;

Remember, C does not have an exponent operator, so you must do something like bx*bx or use the pow() function from math.h to square it.

4
  • That changed something but it is still too white, even whiter actually XD Jan 10, 2021 at 12:41
  • That's because you're supposed to take the square root of the sum of the squares, right? ;) Jan 10, 2021 at 12:50
  • I thought about that, but for some reason I didn't try it -_- Jan 10, 2021 at 12:57
  • It works.... Thank you!!! Jan 10, 2021 at 12:57

You must log in to answer this question.

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