Nuances of tucking images inside another –Steganography!

Let us start by elucidating with a small instance where this process that you will learn of by the end of the article was used in a Python class. Furthermore, this article deals with the understanding of how to insert an image in another so that it is hidden, with a few concepts on image processing. In order to gain a sound understanding of what’s to come we start by understanding aspects such as, color models, pixels, steganography, and digital images.

Meaning of Steganography:

To put it simply, what steganography means is to carry out measures of hiding a message, file, video or an image contained inside one more image, file, video or message.

How does steganography have an edge over cryptography?

To break this down in simple terms is that however tight the security around a message may be, they can still garner a lot of attention. In some cases where encrypted messages are deemed incriminatory in nature by some countries that look upon encryption in a negative light, would draw much attention an unwarranted hassle with the governing bodies. This is where steganography exerts an obvious benefit over cryptography because in using this methodology you simply avoid attention to the file or image or message.

Which means the obvious reasons for hiding a message and wanting it to be seen by the intended people or person is much more validated by using steganography versus cryptography. It does not divulge any details to the obvious prowlers.

Digital images and nuances:

Now that is easy to relate to steganography, we’ll get into the concepts of understanding a few ideas that deal with processing images.

Basic necessities in building up to you actually knowing how to hide images into another- is that you know the concept of digital images and we can build from there.


A predetermined lot of digital values that are known as pixels are what make up a digital image. These tiny character elements called pixels, will add to let’s say, the intensity of a particular colour in an image – they are basically the components that store these values. What an image should look like now after knowing this is that it gives out a multi-dimension range or a matrix that processes a definitive number of columns and rows.


“Raster graphics” are the dotted matrix data structure that stands for a network of pixels, which is what can be housed within image files in a number of formats. In this instance, the “digital image” expression is what raster graphics stand for. To enhance further knowledge on the subject surrounding raster graphics, bitmaps or digital images, go onto the Wikipedia website.

The concept of Pixels and usage of color models in images.

To further elucidate on what you already know about pixels, other than them being the tiniest singular value in an image, is that each pixel gives you a foray of the real image. That is, if you add up all the pieces of pixels, you will be left with what the real image looks like. What is predominant is that every pixel has a different level of intensity . However, in the colour imaging system, any particular colour usually symbolise about three or four-part intensities, like cyan, magenta, yellow, and black, or red, green, and blue.


Now to move on to the RGB colour model, this model uses three straits, that is, blue, red and green. You will notice that the coming together of these three colours in the RGB colour model, in many different ways to bring together a vast range of colours, which make it a preservative colour model. This peculiar yet stunning aspect of the play with red, green, and blue contribute to how the model is known. In spite of being used in straightforward photography, the focal reason of the RGB colour model is to stand for, feel and show images in a very plausible manner on electronic mediums like televisions or computers and the like.


Now, we have already established the fact that every pixel in an image is made up of 3 components, i.e. red, green and blue. The array of these values can vary from 0-255 and they are known as 8-bit values. It would be futile to go ahead without understanding that some of the jargon used in the article definitely pertains to the computer domain. Nevertheless, it can’t hurt to learn something new every day! A binary code can hold each individual value of the three components in the pixel – which is clearly visible in the picture above.

Also seen in a binary code are the rather valuable bits and the ones with lesser value.

From the image above, the most significant bit is the one on the extreme left. What’s important to know is that if you change or replace the bit on the leftmost side it will alter the nuances of the end image. Here is a small instance of the same fact: say you alter the leftmost bit from 11111111 to 01111111 the decimal value reverses from 255 to 127.

The rightmost bit signifies the least significant bit in the image. This means that if the value of this bit is altered it will not reflect as much on the overall image. That is to say you change the rightmost bit’s value from 11111111 to 11111110; the decimal value will go from 255 to 254. This is significant to know that in a range of 256 it is changing only 1 and this is a mere 1%.

