Image Steganography is the process of hiding secret data in some image. In this post, we will hide one image inside another and convert it into another image and then extract back both the images from the previous image.
The idea behind image-based Steganography is very simple. Images are composed of digital data (pixels), which describes what’s inside the picture, usually the colors of all the pixels. Since we know every image is made up of pixels and every pixel contains 3-values (red, green, blue).
For example, suppose we have to hide img2 in img1, where both img1 and img2 are
numpy nd array of pixel values. The size of img2 must be less than the size of img1. We are using color images, hence both will have 3 values (red, green, blue). Each pixel value varies from 0 to 255, so each pixel value is of 1 byte or 8 bits. Let
img[i][j][l] be the pixel value at location
(i, j) and of channel l where i varies from 0 to width and j varies from 0 to height and l varies from 0 to 2.
Note: The quality of the new images is a little bit less than the old images.
img2[i][j][l] be some pixel value of each image. Let v1 be 8 bits binary representation of
img1[i][j][l] and v2 be 8 bits binary representation of
v3=v1[:4]+v2[:4], where, v3 is the first 4 bits of v1 and v2. Then we assign
img1[i][j][l] to v3.
Here img1 is the final image produced after encoding.
img[i][j][l] be the pixel value of the image. Let v1 be 8 bits binary representation of
v2=v1[:4]+4 random bits and
v3=v1[4:]+4 random bits. Then we assign
img1[i][j][l] to v2 and
img2[i][j][l] to v3.
Here img1 and img2 are the final images produced after decoding.
Lets’ consider the images used are as follows:
We want to hide image2 in image1. Below is the implementation.
Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.
To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course.