【问题标题】:Need some initial direction with cs50 Filter Grayscale需要cs50滤镜灰度的一些初始方向
【发布时间】:2020-09-29 02:25:00
【问题描述】:

我正在尝试解决滤镜灰度的问题,但在开始之前我正在苦苦挣扎。

对于灰度,我们给出的公式是平均 RGB 的值,然后将该值用作每个像素的新 RGB 值。平均后如何更新像素中的值?

我想我可以创建一个布尔值 Replace 并将其设置为 false,然后在替换后将其设置为 true,但现在我认为我忽略了一些更简单的东西。

当我不知道除了'height -1'行之外还有多少行时,我如何将图像视为一个数组。

作业视频将像素格式示例描述为:

image[2][3].rgtbBlue
image[2][3].rgbtGreen
image[2][3].rgbtRed

这是否意味着

((BYTE.rgbtBlue + BYTE.rgbtGreen + BYTE.rgbtRed) /3)

无法获得平均值?

这行得通吗?

for (int i = 0; i < height -1; i ++)
{
   for (int j =0; j < height; j++)
    {
        image[i][j].rgbtBlue = round(((BYTE.rgbtBlue+ BYTE.rgbtGreen + BYTE.rgbtRed) /3));
        image[i][j].rgbtGreen = round(((BYTE.rgbtBlue+ BYTE.rgbtGreen + BYTE.rgbtRed) /3));
        image[i][j].rgbtRed = round(((BYTE.rgbtBlue+ BYTE.rgbtGreen + BYTE.rgbtRed) /3));
     }
}

【问题讨论】:

    标签: c filter cs50 grayscale


    【解决方案1】:
    void grayscale(int height, int width, RGBTRIPLE image[height][width])
    {
    // Locate the pixel
        for (int i = 0; i < width; i++)
        {
            for (int j = 0; j < height; j++)
            {
    // Find the average pixel color
                float avgpixel = round((image[j][i].rgbtBlue + image[j][i].rgbtGreen + image[j][i].rgbtRed) / 3.00);
    // Replace the grayscale pixel to all colors
                image[j][i].rgbtBlue = avgpixel;
                image[j][i].rgbtGreen = avgpixel;
                image[j][i].rgbtRed = avgpixel;
            }
        }
        return;
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-12-31
      • 1970-01-01
      • 1970-01-01
      • 2016-01-06
      • 2014-02-11
      • 2018-02-18
      • 1970-01-01
      相关资源
      最近更新 更多