Design of digital watermarking based on Matlab—watermarking based on DCT domain

Realization of Digital Watermarking Algorithm Based on MATLAB

1. Subject introduction

Digital Watermark (Digital Watermark) technology refers to embedding concealed marks in digitized multimedia data by means of signal processing. This mark is usually invisible and can only be extracted by a special detector or reader. Digital watermarking is an important research direction of information hiding technology. With the development of digital watermarking technology, the application fields of digital watermarking have also been expanded. The basic application fields of digital watermarking are copyright protection, hidden identification, authentication and secure invisible communication.

When digital watermarking is applied to copyright protection, potential application markets lie in e-commerce, online or offline distribution of multimedia content, and large-scale broadcasting services. When digital watermarking is used to hide identification, it can be applied in fields such as medicine, cartography, digital imaging, digital image monitoring, multimedia indexing and content-based retrieval. In terms of digital watermark authentication, the safe and invisible communication of digital watermarks on ID cards, credit cards, ATM cards, etc. will be widely used in national defense and intelligence agencies.

This paper mainly builds and implements a digital watermarking encryption system based on DCT domain through system programming in the MATLAB environment based on the acquired knowledge of digital image processing. The system mainly includes the embedding and extraction of digital watermarking. The simulation results show that the digital watermarking algorithm has effectiveness, reliability, anti-attack, robustness and invisibility. Provide effective technical guarantees to ensure data security and integrity.

2. Subject outline

1 Design purpose

2 design requirements

3 Basic principles of digital watermarking technology

3.1 Basic framework of digital watermarking

3.2 Algorithm classification

3.2.1 DCT method

3.2.2 Other methods

3.3 Practical issues to consider

3.3.1 Invisibility

3.3.2 Robustness

3.3.3 Watermark capacity

3.3.4 Security

4 Simulation based on DCT transformation

4.1 Algorithm principle

4.1.1 Preparations

4.1.2 Select 8*8 transform block

4.1.3 Boundary adaptation

4.1.4 DCT transformation and embedding

4.1.5 Restoration of airspace 8

4.2 Embedding Algorithm Extension

4.2.1 Division of three matrices of RGB color image

4.2.2 Eight-color watermark

4.3 Watermark Extraction

4.4 Simulation program

5 Results Analysis 4

Conclusion 7

Reference 8


3. Basic principles of digital watermarking technology

3.1 Basic framework of digital watermarking

A digital watermarking system generally includes three basic aspects: watermark generation, watermark embedding and watermark extraction or detection. The basic framework of the general process of digital watermark embedding and extraction is shown in Figure 3.1 and Figure 3.2.


Watermark Generation Algorithm (G)

Digital watermark (W)

Raw carrier data (J)

Watermark Embedding Algorithm (E)

Private Key/Public Key (K)

Embedded watermarked data (IW)

Figure 3.1 The basic framework of the general process of watermark embedding


Data to be tested (IW)

Watermark detection algorithm (D)

Private Key/Public Key (K)

Estimated Watermark (W) / Similarity Detection (Sim)

Digital Watermark (W)/Original Data (I)

Figure 3.2 The basic framework of the general process of watermark detection

3.2 Algorithm classification

According to different implementation methods of watermarking, digital watermarking can be divided into space (time) domain digital watermarking and frequency domain digital watermarking.

Spatial digital watermarking is to directly superimpose watermarking signals on the signal space, while the principle of adding digital watermarking in the frequency domain method is to first transform the original signal (voice one-dimensional signal, image two-dimensional signal) into the frequency domain. The commonly used transformations generally include DWT, DCT, DFT, WP and fractals. Then, the frequency-domain inverse transform (IDWT, IDCT, DFT, WP) is performed on the signal added with watermark information to obtain a signal containing watermark information.

