How to communicate secretly with SteganoGAN?

Steganography is the practice of concealing a secret message within or even on top of something public.

Steganography is the term used to refer to secret communication, which is the process of hiding a sort of information in the main medium of communication. Deep learning is also used in this field to develop powerful and secure applications when communication is supposed to be done through images. In this article, we will discuss steganography and how it is used nowadays with the latest developments. Later we will discuss the SteganoGAN which is a tool that does steganography on images. Following are the major points to be discussed in this article. 

Table of contents

  1. Understanding the steganography
  2. How is it carried out?
  3. How does SteganoGAN work?
  4. Implementing SteganoGAN

Let’s first discuss Steganography.

Understanding the steganography

Steganography is the practice of concealing a secret message within or even on top of something public. That something can be anything you want it to be. Many examples of steganography nowadays involve embedding a secret piece of text inside of a picture. Alternatively, you could conceal a secret message or script within a Word or Excel document.

AIM Daily XO

Join our editors every weekday evening as they steer you through the most significant news of the day, introduce you to fresh perspectives, and provide unexpected moments of joy
Your newsletter subscriptions are subject to AIM Privacy Policy and Terms and Conditions.

Steganography’s purpose is to conceal and deceive. It is a type of covert communication in which messages are hidden using any medium. It is not a type of cryptography because it does not involve data scrambling or the use of a key. Instead, it is a type of data concealment that can be carried out in imaginative ways.

How is it carried out?

Data is encrypted or obfuscated in some other way before being injected into data that is part of a certain file type, such as a JPEG image, audio, or video file, employing a special algorithm in current digital steganography. The hidden message can be inserted into ordinary data files in a variety of ways. 

Download our Mobile App

One way is to disguise data in bits that represent the same colour pixels in an image file’s row. By applying the encrypted data inconspicuously to the redundant data, the outcome is a picture file that seems identical to the original image but contains “noise” patterns of normal, unencrypted data.

One frequent application of steganography is the use of a watermark, which is a trademark or other identifying data buried in multimedia or other content files. Watermarking is a method used by internet publishers to determine the origin of media assets that have been uploaded without permission.

One frequent application of steganography is the addition of a watermark — a brand or other identifying data concealed in multimedia or other content files. Watermarking is a technique commonly employed by online publishers to identify the source of media assets discovered to be shared without permission.

How does SteganoGAN work?

Traditional image steganography techniques are only effective up to a relative payload of about 0.4 bits per pixel. They tend to introduce artefacts beyond that limit, which can be easily spotted by automated steganalysis techniques and, in severe circumstances, by the human eye. 

STEGANOGAN is a revolutionary end-to-end model for image steganography that leverages current deep learning developments. It employs dense connections, which have been demonstrated to boost performance by mitigating the vanishing gradient problem. 

Multiple loss functions are used within an adversarial training framework to optimize the encoder, decoder, and critical networks all at the same time. We discover that our method successfully embeds arbitrary data into cover photos derived from a variety of natural landscapes and reaches cutting-edge embedding rates of 4.4 bits per pixel.

Steganography, at its most basic, involves only two operations: encoding and decoding. The encoding procedure generates a steganographic image from a cover image and a binary message. The decoding operation retrieves the binary message from the steganographic image.

Implementing SteganoGAN

To use SteganoGAN we need to install SteganoGAN via pip or via source by cloning the repository, and also we have to use a dataset to train the GAN. The dataset can be used from the repository. There is a shell file at the directory SteganoGAN/research/data/ by running this file we can download the div2K and MS COCO dataset. Either of these datasets is required for the training here. I have used the div2k dataset. We can download only the div2k dataset by commenting out the script of MS COCO in the .sh file and after saving it run it as follows.

# downloading the dataset
! /content/SteganoGAN/research/data/

# installing the architecture
! pip install steganogan

Let’s import the dependencies.

from steganogan import SteganoGAN
from steganogan.critics import BasicCritic
from steganogan.decoders import DenseDecoder
from steganogan.encoders import DenseEncoder
from steganogan.loader import DataLoader
import numpy as np

