Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Desaturate an Image In this lab you will desaturate an image. That is, you will change it from colorful to black and white. What makes

image text in transcribedimage text in transcribed

Desaturate an Image In this lab you will desaturate an image. That is, you will change it from colorful to black and white. What makes a digital image greyscale? We see white on a digital display when Red, Green and Blue components of a pixel are all on as bright as possible: all set to 255. We see black when Red, Green and Blue are all off: all set to 0. In between white and black is grey. For any lightness of grey, the Red, Green and Blue channels are equal to each other, and can be anywhere in the range from 1 (very, very dark grey) to 254 (almost white). You can desaturate a colored image by averaging the Red, Green and Blue pixel values at each pixel location in the image. Implement the Desaturate function We've provided code to get an image file from the user over the command line, load it, display it, and save it as output.bmp . All you need to do is fill in the body of the function Desaturate in desaturate.cc. You will need to loop (hint: use for loops) over every pixel in the image and desaturate them one by one. Some helpful functions you can call on a graphics:: Image are: // Returns the width and height of the image. int GetWidth(); int GetHeight(); // 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); Here's how these can be used: Here's how these can be used: // Gets the width of the image. int width - image. GetWidth(); 1/ Gets the height of the image. int height = image. GetHeight(); // 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); You can learn more about using graphics::Image in the Intro to Images walk-through. Run the program to desaturate images To manually test Desaturate you can compile and run this program with: clang++ -std=C++17 main.cc desaturate.cc cpputils/graphics/image.cc -o main -lm -1x11 -1pthread ./main Note: you need a few additional flags on Mac However, that's a lot to type, so we've included a shortcut to compile and create main : make build ./main We've provided a .bmp format image for you at input.bmp, but you are welcome to try this on your own images! Lightshot Screenshot is s Click here to o Desaturate an Image In this lab you will desaturate an image. That is, you will change it from colorful to black and white. What makes a digital image greyscale? We see white on a digital display when Red, Green and Blue components of a pixel are all on as bright as possible: all set to 255. We see black when Red, Green and Blue are all off: all set to 0. In between white and black is grey. For any lightness of grey, the Red, Green and Blue channels are equal to each other, and can be anywhere in the range from 1 (very, very dark grey) to 254 (almost white). You can desaturate a colored image by averaging the Red, Green and Blue pixel values at each pixel location in the image. Implement the Desaturate function We've provided code to get an image file from the user over the command line, load it, display it, and save it as output.bmp . All you need to do is fill in the body of the function Desaturate in desaturate.cc. You will need to loop (hint: use for loops) over every pixel in the image and desaturate them one by one. Some helpful functions you can call on a graphics:: Image are: // Returns the width and height of the image. int GetWidth(); int GetHeight(); // 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); Here's how these can be used: Here's how these can be used: // Gets the width of the image. int width - image. GetWidth(); 1/ Gets the height of the image. int height = image. GetHeight(); // 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); You can learn more about using graphics::Image in the Intro to Images walk-through. Run the program to desaturate images To manually test Desaturate you can compile and run this program with: clang++ -std=C++17 main.cc desaturate.cc cpputils/graphics/image.cc -o main -lm -1x11 -1pthread ./main Note: you need a few additional flags on Mac However, that's a lot to type, so we've included a shortcut to compile and create main : make build ./main We've provided a .bmp format image for you at input.bmp, but you are welcome to try this on your own images! Lightshot Screenshot is s Click here to o

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Intranet And Web Databases For Dummies

Authors: Paul Litwin

1st Edition

0764502212, 9780764502217

More Books

Students also viewed these Databases questions

Question

What does Processing of an OLAP Cube accomplish?

Answered: 1 week ago