深褐色滤镜CS50第4周

问题描述 投票:-4回答:1

我需要在我的代码上用下面的公式创建一个将彩色图像转换为深褐色滤镜的滤镜。这是一个CS50第4周的问题集。

我不明白当我运行check50时出现的错误。请看下面我的代码和我得到的错误。代码是有意义的,并且返回了预期的RGB值,但我在check50上仍然得到两个错误。

sepia正确过滤单个像素 :) sepia正确过滤简单的3x3图像 :( sepia正确过滤更复杂的3x3图像,预期的是 "25 22 17\n/66 5...",而不是 "25 22 17\n/66 5..."。- ERROR HERE :( 深褐色正确过滤4x4图像预期 "25 22 17\n66 5...",而不是 "25 22 17\n66 5..." - 这里的错误:(sepia正确过滤4x4图像,预期是 "25 22 17 N66 5...",而不是 "25 22 17 N66 5..."。// Convert image to sepia
void sepia(int height, int width, RGBTRIPLE image[height][width])
{
    float sr = 0;
    float sg = 0;
    float sb = 0;

    for (int i = 0; i < height; i++)
    {
        for (int j = 0; j < width; j++)
        {
            sr = (0.393 * image[i][j].rgbtRed + 0.769 * image[i][j].rgbtGreen + 0.189 * image[i][j].rgbtBlue);
            sg = (0.349 * image[i][j].rgbtRed + 0.686 * image[i][j].rgbtGreen + 0.168 * image[i][j].rgbtBlue);
            sb = (0.272 * image[i][j].rgbtRed + 0.534 * image[i][j].rgbtGreen + 0.131 * image[i][j].rgbtBlue);

           image[i][j].rgbtRed = round(sr);
           image[i][j].rgbtGreen = round(sg);
           image[i][j].rgbtBlue = round(sb);
        }
    }

    for (int i = 0; i < height; i++)
    {
        for (int j = 0; j < width; j++)
        {
           if (image[i][j].rgbtRed > 255)
           {
               image[i][j].rgbtRed = 255;

           }

            if (image[i][j].rgbtGreen > 255)
           {
               image[i][j].rgbtGreen = 255;

           }

            if (image[i][j].rgbtBlue > 255)
           {
               image[i][j].rgbtBlue = 255;

           }

        }

    }

    return;

}
c rgb cs50
1个回答
0
投票
sr = (0.393 * image[i][j].rgbtRed + 0.769 * image[i][j].rgbtGreen + 0.189 * image[i][j].rgbtBlue);
sg = (0.349 * image[i][j].rgbtRed + 0.686 * image[i][j].rgbtGreen + 0.168 * image[i][j].rgbtBlue);
sb = (0.272 * image[i][j].rgbtRed + 0.534 * image[i][j].rgbtGreen + 0.131 * image[i][j].rgbtBlue);

对于这部分,你需要限制像素颜色超过255。你可以做一个这样的函数

int limit(int RGB)
{
    if (RGB > 255)
    {
        RGB = 255;
    }
    return RGB;
}

来限制它。你还必须使用圆角功能对深褐色进行圆角处理

© www.soinside.com 2019 - 2024. All rights reserved.