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.
- Image based Steganography using Python
- Image Steganography in Cryptography
- Early Evidence of Steganography
- OpenCV - Facial Landmarks and Face Detection using dlib and OpenCV
- Transition from OpenCV 2 to OpenCV 3.x
- Image resizing using Seam carving using OpenCV in Python
- OpenCV Python Program to analyze an image using Histogram
- Python Program to detect the edges of an image using OpenCV | Sobel edge detection method
- Reading an image in OpenCV using Python
- Python | Detect corner of an image using OpenCV
- Image Pyramid using OpenCV | Python
- Negative transformation of an image using Python and OpenCV
- Python | Image blurring using OpenCV
- Image Resizing using OpenCV | Python
- Find Circles and Ellipses in an Image using OpenCV | Python
- Image Translation using OpenCV | Python
- Image Registration using OpenCV | Python
- Python | Detect Polygons in an Image using OpenCV
- Create Local Binary Pattern of an image using OpenCV-Python
- Log transformation of an image using Python and OpenCV
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.