The principle of the frequency domain method to detect the watermark is to transform the original signal and the signal to be detected into the transform domain at the same time, compare the difference between the two, and perform the inverse operation of embedding the watermark to obtain the watermark information. If it is a readable watermark, then this is the end. If it is an unreadable watermark, such as Gaussian noise, compare the obtained watermark with the known watermark, and judge by the correlation, the signal to be detected contains no watermark, so the watermark The detection has two endpoints.

The frequency domain method has the following advantages: the energy of the embedded watermark signal can be distributed to all pixels in the airspace, which is beneficial to ensure the invisibility of the watermark; some characteristics of the visual system (HVS) (such as the masking characteristics of frequency) can be more conveniently Combined with the watermark encoding process; the frequency domain method is compatible with international data compression standards, thereby realizing watermark encoding in the compressed domain.

3.2.1 DCT method

Algorithm for doing DCT on the original signal: the classic work of DCT technology proposed by Cox and Piva et al. Cox uses a random number generator to generate a standard normal sequence as the watermark information to perform the overall DCT transformation on the image, and then selects the lower frequency coefficients except the DC coefficients to superimpose the watermark information; Piva modifies the intermediate frequency part of the entire image.

After the original signal is divided into blocks, the algorithm of DCT is performed: Hsu and Wu divide the image into 8*8 blocks, and put a binary sequence as a watermark into the intermediate frequency area of ​​DCT; some scholars calculate the DCT of the entire image, and put a real number The sequence is embedded on the intermediate frequency coefficients of the DCT. The advantage of choosing the intermediate frequency region is that on the one hand, it minimizes the impact of embedded information on the subjective vision of the image; at the same time, it tries to avoid the possible loss of watermark information caused by lossy compression.

Another DCT method is to embed watermark information into high-frequency coefficients, but with this method, the compression resistance is very poor.

3.3 Practical issues to consider

In digital watermarking technology, the data volume and robustness of watermark constitute a pair of basic contradictions. Subjectively speaking, an ideal watermarking algorithm should not only hide a large amount of data, but also be resistant to various channel noise and signal deformation. However, in practice, these two indicators often cannot be realized at the same time, but this will not affect the application of digital watermarking technology, because practical applications generally only focus on one aspect. If it is for concealed communication, the amount of data is obviously the most important. Since the communication method is extremely concealed, the possibility of encountering an enemy tampering attack is very small, so the robustness requirement is not high. But for ensuring data security, the situation is just the opposite. All kinds of confidential data are in danger of being stolen and tampered with at any time, so robustness is very important. At this time, the requirement of hiding the amount of data is secondary.

3.3.1 Invisibility

For information stored and distributed in analog form (such as television programs) or stored in physical form (such as newspapers, magazines), a visible sign is sufficient to indicate ownership. However, in digital mode, the logo information is easily modified or erased. Therefore, according to the type and geometric characteristics of multimedia information, the watermark should be hidden in a series of randomly generated positions using the key provided by the user, so that people cannot detect it. The left side of Figure 3.3 is the original image, and the right side is the image after embedding the watermark.


v2-6cff5359f5e62ca0f9b7556bdb6ca8e7_b.jpg


Figure 3.3 Comparison of the original image and the image after embedding the watermark

3.3.2 Robustness

Watermarking must be robust to general signal processing operations (such as filtering, smoothing, enhancement, compression with distortion, etc.), erasure attacks, obfuscation attacks, etc. Unless there is sufficient prior knowledge of the digital watermark, any attempt to destroy and eliminate the watermark will severely damage the quality of multimedia information.

3.3.3 Watermark capacity

The embedded watermark information must be sufficient to represent the identification information of the creator or owner of the multimedia content, or the serial number of the purchaser. In this way, when a copyright dispute occurs, the information of the creator or owner is used to identify the copyright owner of the data, and the serial number is used to indicate the user who violates the agreement and provides multimedia data for piracy.