To sum up what we have gone through so far:

  • Every pixel has 3 components or values, that is, red, green and blue.
  • Every RGB is worth 8-bit or 8 binary values.
  • The bit that is on the rightmost part has the least value or significance and in altering this bit the end image will alter only fractionally.
  • The most important point is to note that this is the key steganography uses to tuck away one image into another. That is to alter the bit with the least importance and contain the bits of higher importance from another image.

Camouflaging one image into another

Now the fun learning of inserting and hiding away one image into another, because you are now aware of what pixels are and colour models too.

By implementing the Python code we can now go through a series of steps to figure out how to conceal and then unveil an image.

 To hide the image:

  1. It is important that the image that is hidden is relatively the same size of the image that will wrap it up. This is very important in hiding an image.
  2. Two loops need to be created to flow by every row and column from the images – this means it needs to loop every pixel.
  3. Image 2 will have the binary values and image 1 will render us with the RGB model.

To change decimal values to a binary value using the following method, that is, __int_to_bin :

  1. To combine the important bits of both image 1 and image 2:

Another method that can be used is the __merge_rgb method:

What this function (__merge_rgb method) does is that it uses the four most vital bits from each image, and it is changeable. An important aspect to weigh here is that if you use many bits the chances are the end result of the image revealed will not be of a substantial quality.

  1. In the last step we change the recent binary value to a decimal one:

The __bin_to_int method can be applied:

You will have to change the setting to a fresh pixel place from the image that shows.

Voila!! You will be left with an image hidden seamlessly into another.

Find the whole merge method here.

Ultimately, how to reveal a hidden image:

  1. It is vital to know the number of bits that were utilized to hide the image. Here only a specific number of 4 bits are in use.
  2. At the very start of this process you will have to fabricate two loops that will go via all the pixels from the image:
  3. What you then do is to take out every RGB strait as a binary value from the present pixel:

The __int_to_bin method can be put into use here:

  1. The next step will have you develop a fresh RGB value of the by linking a series only the 4 rightmost bits of the present pixel with zero values. This will form a newly developed 8-bit value:
  2. A step closer to the final revelation would be to change the binary value to decimal ones and then, set it to the present pixel in the fresh image:
  3. You can now smoothen out the black borders of the hidden image which was tinier in size compared to the image that was hiding it, and this would be the final step of your freshly created algorithm. This is how you can accomplish getting one image that is hidden out of another.

You can browse here to check out the whole process of the unmerge method.

Here are some effects visible in the images below:

The image toward the upper left is the image used to hide the image that is on the upper right. The image on the lower left shows the two images fused, and the image at the lower right- hand shows an image that has been revealed.

The one thing that will stand out is the fact that in the process of this extraction the image isn’t as excellent as the original one, nevertheless, it does very little to take away from what the image truly is.

Log on to this page called Github: , and discover the Steganography Python code.

I sure hope you will put this knowledge to good use.

About the author

Asif Amod

I am a webtrepreneur, full stack developer and a technology evangelist. I have been coding from a young age. I also speak to databases and make servers do what I say, I am passionate about continuous learning. I thrive on challenges that require lateral thinking - no matter what language or technology. I have founded and Co-founded a number of startups and have created SaaS web applications for different industries. I am currently open to discussing and explore other opportunities.

Add comment

By Asif Amod

About Me

I am a webtrepreneur, full stack developer and a technology evangelist. I have been coding from a young age. I also speak to databases and make servers do what I say, I am passionate about continuous learning. I thrive on challenges that require lateral thinking – no matter what language or technology. I have founded and Co-founded a number of startups and have created SaaS web applications for different industries. I am currently open to discussing and explore other opportunities.

Member of The Internet Defense League

Recent Posts

Top Posts & Pages

Subscribe to my Newsletter
Be the first to get latest updates and exclusive content straight to your email inbox.
Stay Updated
Give it a try, you can unsubscribe anytime.
Sign up to my newsletter to receive weekly updates