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;
}