Another important application of digital watermarking in multimedia information security is authenticity identification (ie authentication) of content. When the multimedia content changes, the highly sensitive fragile watermarking (Fragile watermarking) will change to a certain extent, so that it can be identified whether the original data has been tampered with.

3.3.4 Security

The security of the watermark requires that unauthorized persons cannot find the watermark information contained in the digital works. Or the security of the algorithm depends only on the key and not on the secrecy of the algorithm. Therefore, in the absence of a key, unauthorized persons cannot extract or destroy the watermark information even if they know the watermark information and the watermark algorithm. In addition, the algorithm should be resistant to collusion attacks.

Since the requirements of the watermark feature are highly dependent on the application, the appropriate evaluation criterion is related to the specific application.


Fourth, the specific implementation based on DCT transformation

4.1 Algorithm principle

Discrete cosine transform (Diserete Cosine Transform) referred to as DCT transform. Discrete cosine transform is a special case of Fourier transform. In Fourier series expansion, if the function to be expanded is a real even function, then its Fourier series only contains cosine terms, and then discretizing it can lead to discrete cosine Transform, so the cosine transform has the same physical meaning as the Fourier transform, and the DCT transform avoids the complex operation in the Fourier transform, and it is an orthogonal transform based on real numbers.

The basic principle of the DCT transform domain digital watermarking algorithm is to transform the image in the spatial domain into the frequency domain, then embed the watermark information into its DC term, and finally convert the frequency domain into the spatial domain to complete the embedding of the image watermark. Its main idea is to select mid- and low-frequency coefficients to superimpose watermark information on the DCT transform domain, because the perception of the human eye is mainly concentrated in the mid- and low-frequency bands. When an attacker destroys the watermark, it will inevitably cause a serious decline in image quality, and General image processing will not change this part of the data. Furthermore, since the core of compression algorithms such as JPEG and MPEG is quantization in the DCT transform domain, the watermark can resist certain lossy compression by skillfully fusing the watermark and quantization process. In addition, the statistical distribution of DCT transform domain coefficients has a relatively good mathematical model, which can theoretically estimate the information content of the watermark. The digital watermark based on DCT transform will be scattered in the entire image space during the inverse transformation, so the watermark is not as vulnerable to cropping, low-pass filtering and other attacks as the space domain technology, and has the characteristics of high robustness and good concealment.

4.1.1 DCT transformation and embedding

First, to detect whether the transformed block contains a boundary, the pixel block corresponding to the boundary image and the original image can be proposed, and the method of summing the values ​​of all pixels in the block (only including 0, 1) can be used to detect whether it contains a boundary , may wish to set a threshold equal to 3, that is, if the block contains three or more boundary points, it is considered that the block contains more boundary information, and a larger intensity value should be embedded through the principle of boundary adaptation.

Then, each 8*8 block needs to be subjected to DCT transformation, and the transformed DC component is multiplied by the intensity value and the information of the corresponding pixel of the watermark image. What needs to be pointed out here is that in order to ensure the simplicity of the extraction algorithm, the pixel value of the watermark image can be reduced by a relatively small value.

This step can be realized with MATLAB. You can use block_dct1=dct2(block_dct1) to perform two-dimensional DCT transformation on 8*8 blocks, block_dct1(1,1)=block_dct1(1,1)*(1+Alpha*(mark(m, n)-0.1)) where mark represents the pixel value of the watermark image, and embeds it into the DC item of the block.

4.1.2 Restoration of airspace

Perform inverse DCT transformation on the embedded blocks respectively, and store them back into the I matrix in order. At this time, I is the image after embedding the watermark.

4.2 Embedding Algorithm Extension

The above method generally can only embed a binary image into a grayscale image, and the method of embedding a color image into three binary images or an 8-color image will be carried out below.

4.2.1 Division of three matrices of RGB color image

Since all RGB color images are composed of three colors of red, green and blue, these three images are also divided into three matrices in storage, then we can treat each matrix as a grayscale, and each A watermark image can be embedded in each grayscale image.

