为什么我的CS50棕褐色过滤器不计算正确的像素值?

发布于 2025-02-12 03:46:21 字数 1501 浏览 0 评论 0原文

由于某种原因,我的棕褐色代码的数学部分似乎不起作用。运行Check50时会遇到错误,并且将所有像素值显示为太高。我三重检查过滤器的值,但一切似乎都不错。

    void sepia(int height, int width, RGBTRIPLE image[height][width])
    {
 float org_red = 0;
 float org_green = 0;
 float org_blue = 0;

for (int i = 0; i < height; i++)
    {
        for (int j = 0; j < width; j++)
        {
            org_red = image[i][j].rgbtRed;
            org_green = image[i][j].rgbtBlue;
            org_blue = image[i][j].rgbtGreen;

            long sepiaRed = (.393 * org_red + .769 * org_green + .189 * org_blue);
            long sepiaGreen = (.349 * org_red) + .686 * org_green + .168 * org_blue;
            long sepiaBlue = (.272 * org_red + .534 * org_green + .131 * org_blue);


            if (sepiaRed > 255)
            {
                sepiaRed = 255;
            }

            if (sepiaGreen > 255)
            {
                sepiaGreen = 255;
            }

            if (sepiaBlue > 255)
            {
                sepiaBlue = 255;
            }

            image[i][j].rgbtRed = round(sepiaRed);
            image[i][j].rgbtGreen = round(sepiaGreen);
            image[i][j].rgbtBlue = round(sepiaBlue);
        }
    }

    return;
}

我得到的错误说

:(棕褐色正确过滤单像素 预期的是“ 56 50 39 \ n”,而不是“ 84 75 58 \ n” :(棕褐色正确过滤简单3x3图像 期望“ 100 89 69 \ n100 ...”,而不是“ 100 88 69 \ n100 ...” :(棕褐色正确过滤更复杂的3x3图像 期望“ 25 22 17 \ n66 5 ...”,而不是“ 30 27 21 \ n71 6 ...” :(棕褐色正确过滤4x4图像 期望“ 25 22 17 \ n66 5 ...”,而不是“ 30 27 21 \ n71 6 ...”

for some reason the math portion of my sepia code does not seem to work. I get errors when I run check50, and it shows all the pixel values as being too high. I triple check the values for the filter but all seems good.

    void sepia(int height, int width, RGBTRIPLE image[height][width])
    {
 float org_red = 0;
 float org_green = 0;
 float org_blue = 0;

for (int i = 0; i < height; i++)
    {
        for (int j = 0; j < width; j++)
        {
            org_red = image[i][j].rgbtRed;
            org_green = image[i][j].rgbtBlue;
            org_blue = image[i][j].rgbtGreen;

            long sepiaRed = (.393 * org_red + .769 * org_green + .189 * org_blue);
            long sepiaGreen = (.349 * org_red) + .686 * org_green + .168 * org_blue;
            long sepiaBlue = (.272 * org_red + .534 * org_green + .131 * org_blue);


            if (sepiaRed > 255)
            {
                sepiaRed = 255;
            }

            if (sepiaGreen > 255)
            {
                sepiaGreen = 255;
            }

            if (sepiaBlue > 255)
            {
                sepiaBlue = 255;
            }

            image[i][j].rgbtRed = round(sepiaRed);
            image[i][j].rgbtGreen = round(sepiaGreen);
            image[i][j].rgbtBlue = round(sepiaBlue);
        }
    }

    return;
}

The error i get says

:( sepia correctly filters single pixel
expected "56 50 39\n", not "84 75 58\n"
:( sepia correctly filters simple 3x3 image
expected "100 89 69\n100...", not "100 88 69\n100..."
:( sepia correctly filters more complex 3x3 image
expected "25 22 17\n66 5...", not "30 27 21\n71 6..."
:( sepia correctly filters 4x4 image
expected "25 22 17\n66 5...", not "30 27 21\n71 6..."

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文