void edges(int height, int width, RGBTRIPLE image[height][width])
{
//Set temp image
RGBTRIPLE *edgeimage = malloc((height + 1) * (width + 1) + 4);
//RGBTRIPLE
edgeimage[height][width];
//Go through all pixels and copy to edgeimage
for (int i = 0; i < height; i++)
{
for (int j = 0; j < width; j++)
{
edgeimage[i][j] = image[i][j];
}
}
for (int i = 0; i < height; i++)
{
for (int j = 0; j < width; 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 } };
int GxRed = 0, GxGreen = 0, GxBlue = 0, GyRed = 0, GyGreen = 0, GyBlue = 0;
for (int k = -1; k < 2; k++)
{
if (i + k < 0 || (i + k > height - 1))
{
edgeimage[i + k][j].rgbtRed = 0;
edgeimage[i + k][j].rgbtGreen = 0;
edgeimage[i + k][j].rgbtBlue = 0;
}
for (int h = -1; h < 2; h++)
{
if (j + h < 0 || (j + h > width - 1))
{
//continue;
edgeimage[i][j + h].rgbtRed = 0;
edgeimage[i][j + h].rgbtGreen = 0;
edgeimage[i][j + h].rgbtBlue = 0;
}
for (int a = 0; a < 3; a++)
{
for (int b = 0; b < 3; b++)
{
GxRed += edgeimage[i + k][j + h].rgbtRed * Gx[a][b];
GxGreen += edgeimage[i + k][j + h].rgbtGreen * Gx[a][b];
GxBlue += edgeimage[i + k][j + h].rgbtBlue * Gx[a][b];
GyRed += edgeimage[i + k][j + h].rgbtRed * Gy[a][b];
GyGreen += edgeimage[i + k][j + h].rgbtGreen * Gy[a][b];
GyBlue += edgeimage[i + k][j + h].rgbtBlue * Gy[a][b];
}
}
}
}
float red = sqrt(pow(GxRed,2) + pow(GyRed,2));
float green = sqrt(pow(GxGreen,2) + pow(GyGreen,2));
float blue = sqrt(pow(GxBlue,2) + pow(GyBlue,2));
if (red > 255)
red = 255;
if (green > 255)
green = 255;
if (blue > 255)
blue = 255;
image[i][j].rgbtRed = round(red);
image[i][j].rgbtGreen = round(green);
image[i][j].rgbtBlue = round(blue);
}
}
return;
}