CS50 pset4 过滤器(不太舒服)- 模糊功能不起作用

CS50 pset4 Filter (less comfortable) - blur function not working

我正在处理 CS50 (PSET4) 中的滤镜(不太舒服)问题,并且卡在了模糊功能上。我在所有检查点的 check50 上都收到错误,但是,我无法弄清楚我哪里出错了。如果有人可以帮助我,我将不胜感激。谢谢。这是我写的:

// Blur image
void blur(int height, int width, RGBTRIPLE image[height][width])
{
    RGBTRIPLE sum;
    RGBTRIPLE image_copy[height][width];

    //creating copy of image
    for (int i = 0; i < height; i++)
    {
        for (int j = 0; j < width; j++)
        {
            image_copy[i][j].rgbtBlue = image[i][j].rgbtBlue;
            image_copy[i][j].rgbtGreen = image[i][j].rgbtGreen;
            image_copy[i][j].rgbtRed = image[i][j].rgbtRed;
        }
    }

    //iterating over each pixel
    for (int i = 0; i < height; i++)
    {
        for (int j = 0; j < width; j++)
        {
            sum.rgbtBlue = 0;
            sum.rgbtGreen = 0;
            sum.rgbtRed = 0;
            int count = 0;
            //setting loops for 3*3 grid
            for (int k = i - 1; k <= i + 1; k++)
            {
                if(k >= 0 && k < height)
                {
                    for (int l = j - 1; l <= j + 1; l++)
                    {
                        if (l >= 0 && l < width)
                        {
                            sum.rgbtBlue = sum.rgbtBlue + image_copy[k][l].rgbtBlue;
                            sum.rgbtGreen = sum.rgbtGreen + image_copy[k][l].rgbtGreen;
                            sum.rgbtRed = sum.rgbtRed + image_copy[k][l].rgbtRed;
                            count++;
                        }
                    }
                }
            }
            // calculating average and updating original image
            image[i][j].rgbtBlue = round (sum.rgbtBlue / count);
            image[i][j].rgbtGreen = round (sum.rgbtGreen / count);
            image[i][j].rgbtRed = round (sum.rgbtRed /count);
        }
    }

   return;
}

sum.rgbtBlue / count整数除法,所以在传递给round().

之前已经向下舍入(截断)了

不仅如此,RGBTRIPLE sum 也不能 765 (3 * 255) 的值。

将像素求和到三个 intfloat 变量中,例如

int blue = 0;    // etc.

//...

image[i][j].rgbtBlue = round ((float)blue / count);   // cast before division