In this assignment you will be completing a .ppm reader and writer, with some basic image manipulation. You will be getting used to writing programs in C++, while practicing some basic image manipulation to learn about image representation.
You will first need a .ppm image to work with and a .ppm viewer. You may use your favorite .ppm converter/image viewer, but I recommend using Gimp (there are Windows and Mac installs). Using Gimp, you must export your image to save it as a .ppm, (using the ASCII format.)
Once you have created a .ppm image, you should familiarize yourself with the .ppm image format here.
Assignment
Copy the code from C++_0 to your computer. Make sure you COPY the files and do not edit the file in dropbox. You are given the files, main.cpp, ImageIO.cpp, ImageIO.h., and a ppm image. This ppm image is a little boring, so I recommend you chose a different one, although you can test with this one. You will be adding code to main.cpp, ImageIO.cpp, and ImageIO.h to complete the .ppm reader/writer and to add some image manipulation.
Step 1: Change the file path in main.cpp to point to your .ppm image and run the program. If you have any errors, either your .ppm image was not created correctly, or you do not have the correct path in your ImageIO constructor. Make sure to fix any errors here before proceeding.
Step 2: (You do not need to complete this step to work on Steps 3-6) Wouldn’t it be nice if you had a way to view your image without having to open your ppm file? Why, yes!
The glDrawPixels call in drawImage will read pixel data from memory and write it to the framebuffer. The problem is that your pixel data needs to be in a 1D array starting at the bottom left corner of your image! For example, if the bottom left pixel was red, and the pixel to the right was green, your 1D array would start [1 0 0 0 1 0].
Complete the code in getImageDisplayArray
that converts your 3D array in
image
to a 1D array.
To test this, you will need to uncomment the OpenGL calls in main
.
Step 3: The code reads in the .ppm image found in the path file_name
in the ImageIO(const char* file_name)
constructor. Complete the function writeImage(const char* file_name)
, that writes the image information saved in image
to file_name
. The function has been started for you.
Add the call the_image->writeImage(your_file_path_here)
in main.
Your output image should look the same as the image you read in.
Step 4: Complete the function removeRed which removes all of the red from your image. To remove the red from your image, you should make all of the red pixel values zero.
Step 5: Add the function grayScale which makes a gray scale version of your image. You will need to define grayScale in ImageIO.h. To make a pixel gray, the red, green, and blue values for a pixel should be the same value. To determine a pixel’s luminance we will use the coefficients for human color perception. Humans are very sensitive to green and not very sensitive to blue.
Y = 0.2126R + 0.7251G + 0.0722B
Step 6: Create your own image processing function. You will need to add code to both ImageIO.h and ImageIO.cpp. Here are some options, but you may choose something that is not on this list. You must add comments above your function in ImageIO.cpp so that I fully understand how your function works.
- Color manipulation
- Composite of two images
- Scale the image
Hand in
In your DropBox folder, create the folder C++_1 and hand in main.cpp, ImageIO.cpp, ImageIO.h, (if you are using xCode, please also submit your .xcodeproj) your original .ppm image, and the three .ppm images you created with your code: no red, gray scale, and your choice for image processing. If you needed additional images for your final image processing, hand those images in as well.
Grading
Code (24 points)
Steps 2-6 will each be graded with the following scale. Step 6 will be multiplied by 2.
4 (A) | Completes all criteria, is creative, shows extensive effort (for part 6), clean code |
3 (B) | A mostly working solution, but lacks clean code or something minor |
2 (C) | Missing something major. A not fully working solution |
1 (D) | You handed something in |