1. Edge image of color image

Since I in the edge function must be a grayscale image, if you want to use the GRAY=rgb2gray(I) statement to change the color image into a grayscale image, then use the grayscale image GRAY as its boundary image.

2. Color image layering

In MATLAB, after reading the color RGB image into I, different from the grayscale image, the I matrix is ​​a three-dimensional matrix which can be expressed as I(a,b,c) where when c=1, I(a,b, 1) Represents the matrix of the red component in the color image. Similarly, I(a, b, 2), I(a, b, 3) represent the matrix of the green and blue components in the color image, respectively. When embedding in layers, it means that the original image matrix needs to add the value of the third dimension component c, otherwise MATLAB will default to c=1.

It should be noted here that when generating a new image, all three matrices R, G, and B must be stored in the output matrix, otherwise there will be a lack of color.

4.2.2 Eight-color watermark

Similar to the above principle, the color image used as watermark is also divided into three layers R, G, and B, and each layer can be embedded as a watermark image in the matrix of the original image. When extracting, it is only necessary to store the extracted three watermark images into a three-dimensional matrix, that is, a color image.

However, it should be noted here that the R, G, and B components of the watermark image used have only two values ​​of 0 and 1, respectively. Therefore, if the color image used is improper, it will affect the embedding effect, and even cannot be extracted.

4.3 Watermark Extraction

The watermark extraction method here can be regarded as the inverse transformation of embedding. Since the coefficients related to the watermark information are multiplied in the DC flow of the 8*8 block in the frequency domain, then we can also pass the original image and the watermark image 8*8 The quotient obtained by dividing the value of the DC component of the block is the value related to the watermark image. Since the value of the watermark image only contains 0 and 1 during embedding, and we subtract a small constant after this value, the divided The quotient minus 1 is recorded as cc, so that cc<0 when the embedded watermark value is 0, and cc>0 when the embedded watermark value is 1. In this way, the watermark image can be drawn.

4.4 Source code

blockno=size/block;   %每行块的个数
LENGTH=size*size/64;   %总块的个数1024
Alpha1=0.03;   %非边界处的强度因子
Alpha2=0.1;    %边界处的强度因子
T1=3;   %域值为三个边界点
I=zeros(size,size);   %原始图像
BW=zeros(size,size);   %原始图像的边缘图
block_dct1=zeros(block,block);
mark=imread('D:\水印图','bmp');   %沈阳理工大学字样彩色水印图
mark1=logical(mark(:,:,1));
mark2=logical(mark(:,:,2));
mark3=logical(mark(:,:,3));
figure(1)
subplot(2,2,1);
imshow(mark);title('水印图像');
%显示原图
subplot(2,2,2);I=imread('D:\原始图','bmp');    %读入彩色图像
imshow(I);title('原始图像:I');
%显示prewitt为算子的边缘图
GRAY=rgb2gray(I);   %变灰度要用三位数,即彩色图片
BW=edge(GRAY,'prewitt');   %取边界,用于边界自适应
subplot(2,2,3);imshow(BW);
title('原始图像的边缘');
%嵌入水印
for m=1:blockno;   %到第(m,n)个块
   for n=1:blockno;
      x=(m-1)*block+1;   %该块的起始像素
      y=(n-1)*block+1;
        block_dct1=I(x:x+block-1,y:y+block-1);   %取该块所有像素
        block_dct1=dct2(block_dct1);   %变换
        %第二维
        block_dct2=I(x:x+block-1,y:y+block-1,2);   %取该块所有像素
        block_dct2=dct2(block_dct2);   %变换        
    BW_8_8=BW(x:x+block-1,y:y+block-1);   %取边缘的对应块像素
      if m<=1|n<=1;%m或n小于等于1时,
         T=0;
      else
         T=sum(BW_8_8);   %列取和
         T=sum(T);   %对整个BW_8_8中的数字取和
         %取和
      end
      if T>T1;   %如果改为<则意味着高频区嵌入了低能量,低频区嵌入了高能量。所以在低频区嵌入的过高能量会是不该看出的水印显示出来
         %因此这里表示着边缘自适应性
          Alpha=Alpha2;   %0.1
      else
         Alpha=Alpha1;   %0.03
      end  
   block_dct1(1,1)=block_dct1(1,1)*(1+Alpha*(mark1(m,n)-1));   %对直流进行嵌入
   block_dct2(1,1)=block_dct2(1,1)*(1+Alpha*(mark2(m,n)-1));   %第二层
   block_dct3(1,1)=block_dct3(1,1)*(1+Alpha*(mark3(m,n)-1));   %第三层
   block_dct1=idct2(block_dct1);   %变回空域
   block_dct2=idct2(block_dct2);   %第二层
   block_dct3=idct2(block_dct3);   %第三层
   I(x:x+block-1,y:y+block-1)=block_dct1;    %贴回原图像
   I(x:x+block-1,y:y+block-1,2)=block_dct2;    %第二层
   I(x:x+block-1,y:y+block-1,3)=block_dct3;   %第三层
   end
