Answered step by step
Verified Expert Solution
Question
1 Approved Answer
C++ using std Need some starter code how to change the image from color to black and white in the nested for loops There contain
C++ using std
Need some starter code how to change the image from color to black and white in the nested for loops
There contain three files.
desaturate.cc
#include "desaturate.h" void Desaturate(graphics::Image& image) { // Your code here to desaturate the 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; // Gets the red channel of the center pixel. int red = image.GetRed(width / 2, width / 2); // Sets the blue channel of the center pixel to be equal to the red one. image.SetBlue(width / 2, width / 2, red); } }
----------------------
desaturate.h
#include "cpputils/graphics/image.h" void Desaturate(graphics::Image& image);
--------------------
main.cc
#include#include #include "desaturate.h" int main() { // You do not need to edit this file. std::cout << "Enter the filename of an image to desaturate: "; std::string filename; std::cin >> filename; graphics::Image image; if (!image.Load(filename)) { std::cout << "Could not load the image " << filename << std::endl; return 1; } Desaturate(image); image.ShowUntilClosed(); image.SaveImageBmp("output.bmp"); return 0; }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started