- This topic is empty.
-
AuthorPosts
-
January 12, 2026 at 4:46 am #5936
Context (Code First)
In LSB-based image steganography, we recover a hidden black-and-white image using this kind of code:
from PIL import Image def extract_end_bits(num_end_bits, pixel): return pixel % (2 ** num_end_bits) def reveal_bw_image(filename): img = Image.open(filename) width, height = img.size pixels = img.load() secret_img = Image.new("L", (width, height)) secret_pixels = secret_img.load() for x in range(width): for y in range(height): hidden_bit = extract_end_bits(1, pixels[x, y]) secret_pixels[x, y] = hidden_bit * 255 return secret_imgThis raises an important question.
❓ Q: Why is the hidden image the same size as the original image?
Answer:
Because each pixel of the original image stores exactly one hidden bit.
Every pixel in the carrier image contains:
- Most bits → visible image data
- Last bit (LSB) → hidden image data
So if the carrier image is:
Width = 300 pixels Height = 200 pixels Total pixels = 60,000Then it contains 60,000 hidden bits — one for each pixel.
When we extract those bits and place them back into a grid, they naturally form another image of size:
300 × 200That is why we create the secret image with:
secret_img = Image.new("L", (width, height))
❓ Q: How does one pixel hide one pixel of the secret image?
Answer:
A black-and-white image pixel is just one bit:
0→ black1→ white
So the secret image pixel fits perfectly inside the LSB of a normal image pixel.
Example:
Carrier Pixel Binary Hidden Bit 142 100011100143 100011111When we extract:
hidden_bit = pixel % 2we recover that hidden black/white value.
❓ Q: How does the code rebuild the hidden image?
Answer:
This line:
hidden_bit = extract_end_bits(1, pixels[x, y])extracts one hidden bit from each pixel.
Then:
secret_pixels[x, y] = hidden_bit * 255converts it into:
0 → black255 → white
This fills the new image pixel-by-pixel, reconstructing the secret image.
🧠 Final Takeaway
The hidden image has the same size as the carrier image because each carrier pixel stores exactly one hidden image pixel bit.
This is what makes LSB steganography so powerful — it hides an entire image without changing the visible one in a noticeable way.
-
AuthorPosts
- You must be logged in to reply to this topic.