end
%显示嵌入水印后的图像
subplot(2,2,4);imshow(I);title('嵌入水印后的图像');
imwrite(I,'D:\输出图.bmp','bmp');
figure(2);subplot(2,2,1);imshow(mark(:,:,1));title('原水印的第一层');
subplot(2,2,2);imshow(mark(:,:,2));title('原水印的第二层');
subplot(2,2,3);imshow(mark(:,:,3));title('原水印的第三层');
imwrite(I,'D:\压缩图.jpg','jpg','quality',90);   %压缩 
%通过原图片对比提取水印
I=imread('D:\原始图.bmp','bmp');
J=imread('D:\输出图.bmp','bmp');
K=zeros(32,32,3);   %水印图片为32*32
for q=1:blockno;
    for p=1:blockno;
        x=(p-1)*block+1;
        y=(q-1)*block+1;
  BLOCK1=I(x:x+block-1,y:y+block-1);   %取无水印图的块
  BLOCK2=J(x:x+block-1,y:y+block-1);   %取带水印图的块
  BLOCK1=dct2(BLOCK1);
  BLOCK2=dct2(BLOCK2);
  a=BLOCK2(1,1)/BLOCK1(1,1)-1;
  %第二层
  BLOCK12=I(x:x+block-1,y:y+block-1,2);
  BLOCK22=J(x:x+block-1,y:y+block-1,2);
  BLOCK12=dct2(BLOCK12);
  BLOCK22=dct2(BLOCK22);
  b=BLOCK22(1,1)/BLOCK12(1,1)-1;
  %第三层
  BLOCK13=I(x:x+block-1,y:y+block-1,3);
  BLOCK23=J(x:x+block-1,y:y+block-1,3);
  BLOCK13=dct2(BLOCK13);
  BLOCK23=dct2(BLOCK23);
  c=BLOCK23(1,1)/BLOCK13(1,1)-1;
  if a<0
      W(p,q)=0;   %恢复水印图像
  else
      W(p,q)=1;
  end
  if b<0
      W2(p,q)=0;
  else
      W2(p,q)=1;
  end 
    end
