CPSC120
Fundamentals of Computer Science

In-class Activity 31

  1. Create a Python program that writes a new ppm file that is a half scale version of a ppm file that is specified as a command line argument. An image can be scaled to half as large by averaging squares of four pixels to produce one new pixel. Assume that the input image has even dimensions. Use the ppm.py module for reading and writing ppm files.

  2. Create a Python program that writes a new ppm file that is an edge map of a ppm file that is specified as a command line argument. An edge map of an image is an image that contains white pixels where there is an edge and black where there is not an edge. An edge can be detected by checking if the absolute value of the difference between grayscale values of a pixel and its neighbor exceeds a threshold. A larger threshold will detect more edges. Use the ppm.py module for reading and writing ppm files.