Mar 14, 2025 | 385 words | 4 min read
11.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 this task in tp1_team_2_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 top to bottom down the image, and then left to right across the image, extract each pixel’s LSB. If the pixel is a color image, extract the LSB (0 or 1) from each color channel: first Red, then Green, and finally Blue. Concatenate the LSBs (0s and 1s) to form a single binary string.
Our hidden message is contained within this long binary string of LSB values. To locate it, find the start and end sequence in this binary string and the hidden message will be the binary data 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 11.6 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 11.7 below to test your program.
Case |
image_path |
start_seq |
end_seq |
|---|---|---|---|
1 |
ref_col_p.png |
123 |
*&^ |
2 |
ref_gry_p.png |
abc |
789 |
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: 123 Enter the end sequence: *&^ Extracted Message: 011100110110010101100011011100100110010101110100
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: abc Enter the end sequence: 789 Extracted Message: 0110100001100101011011000110110001101111
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.
Deliverables |
Description |
|---|---|
tp1_team_2_teamnumber.py |
Your completed Python code. |
tp1_team_2_teamnumber.pdf |
Flowchart(s) for this task. |