我在cs50(filter-more)的习题集4中卡住了模糊函数,我不知道为什么最后得到的照片是非常奇怪的

bvn4nwqk  于 2023-08-03  发布在  其他
关注(0)|答案(1)|浏览(119)

这是Problem Set 4 Filter-more
这是我的代码。

// Blur image
void blur(int height, int width, RGBTRIPLE image[height][width])
{
    RGBTRIPLE temp[height][width];
    // for the calculation of the averages of RGB values
    BYTE blue_sum, green_sum, red_sum;
    float counter;
    // inclusive lower and upper bounds
    int lower_bound_row, upper_bound_row, lower_bound_col, upper_bound_col;
    for (int i = 0; i < height; i++)
    {
        lower_bound_row = (i - 1 < 0)? i : i - 1;
        upper_bound_row = (i + 1 == height)? i : i + 1;
        for (int j = 0; j < width; j++)
        {
            blue_sum = 0; green_sum = 0; red_sum = 0;
            counter = 0.00;
            lower_bound_col = (j - 1 < 0)? j : j - 1;
            upper_bound_col = (j + 1 == width)? j : j + 1;

            // Adding the color values of neighboring pixels
            for (int a = lower_bound_row; a <= upper_bound_row; a++)
            {
                for (int b = lower_bound_col; b <= upper_bound_col; b++)
                {
                    blue_sum += image[a][b].rgbtBlue;
                    green_sum += image[a][b].rgbtGreen;
                    red_sum += image[a][b].rgbtRed;
                    counter++;
                }
            }
            // Dividing the sums by no. of neighing pixels to calculate the averages
            temp[i][j].rgbtBlue = round(blue_sum / counter);
            temp[i][j].rgbtGreen = round(green_sum / counter);
            temp[i][j].rgbtRed = round(red_sum / counter);
        }
    }
    for (int i = 0; i < height; i++)
    {
        for (int j = 0; j < width; j++)
        {
            image[i][j] = temp[i][j];
        }
    }
    return;
}

字符串
我尝试使用debug 50,但我不能跟踪每个像素的rgb值,所以我不能找出什么是错的。感谢任何试图帮助我们的人!谢谢你,谢谢

jjjwad0x

jjjwad0x1#

谢谢你退休的忍者帮我!!最后只需要将blue_sum,绿色_sum和red_sum数据类型改为int就可以了:D

相关问题