I was making a grayscale filter for an image that is passed in as a struct and is image[height][width]. All the values seem to be working but for some reason, the function doesn't round properly. For example if the RGB values are 27 28 28, the avg should be 28 but instead, it is 27 so it copies as 27 27 27. Why?
// Convert image to grayscale
void grayscale(int height, int width, RGBTRIPLE image[height][width])
{
for (int i = 0; i < height; i++)
{
for (int w = 0; w < width; w++)
{
float avg = ((image[i][w].rgbtRed + image[i][w].rgbtGreen + image[i][w].rgbtBlue) / 3);
image[i][w].rgbtRed = round(avg);
image[i][w].rgbtGreen = round(avg);
image[i][w].rgbtBlue = round(avg);
}
}
return;
}