Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Blur image
- void blur(int height, int width, RGBTRIPLE image[height][width])
- {
- // Creates the temporary variable to store the data in before we change it; as well as introduces variables RGB sum & incrementing variable 'elements' to divide by
- RGBTRIPLE temp[height][width];
- float redsum;
- float greensum;
- float bluesum;
- float elements;
- // Enters row
- for (int i = 0; i < height; i++)
- {
- // Enters column
- for (int j = 0; j < width; j++)
- {
- // Nullifies the variables
- redsum = 0;
- greensum = 0;
- bluesum = 0;
- elements = 0;
- // Restricts to 1 row below through to 1 above
- for (int x = i - 1; x <= i + 1; x++)
- {
- // Restricts to 1 column to the side through to 1 over
- for (int y = j - 1; y <= j + 1; y++)
- {
- // Restrict the x and y variables so that they are never < 0 or > matrix_size
- if ((x >= 0 && x <= height - 1) && (y >= 0 && y <= width - 1))
- {
- // Sum up all original red values in the defined matrix
- redsum += image[x][y].rgbtRed;
- // Sum up all original blue values in the defined matrix
- greensum += image[x][y].rgbtGreen;
- // Sum up all original green values in the defined matrix
- bluesum += image[x][y].rgbtBlue;
- // Increment the pixels/elements used
- elements++;
- }
- }
- }
- // Store the average RGB values in the temporary variable
- temp[i][j].rgbtRed = round(redsum / elements);
- temp[i][j].rgbtGreen = round(greensum / elements);
- temp[i][j].rgbtBlue = round(bluesum / elements);
- }
- }
- // Enters column
- for (int i = 0; i < height; i++)
- {
- // Enters row
- for (int j = 0; j < width; j++)
- {
- // Sets the 'selected pixel' to the temporary variables we stored in previously
- image[i][j].rgbtRed = temp[i][j].rgbtRed;
- image[i][j].rgbtGreen = temp[i][j].rgbtGreen;
- image[i][j].rgbtBlue = temp[i][j].rgbtBlue;
- }
- }
- return;
- }
Advertisement
Add Comment
Please, Sign In to add comment