The first import is the SteganoGAN wrapper class which creates the architecture, trains the architecture, loads the previously trained model, and finally and importantly performs encoding and decoding operations.

The next two imports are for encoder and decoder architecture. Basically, there are three models for each namely Basic, Residual and Dense. And currently, the implementation part supports Basic and Dense architecture. 

The next import is about the data loader. This function is used to load the dataset from the directory and additionally, you set a couple of parameters like a number of images to be used, shuffling etc.     

Now after downloading the dataset by the shell command above we can load it by using the Data Loader function. The dataset is by default downloaded into two splits and validation here we’ll use those two.

train = DataLoader('div2k/train/', limit=np.inf, shuffle=True, batch_size=4)
validation = DataLoader('div2k/val/', limit=np.inf, shuffle=True, batch_size=4)

Now that’s it we can now directly use the wrapper class of SteganoGAN to create the architecture as shown below.  

#use the wrapper class
steganogan = SteganoGAN(1, DenseEncoder, DenseDecoder, BasicCritic, hidden_size=32, cuda=True, verbose=True)

In the above definition, we have used the BasicCritic function which is a kind of evaluation function which checks if a given image is stenographic or not.  

Now we can begin with training. To train this model we just need to simply call the .fit method as we do with normal ML algorithms by supplying the training and validation data.

# train, validation, epochs=5)

After completing the training we can use the encoder and decoder functions. Here the encoder function is used to take three arguments namely the input image, the name and path of the output image, and the string or text message to be conveyed.  

Here is the image that we are using. 

# encoding
steganogan.encode('/content/artillery.png','output.png','Fire in the hole!')

Similarly, the decoding function takes only the generated image and outputs the message coded above. 

# decoding

Output:   Fire in the hole!

And here is the output image.

The coded image looks similar to the original image as we can see above. For the sake of curiosity, we can check the difference between the two images by using OpenCV as follows.

import cv2
from google.colab.patches import cv2_imshow

# load original image
original = cv2.imread('/content/artillery.png', cv2.COLOR_BGR2RGB)

# loaded coded image
coded = cv2.imread('/content/output.png', cv2.COLOR_BGR2RGB)
# subtract two
diffrence = cv2.subtract(original, coded)

# get the result

Here is the result,

A complete black image results that there is absolutely no difference between the images. 

Final words

Through this article, we have learned about steganography which is basically a technique by which one can convey a kind of information separately between the parties. For the image steganography, we have seen the python-based tool called SteganoGAN which can code the arbitrary message to the image and retrieve it, and in the whole process, we can not see any changes in the image.  


Sign up for The Deep Learning Podcast

by Vijayalakshmi Anandan

The Deep Learning Curve is a technology-based podcast hosted by Vijayalakshmi Anandan - Video Presenter and Podcaster at Analytics India Magazine. This podcast is the narrator's journey of curiosity and discovery in the world of technology.

Vijaysinh Lendave
Vijaysinh is an enthusiast in machine learning and deep learning. He is skilled in ML algorithms, data manipulation, handling and visualization, model building.

Our Upcoming Events

24th Mar, 2023 | Webinar
Women-in-Tech: Are you ready for the Techade

27-28th Apr, 2023 I Bangalore
Data Engineering Summit (DES) 2023

23 Jun, 2023 | Bangalore
MachineCon India 2023 [AI100 Awards]

21 Jul, 2023 | New York
MachineCon USA 2023 [AI100 Awards]

3 Ways to Join our Community

Telegram group

Discover special offers, top stories, upcoming events, and more.

Discord Server

Stay Connected with a larger ecosystem of data science and ML Professionals

Subscribe to our Daily newsletter

Get our daily awesome stories & videos in your inbox

Council Post: Evolution of Data Science: Skillset, Toolset, and Mindset

In my opinion, there will be considerable disorder and disarray in the near future concerning the emerging fields of data and analytics. The proliferation of platforms such as ChatGPT or Bard has generated a lot of buzz. While some users are enthusiastic about the potential benefits of generative AI and its extensive use in business and daily life, others have raised concerns regarding the accuracy, ethics, and related issues.