PPM Image Editor

Joshua T. Guerin and Debby Keen
University of Kentucky
{jtguer2, keen}@uky.edu

Assignment Overview

Programs with graphical elements are often a favorite for intro level computer science courses, however they often require language-dependant graphics libraries or "black-box" style code provided by the instructor. This assignment gives students the ability to implement photoshop-style effects at the pixel level with minimal knowledge of image processing.

This assignment leverages the relative simplicity of the PPM image format, allowing students to deal only with plaintext file editing. This gives the student the experience of creating powerful image filters completely from scratch, without specific language requirements or the requirement of any additional libraries.

Meta Information

Summary Read PPM image from file an ASCII file, alter RGB elements of each pixel, and print resulting image to a new file. Students will gain an understanding of basic image processing techniques, and an appreciation for image editing software that they may already use.
Topics
  • ASCII file input/output.
  • Loops
  • Conditionals
  • Functions (optional but probably desirable)
  • Arrays/2D arrays (optional for CS1 or later, allows for greater range of effects to be employed).
  • Image processing techniques
Audience
Appropriate for CS1, CS2, or later courses.
Difficulty
This is an intermediate to advanced assignment, taking about 2 weeks for a CS1 student.
Strengths
  • Platform independant
  • Language independant
  • No graphics libraries needed
  • Easy to code
  • Assignment can be adapted to a variety of difficulty levels, requiring (in the simplest form) only file/IO, variables, and arithmetic
  • Students get a glimse under the hood of considerably more complex graphics editing software
  • Assignment gives the students the feeling that they are solving a practical, real-world computing problem.
Weaknesses
While the assignment may be simple to implement, students may have apprehension about tackling (what seems to be) a larger task than most intro assignments.
Dependancies
No language/library dependancies for student code. This assignment has been used in our departmetn in C++ and Python, but any language should suffice.

The PPM image format is completely uncompressed, an therefore is often not employed in the real-world. Students will need software to view thte PPM images, should be available for any operating system. We have found solutions for several operating systems for viewing/saving PPM images (this list is not exhaustive):
Windows: Irfanview (shareware)
Apple: Graphic Converter (came bundled with some versions of OS X)
Linux: GIMP
Cross-platform: GIMP, Photoshop (available as a free 30-day trial)

Our program uses Windows computers for CS1 or 2, and we had no problems with Irfanview.
Variants
Simple effects (requirements: loops, conditionals, file I/O):
Color inversion, conversion to greyscale, contrast effects, brightness adjustment, random noise (requires random numbers, but is still pretty easy).
Arrays can be avoided for simple effects because only one pixel needs to be in memory at a time (int R, G, B).

Intermediate effects (additional requirements: arrays):
flip image vertical, flip image horizontal, horizontal blur
Intermediate effects require a horizontal slice of an image, or an entire image to be stored in memory at once (int R[MAX_WIDTH], G[MAX_WIDTH], B[MAX_WIDTH])

Advanced effects (additional requirements: 2D arrays)
Vertical blur, bidirectinoal blur.


For CS2 or greater level programs, this would make a great introduction to nested classes.

The effects listed are just for example, students and instructors may come up with a variety of interesting additional effects. For instance, using only simple arithmetic instructors could add an advanced/bonus feature of applying effects to only a portion of the images (every nth row, every nth column, specific quadrants, etc.).

Example Effects

Note: Base image and resulting images were originally in PPM format. Effects were generated by a C++ program. These images have been converted to jpg format to ensure that they render in a web browser.

Click any image to enlarge.
Base Image (no effects)
Flip Vertical
Greyscale
Invert RGB
Zero-out GB
Extreme contrast
Horizontal blur
Random noise

For Instructors

Assignment

Sample version of an assignment which may be given to students: image_editor.html.
Sample grade sheet: image_editor_gradesheet.html
Our sample assignment assumes the use of arrays, and we introduced the concept of buffering by requiring that arrays have a max length of 3000 integers.

Full-Sized PPM Sample Images

Images compress well because they are plaintext, but full sized images may easily be 4-5 MB.
sample inputs in PPM format (includes cake.ppm): ZIP Archive (1.2 MB)
sample outputs in PPM format: ZIP Archive (5.1MB)

Frequently Asked Questions

Q: Was that a real slice of cake?
A: Yes.

Q: Did you eat it?
A: Yes.

Q: Was it delicious?
A: Yes.


Extra info about this assignment: