I'm tasked with writing a program that applies a gray scale filter to a given image. This is done by looping over each pixel and averaging the rgb values. When I check my code, I receive an error which seems to say "ERROR: expected X, received X". Any clarifications of the error message or comments about possible bugs are appreciated.
My code loops over each pixel in each row of an array of pixels which are described as RGBTRIPLES
, structs comprised of 3 uint8_t
's. In the case of a non-whole-number average the program rounds up to the nearest whole number. My answer is the code included below.
My problem comes when I run check50 cs50/problems/2021/x/filter/more
, a program which tests students' programs against keys made by the course designers. The 7th test check's the program's accuracy in filtering a "complex" 3x3 image; I get the following result:
:( grayscale correctly filters more complex 3x3 image
expected "20 20 20\n50 5...", not "20 20 20\n50 5..."
I am confused as it seems that my output matches the expected. Could someone give me a hint as to what my problem is?
My code:
void grayscale(int height, int width, RGBTRIPLE image[height][width])
{
//Loop over pixels
for (int y = 0; y < height; y++)
{
for (int x = 0; x < width; x++)
{
//Average out rgbs to get a corresponding greyscale value
BYTE average_activation = ceil(((float) image[y][x].rgbtBlue + image[y][x].rgbtRed + image[y][x].rgbtGreen) / 3);
RGBTRIPLE resultant_pixel = {average_activation, average_activation, average_activation};
//apply
image[y][x] = resultant_pixel;
}
}
return;
}