首页 > 解决方案 > 如何将图像从彩色去饱和到黑白?

问题描述

我一直在使用我的代码来更改图像的颜色,但我不知道在嵌套的 for 循环中下一步该做什么?

到目前为止,我只有平均图像中每个像素位置的红色、绿色和蓝色像素值。

谁能帮助/建议我下一步该怎么做?

#include "desaturate.h" 
void Desaturate(graphics::Image &image) {

  // Returns the width and height of the image.
  int GetWidth();
  int GetHeight();

  // Create variable
  int red;
  int green;
  int blue;

  // Gets the red, green or blue pixel value at an (x, y) pixel location.
  int GetRed(int x, int y);
  int GetGreen(int x, int y);
  int GetBlue(int x, int y);

  // Sets the red, green or blue pixel value at an (x, y) pixel location.
  bool SetRed(int x, int y, int red);
  bool SetGreen(int x, int y, int green);
  bool SetBlue(int x, int y, int blue);

  // Gets the width of the image.
  int width = image.GetWidth();
  // Gets the height of the image.
  int height = image.GetHeight();

  for (int i = 0; i < width; i++) {
    for (int j = 0; i < height; j++) {
      int average = (red + green + blue) / 3;

      // What should I do next for this part?
    }
  }

标签: c++image-processing

解决方案


推荐阅读