end
figure(3);
subplot(2,2,1);imshow(W);
title('从第一层提取的水印(红R)');   %0表示黑色
subplot(2,2,2);imshow(W2);
title('从第二层提取的水印(绿G)');
subplot(2,2,3);imshow(W3);
title('从第三层提取的水印(蓝B)');
K(:,:,1)=W;
K(:,:,2)=W2;
K(:,:,3)=W3;
subplot(2,2,4);imshow(K);title('合并的彩图');
%检测压缩后的水印图像
J=imread('D:\压缩图.jpg','jpg');
for q=1:blockno;
    for p=1:blockno;
        x=(p-1)*block+1;
        y=(q-1)*block+1;
  BLOCK1=I(x:x+block-1,y:y+block-1);   %取无水印图的块
  BLOCK2=J(x:x+block-1,y:y+block-1);   %取带水印图的块 
  %第二层
  BLOCK12=I(x:x+block-1,y:y+block-1,2);
  BLOCK22=J(x:x+block-1,y:y+block-1,2);
  BLOCK12=dct2(BLOCK12);
  BLOCK22=dct2(BLOCK22);
  b=BLOCK22(1,1)/BLOCK12(1,1)-1;
  %第三层
  BLOCK13=I(x:x+block-1,y:y+block-1,3);
  BLOCK23=J(x:x+block-1,y:y+block-1,3);
  BLOCK13=dct2(BLOCK13);
  BLOCK23=dct2(BLOCK23);
  c=BLOCK23(1,1)/BLOCK13(1,1)-1;
  if a<0
      W(p,q)=0;
  else
      W(p,q)=1;
  end
  if b<0
      W2(p,q)=0;
  else
      W2(p,q)=1;
  end
  if c<0
      W3(p,q)=0;
  else
      W3(p,q)=1;
  end
 end
end
K(:,:,1)=W;K(:,:,2)=W2;K(:,:,3)=W3;
figure(4);imshow(K);title('90压缩的提取');

5. Running result simulation



v2-678809641d7a03d4fd110cdc79d6bc2c_b.jpg


Figure 5.1 Comparison of the original image and the image after embedding the watermark

There is only a slight difference between the original image and the image after embedding the watermark, and the human eye can hardly distinguish any difference between the two images. This shows that the DCT domain watermarking algorithm has better invisibility, basically does not affect the visual quality, and also satisfies the requirement of transparency well.


v2-93dd4eafbeacc27aa091adb654e7f6d8_b.jpg


Figure 5.2 Watermark extracted by comparing with the original image


v2-fd5d746caeee4a40e12a6658bf01320f_b.jpg


Figure 5.3 Layered extracted watermark image

When extracting the watermarked image layer by layer, some errors occurred, and some image pixels disappeared. When the watermarked image was restored by forming a color watermark, the original color image could no longer be restored.


v2-a480fb0033a2ca2dbfea63b691edcfd2_b.jpg


Figure 5.4 The result of detecting the compressed watermark image

It can be seen from the above results that this method is relatively simple in watermark embedding and extraction. This method has very low resistance to compression attacks and can be said to be fragile. Obviously, it is difficult to distinguish the watermark content under 90 quality compression.

The experimental results have verified the effectiveness, reliability, anti-attack, robustness and invisibility of the algorithm in some aspects, and can provide digital media information with anti-counterfeiting, anti-tampering, authentication, and data security and integrity protection. Effective technical support.









literature

[1] Ruan Qiuqi. Digital Image Processing [M]. Beijing: Electronic Industry Press, 2001.

[2] Gong Shengrong, Liu Chunping, Wang Qiang, etc. Digital Image Processing and Analysis [M]. Beijing: Tsinghua University Press, 2006.

[3] Jia Yonghong. Computer Image Processing and Analysis [M]. Wuhan: Wuhan University Press, 2001.

[4] Chen Guiming. Applying MATLAB language to process digital signal and image processing [M]. Beijing: Science Press, 2000.

[5] Xia Deshen, Fu Desheng. Computer Image Processing and Application [M]. Nanjing: Southeast University Press, 2004.

[6] Yao Min. Computer Image Processing [M]. Beijing: Machinery Industry Press, 2006.

[7] Rong Guanao. Computer Image Processing [M]. Beijing: Tsinghua University Press, 2000.

[8] Wu Jiankang. Digital Image Analysis [M]. Beijing: Posts and Telecommunications Press, 1989.

Guess you like

Origin blog.csdn.net/TuTu998/article/details/120177074