CSc 110: Hidden Messages

This assignment should be written in the python programming language. You should only use python features that we have discussed up to this point. If you have questions about whether or not a particular feature can/should be used, ask the instructors! You may use any python version 3.0 or newer.

All of your programming should be well-formatted and easy for the graders to read and comprehend. Each program file should have a header comment at the top that has the following format:

#
# Author: Student Name
# Description:
#    A short description of what this program does!
# 

If any part of your scripts are particularly complex, you should put documentation comments above those lines of code.

Hidden Messages

We briefly discussed the PPM (sometimes also referred to as pbm) image format in class. If you need a refresher on the format, take a look at the course materials. You may also find these resources useful:

The first line of a ppm file specifies the exact format. the second line specifie the maximum RGB value, and the third specifies the width and height. Technically, comment lines starting with # are allowed in a PPM image, but you may assume that the PPM images will not have any comments. From the fourth line and on, the ASCII representation of each red, green, and blue pixel value in the image in represented in text. For the purposes of this assignment, you may assume that:

In this assignment, you will be writing a program that reads in a ppm image and extracts hidden messages from them.

In total, your program should read in 3 different input values, using input(). The first shall be the name of the file containing the ppm image to find the message in. The second will the name of a (new) file to save the modified image into. The third will request the color channel to extract (red, green, or blue). You should use the input() function to grab these values. An example of reading these values in looks like the following:

Select an image file: input.ppm
Select an output file: out.ppm
Channel: green
...

If the last value is not red, green, or blue, you should report a complaint to the console and then exit the program.

Using these values, your program hidden.py will extract the hidden message from the provided color channel. For each pixel, you should check the brightness value of the color that corresponds to the channel. If the value is non-zero, make the value of the pixel the max (255). If it is zero, leave as-is. The brightness values of the remaining channels should be changed to zero for all pixels. If an image with a hidden message is passed into the program, this will reveal it.

The original image should remain un-modified. The adjusted image will be written to the output file.

You must use 2D lists to represent the rows and columns of the text images!


Examples


PPM images generally do not render well in a browser. In the below examples, I’m going to show you PNG versions of the output I expect you to generate with PPM images. The actual output of running your program should be PPM images.

The class diff-testing tool was not designed to test graphical outputs like this. Instead, use the examples below to check that your program is working correctly.

Small Example

Below is a PNG version of a very small 8x8 PPM image which can be downloaded here:

In first glance, there appears to be nothing interesting about this image. However, throughout the image there are some slight variations in the green values of each pixel. Thus, if you were to run a working hidden.py with the following options:

Select an image file: small.ppm
Select an output file: small-green.ppm
Channel: green

small-green.ppm would looks like the following, revealing the secret message “YO” embedded in this image:

However, Running the same image through hidden.py with the blue and red channels would not reveal the message. This is the output you should see for blue:

… and for red:

Example 1

Below is a PNG version of a PPM image which can be downloaded here:

In first glance, there appears to be nothing interesting about this image. However, throughout the image there are some slight variations in the blue values of each pixel. Thus, if you were to run a working hidden.py with the following options:

Select an image file: message-1.ppm
Select an output file: message-1-blue.ppm
Channel: blue

message-1-blue.ppm would looks like the following, revealing the secret message embedded in this image:

However, Running the same image through hidden.py with the green and red channels would not reveal the message. This is the output you should see for green:

… and for red:

Example 2

Below is a PNG version of a PPM image which can be downloaded here:

As with the previous example, there is a hidden message embedded in one of the channels of this image (the red channel this time). Running the following:

Select an image file: message-2.ppm
Select an output file: message-2-red.ppm
Channel: red

message-2-red.ppm would looks like the following, revealing the secret message embedded in this image:

However, Running the same image through hidden.py with the green and blue channels would not reveal the message. This is the output you should see for green:

… and for blue:

Example 3

Let’s walk through another example, using this PPM image. Here is the original image:

As with the previous example, there is a hidden message embedded in one of the channels of this image (again, the red channel). Running the following:

Select an image file: message-3.ppm
Select an output file: message-3-red.ppm
Channel: red

Would reveal this hidden message in this image:

Again, Running the same image through hidden.py with the green and blue channels would not reveal the message. This is the output you should see for green:

… and for blue:

Submission and grading

It is due on Tuesday, 8/1/2017, at 7:00pm.

You should put all of your code in to a python file named hidden.py. Submit hidden.py to the associated D2L dropbox. Following these turn-in and naming instructions closely is very important, because our grading scripts will depend on some of the details. You may lose points if these instructions are not followed precisely!