Assignment 2: Image Processing And Steganography
Part 3: Image Encoding (15 Points)
Chris Tralie
Due Friday 2/24
In the next part, you should create a program to hide your own text in images of your choice. Create a program encode.cpp
which takes in 3 command line arguments:
- A path to the image inside of which to hide the text
- A path to a text file containing the text you want to hide
- A path to the output image that will store the hidden text
For example, running the following to
should create a text file with the contents "Hello world"
, which is then hidden in the image hidden.png
, which is then decoded. So you should see "Hello world"
in your console when these are finished.
Of course, you should also test this on more examples of your own and visually ensure that the images with hidden text are indistinguishable from the originals.
NOTE: It is very important that you use a lossless image codec like .png
to save your images. If you use something lossly like jpeg, for example, it will destroy the information that you're putting in your image.
As a related note, you will notice that the file sizes of your files containing the hidden text are larger than the originals. This is because they are now storing information, and it makes it theoretically impossible to compress them more.
Hint on loading text
We haven't had much time to talk about file I/O in the class yet, so you can use the code snippet below to load a character string from a text file:
Other Ideas for The Bored
Here are some other things you can try if these ideas really excite you and you finish early. If you seriously pursue one of these, I may give you some extra credit
- One thing that makes this a little bit easier to detect programmatically (and hence less "secure" for embedding messages) is the fact that we take bits in "scanline order" from left to right, top down. You could add some randomness here by using the LFSR to choose the row and column of the next bit to use, in addition to using it to encrypt the bits themselves.
- Embedding the data as we have does have a statistically significant effect on the histogram of the RGB values. See if you might make subtle changes to the pixels that don't hide data to preserve the histogram of the original image as well as possible.
- We don't visually notice the difference by changing the least significant bit, but we probably also won't notice the difference of changing the least two significant bits (both the 1's place and the 2's place). This will double the information capacity of the image. What is the limit of this? Is 3 bits still invisible? 4 bits? Explore this.
- We were hiding ASCII text in this example, but you can hide any sequence of bits this way. Modify the program so that it encrypts any other file you specify in binary, and see if you can hide a small mp3 audio clip in your image, especially if you are able to increase the information capacity as suggested in the above point.