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.
- Image based Steganography using Python
- Image Steganography in Cryptography
- Python | Image blurring using OpenCV
- Image Processing without OpenCV | Python
- Reading an image in OpenCV using Python
- Cartooning an Image using OpenCV - Python
- Image Translation using OpenCV | Python
- Image Resizing using OpenCV | Python
- Log transformation of an image using Python and OpenCV
- Image Pyramid using OpenCV | Python
- Image Registration using OpenCV | Python
- Python | Detect corner of an image using OpenCV
- Negative transformation of an image using Python and OpenCV
- OpenCV Python Program to blur an image
- Python | Detect Polygons in an Image using OpenCV
- OpenCV Python Program to analyze an image using Histogram
- Set Countdown timer to Capture Image using Python-OpenCV
- Find Circles and Ellipses in an Image using OpenCV | Python
- Python | OpenCV program to read and save an Image
- Create Local Binary Pattern of an image using OpenCV-Python
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. 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.