Dec 03, 2024 | 368 words | 4 min read
9.2.2. Task 2#
Learning Objectives#
Extract a binary message from an image using the Least Significant Bit (LSB) technique.
Task Instructions#
Save the flowcharts for each of your tasks in tp1_team_teamnumber.pdf You will also need to include these flowcharts in your final report.
Write Python code that will extract binary data from the Least Significant Bit (LSB) of each pixel’s value in an image. This binary data contains a hidden message. Name this program tp1_team_2_teamnumber.py. Utilize the code you wrote in Task 1 to import and scale the image data before processing.
The encoded message starts and ends with specific sequences (provided in text form). Convert these sequences from text to binary to match the binary format used in the image. You may want to write a function to do this conversion.
Starting from the upper left corner, and proceeding left to right across the image, and then top to bottom down the image, extract each pixel’s LSB(s). If the pixel is a color image, extract the LSBs from each color channel: first Red, then Green, and finally Blue. Concatenate the LSBs to form a single binary string.
The LSB values between the start and end sequence contain our hidden message. Locate the start and end sequences in the binary data to extract and display the bits in between. If the start or end sequence is not found, print an error message.
Note
Your code should be able to handle the case where the start and end sequences are the same. To handle such a case, look for end sequence only after the index where start sequence was already found.
Organize your code to use functions that break up the task into manageable pieces. Use the files provided in the Table 9.16 to test your code.
Image File Name |
Description |
---|---|
A color image with a hidden message |
|
A grayscale image with a hidden message |
Sample Output#
Use the values in Table 9.17 below to test your program.
Case |
image_path |
start_seq |
end_seq |
---|---|---|---|
1 |
ref_col_p.png |
007 |
700 |
2 |
ref_gry_p.png |
007 |
700 |
3 |
ref_gry_p.png |
000 |
777 |
Ensure your program’s output matches the provided samples exactly. This includes all characters, white space, and punctuation. In the samples, user input is highlighted like this for clarity, but your program should not highlight user input in this way.
Case 1 Sample Output
$ python3 tp1_team_2_teamnumber.py Enter the path of the image you want to load: ref_col_p.png Enter the start sequence: 007 Enter the end sequence: 700 Extracted Message: 0100110001010101010000110100101101011001
Case 2 Sample Output
$ python3 tp1_team_2_teamnumber.py Enter the path of the image you want to load: ref_gry_p.png Enter the start sequence: 007 Enter the end sequence: 700 Extracted Message: 0100100001000101010011000100110001001111
Case 3 Sample Output
$ python3 tp1_team_2_teamnumber.py Enter the path of the image you want to load: ref_gry_p.png Enter the start sequence: 000 Enter the end sequence: 777 Start or end sequence not found in the image.