APCS: Image Processing Project, Activity 10
This exercise offers an introduction to steganography, which is the science of hiding information in images.
The leftmost image above is the original image. The middle image, which displays the message "Meet me at 3:00pm!", is added to the original image. The result is the final image, which looks much like the original image, but it has the message embedded in it.
The encode method
The first step in encoding the message in the image is to visit each of the pixels in the original image. (This can be done by working inside 2 nested for loops.) If the pixel's value of red is an odd number, decrement by 1 the red value. Then, still within the same nested loops, examine the pixel at the same position in the image that contains the message. If this pixel contains a substantial amount of black (meaning that it is part of the message) then increment by 1 the value of red in the original image. To determine if a pixel has a lot of black, you might use the ColorDistance method of the Pixel class.
The result will be an image in which the pixels with even values of red have nothing to do with the embedded message. At the same, pixels with odd values of red are associated with the embedded message.
The decode method
Create an empty Picture in this way: Picture msg = new Picture(height, width);
Step through the pixels of the modified image. If a pixel's red value is odd, color the associated pixel in 'msg' to be black.
The embedded message should then be extracted from the modified image.
The static method testEncodeAndDecode, in PictureTester, looks like this:
public static void testEncodeAndDecode()
Picture pic = new Picture("Your Path Here / beach.jpg");
Picture picMsg = new Picture("Your Path Here / msg.jpg");
Picture decoded = pic.decode();
Image Processing Project
AP Computer Science