Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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];
- }
- }
- for (int i = 0; i < height; i++)
- {
- for (int j = 0; j < width; j++)
- {
- image[i][j].rgbtRed = color_value('r', i, j, height, width, copy);
- image[i][j].rgbtGreen = color_value('g', i, j, height, width, copy);
- image[i][j].rgbtBlue = color_value('b', i, j, height, width, copy);
- }
- }
- return;
- }
- int color_value(char color, int i, int j, int height, int width, RGBTRIPLE pixels[height][width])
- {
- //Arrays for Gx and Gy for weighted sum
- int Gx[] = {-1, 0, 1, -2, 0, 2, -1, 0, 1};
- int Gy[] = {-1, -2, -1, 0, 0, 0, 1, 2, 1};
- int Gx_value = 0;
- int Gy_value = 0;
- for (int k = 0; k < 9; k++)
- {
- int box_height = i + (k % 3) - 1; // "-1" is offset from pixel
- int box_width = j + (k / 3) - 1;
- // Check if pixel is out of border
- if (box_height < 0 || box_width < 0 || box_height >= height || box_width >= width)
- {
- Gx_value += 0;
- Gy_value += 0;
- continue;
- }
- switch(color)
- {
- case 'r':
- Gx_value += Gx[k] * pixels[box_height][box_width].rgbtRed;
- Gy_value += Gy[k] * pixels[box_height][box_width].rgbtRed;
- break;
- case 'g':
- Gx_value += Gx[k] * pixels[box_height][box_width].rgbtGreen;
- Gy_value += Gy[k] * pixels[box_height][box_width].rgbtGreen;
- break;
- case 'b':
- Gx_value += Gx[k] * pixels[box_height][box_width].rgbtBlue;
- Gy_value += Gy[k] * pixels[box_height][box_width].rgbtBlue;
- break;
- }
- }
- return (round(sqrt(Gx_value * Gx_value + Gy_value * Gy_value)) < 256) ? round(sqrt(Gx_value * Gx_value + Gy_value * Gy_value)) : 255;
- }
Add Comment
Please, Sign In to add comment