How could I desaturate the image from color to black and white?

  c++, image-processing

I have been working with my code for changing the color of image but I did not know what to do next in the nested for loop? Only what I have so far is averaging the Red, Green and Blue pixel values at each pixel location in the image. Anyone can help/suggest me what should I do next?

#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();

  // 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?
    }
  }

Source: Windows Questions C++

LEAVE A COMMENT