Digital Image Watermarking using Optimized DWT-DCT

(1 customer review)


Total downloads: 326

This repository is for the free code of digital image watermarking .  This code is for the invisible digital image watermarking using combination of three methods: Discrete Wavelet Transform (DWT), Discrete Cosine transform (DCT) and Bacterial Foraging optimization (BFO). You need to run the file ‘main.m’ in MATLAB and follow the steps shown in video


The digital image watermarking is based on the fact that a message is hide into the image such that image doesn’t get disturbed and message can be retrieved easily. The method should be robust. For this purpose, this repository is implementing the discrete wavelet transform (DWT) and discrete cosine transform (DCT) in cascade so that more robustness and security can be achieved. These methods divide the image into different frequency regions so that watermark message can be embedded into lowest frequency region which will not disturb the image. DCT is applied first which is similar to Fourier transform and divides the image into two parts of lower and higher frequency region. Lower frequency region has most of the image information.

DCT frequency coefficient of image

Figure: (a) original image (b) low frequency component of DCT (c) high frequency component of DCT

Similarly, DWT using haar  wavelet transform split the images into four different frequency coefficients: approximation coefficients, horizontal , vertical and detailed frequency component.

DWT frequency coefficient for image

Figure: DWT frequency components of image

Horizontal coefficient is used to insert the watermark image and DCT transform is further applied to cH1 component of DWT transformed image. The embedding of watermark image needs a optimal gain factor which sets the robustness of the message. If this value is too high then security will be increased but retrieval of message will be difficult and vice-versa. So trade off gain factor has to be used for embedding of watermark in it. We used Bacterial Foraging optimization (BFO) for this purpose at

Embedding of Watermark

  1. Take the message and reformulate the message into sequence of 1 and 0.
  2. Encode the message using convolution and this encoded message is further used for processing
  3. Take the key and generate a PN sequence by that key. This PN sequence is kept same during all embedding process.
  4. Generate two highly uncorrelated PN sequence pn_sequence_1 and pn_sequence_0.
  5. Perform DWT on the host image to decompose it into four non-overlapping multi resolution coefficient sets: cA1, cH1, cV1 and cD1.
  6. Choose block size and a mid band coefficients matrix for DCT. In our paper block size of 8 is chosen and a mid band matrix of 8*8 is chosen from literature review.
  7. Now perform DCT on cH1 and embed both PN sequence with a gain factor ‘k’ depending on the bit value of message. The algorithm for embedding PN sequence is shown as

    X = x + k * PN0 if b = 0

    X = x + k * PN1 if b = 1


                  x = is the cover image

                  b = is the watermarked bit

                 X = is the embedded image

  8.  Now perform IDCT on cH1.
  9. Repeat step6 and 7 for cV1.
  10. Perform IDWT on updated values of cA1, cH1, cV1, cD1 and name this image as watermarked image.
  11. PSNR and Normalized cross correlation is found out to determine robustness and image quality of watermarked image.
  12. Now follow steps from 1 to 10 for embedding next watermark using separate key for PN sequence. The size of watermark is determined by hit and trial method and that comes less than the previous watermark size.
  13. Number of watermarks embedded depends upon retrieval process because watermark should be retrieved properly that is without any distortion.

Retrieval of Watermark

The joint DWT-DCT algorithm is a blind watermarking algorithm, and thus the original host image is not required to extract the watermark.

  1. Step 1: Steps from 1 to 5 of embedding process are same using same key for PN sequence generation.
  2. Now perform DCT on cH1 and generate a sequence at condition where mid band matrix element is 1. Correlate that sequence to pn_sequenc_0 and to pn_sequence_1.
  3. Repeat the step 2 with cV1.
  4. Take the mean of correlation value for pn_sequence_1 of cH1 and cV1 and correlation value for pn_sequence_0 of cH1 and cV1.
  5. If correlation value for 0 is greater than the correlation value of 1, put the message vector element equal to 0 otherwise 1.correlation_0>correlation_1Message vector = 0


    Message vector = 1

  6. Apply viterbi decoder on message vector to deocde message vector into original.
  7. Reshape the message vector and that will be similar to message embedded.
  8. Same steps are repeated for next watermark message retrieval.

Fitness Function Calculation

To set the optimum value of gain factor bacterial foraging optimization is used in our work. The BFO minimizes the objective function value to get the best location of E.Coli bacteria. So the task is to formulate the objective function to achieve the best gain value. For this purpose inverse of normalized cross correlation has been considered the parameter which is to be minimized. Initially random gain value is selected and that is passed to the embedding and retrieval process of message using DWT and DCT watermarking process. At the watermarked image by this process various noises like Gaussian noise, salt & pepper noise, speckle noise and poisson noise have been added and message is recovered from these noisy images. NCC between the original message and recovered from these noisy watermarked images have been found out. Then the inverse of sum of all these NCCs is considered as the objective function of BFO.

Image watermarking objective function

Result Discussion

We tested the algorithm at three different kind of images which are low,high and medium key images. This category is suggested on the basis of computer graphics literature where the image with more number of histogram bins are aligned to left for low key image, to right for hugh key image and in middle  for medium key image.

low key image for image watermarking

Figure: histogram plot for low and high key image

A gui to compare the three different watermarking algorithms is also designed in MATLAB. It makes easy to run the algorithm and analyse. On the criteria of PSNR, NCC and IF parameters, we found the gain factor tuning by BFO gives best performance.

Image Watermarking GUI

1 review for Digital Image Watermarking using Optimized DWT-DCT

  1. fodayj25 (verified owner)

    I am working on my thesis using DWT-SVD and I have embedded in different sub-band of the DWT. I came across your work. It has really helped me. The reason is that my supervisor wants me to compare DWT with other watermarking techniques and see the results. I really appreciate the work done with this code. It very neat and easy to understand.
    Thank you!

    • admin (verified owner)

      We are glad, it helped you.

  2. pratuisha.koripilli (verified owner)


  3. azlina.mahad (verified owner)


  4. qq.qq (verified owner)


  5. imjoy (verified owner)


  6. anshuman.prakash (verified owner)


  7. kumarraghav (verified owner)

    very good

  8. raillon.georges (verified owner)

    Très interresentes approche

  9. ashishsoni (verified owner)


  10. venkat.reddy (verified owner)


  11. venkat.reddy (verified owner)


  12. rohit.bumo (verified owner)


Only logged in customers who have purchased this product may leave a review.