To gain experience with C++ programming including classes, multi-dimensional arrays, program parameters, and the UNIX environment.
For this program, you will write a program that converts images from full color into grayscale.
Most image file formats write the image data in binary, and utilize compression in order to keep the file sizes small. Unfortunately, this makes reading them in quite difficult. In contrast, the PPM image format is textual and quite simple and easy to work with.
A PPM image file contains the following:
To convert an image to grayscale, you can simply average the red, green and blue values for a given pixel, then write that value over the red, green and blue values.
For example, if a pixel has a red value of 250, a green value of 100, and a blue value of 10, it will be a bright orange color. If we wish to convert the color to grayscale, we average 250, 100 and 10 which gives us 120. If we set the red, green and blue values all to 120, we get a gray color roughly as bright as the orange.
If we apply this process to each of the pixels in the image, it will be grayscale.
|Input Image||PNG Version||Expected Output||PNG Version|
In order to test your program's output, you will need to view the images. It will be easiest to first convert them from the PPM image format into a more common one, such as PNG. To do this on Linux, you can use the convert command:
$ convert grayscale.ppm grayscale.png
You can then do one of the following:
View Them in the B13 Lab
If you are in the B13 lab computers, you can simply open a file browser, navigate to the directory where your program is, and open the image file.
Copy Them to Your Local Machine
You can use a file transfer program (such as FileZilla) to connect to cs, and copy the files to your local machine to view them.
View Them Over the Web
You can create a directory in your home directory called 'public_html', and place the image files there. You can then view the image files with a web browser by navigating to "cs.umw.edu/~username/grayscale.png".
If you have trouble with any of these, please let me know. It is heavily recommended to start the assignment early so that you can be sure you can test your program!
For extra credit, you can perform any other kind of image manipulation effect you wish. Examples might include flipping the image, lightening, darkening, applying Instagram-like filters etc. If you complete an extra credit effect, you should write the modified image to a file called "extra.ppm". You also must briefly describe the effect in your email submission.
When you are done, submit your program by emailing your code to email@example.com.
Copyright © 2018 Ian Finlayson | Licensed under a Creative Commons Attribution 4.0 International License.