MATLAB final assignment

Posted by sparkie624 on Mon, 07 Mar 2022 06:45:07 +0100

Digital watermarking based on wavelet filter transform, Heisenberg decomposition and singular value decomposition (MATLAB)

brief introduction

Digital watermarking refers to embedding specific information into digital signals, which may be audio, picture or video. If you want to copy the signal with digital watermark, the embedded information will also be copied. Digital watermarking can be divided into two types: emerging and hidden. The former is visible watermarking, and the information contained in it can be seen at the same time when watching pictures or videos. Generally speaking, the emerging watermark usually contains the name or logo of the copyright owner.

The realization of digital watermarking in this paper aims to embed the target picture into the picture to be protected, and ensure that it does not affect the visual effect of the picture to a certain extent, and the watermark is invisible without processing. And the method used in this paper is robust, that is, it can still extract the watermark information from the watermarked image when the image is stained, compressed, distorted, rotated and so on.

principle

embed

  • Host image \(\rightarrow\) DWT2 \(\rightarrow\) HD \(\rightarrow\) SVD
  • logo \(\rightarrow\) SVD
  • \(\Sigma_{\text {output\ image }}=\Sigma_{\text {Origin }}+\alpha \Sigma_{\text {logo }}\)
  • Inverse SVD \(\left(U \Sigma_{\text {output\ image }} V^{*}\right) \rightarrow\) Inverse HD \(\rightarrow\) Inverse DWT2

Firstly, in order to simplify the algorithm, take the "red" layer of the original RBG image, which is hereinafter referred to as "host image";

Carry out two-dimensional wavelet filtering on the host image and take the LL layer - because the LL layer is difficult to distinguish with the naked eye, we choose to hide the information in this layer;

Perform Hessenberg decomposition on LL to obtain H matrix, and perform singular value decomposition on H to obtain \ (\ Sigma {\ text {origin}} \) matrix;

Remember that the image to be embedded is a logo. Perform singular value decomposition on the logo to obtain $\ Sigma_{\text {logo} $matrix;

The two \ (\ Sigma \) matrices are linearly combined as follows to obtain the output \ (\ Sigma {\ text {output \ image} \)

\[\Sigma_{\text {output\ image }}=\Sigma_{\text {Origin }}+\alpha \Sigma_{\text {logo }} \]

Reverse singular value decomposition, reverse Heisenberg decomposition and reverse two-dimensional wavelet filtering are carried out in turn;

separate

DWT2 \(\rightarrow\) HD \(\rightarrow\) SVD \(\rightarrow\) Computed extracted singular \(\rightarrow\) Inverse SVD \(\rightarrow\) logo

After two-dimensional wavelet filtering, Heisenberg decomposition and singular value decomposition, the watermark image can be obtained \ (\ Sigma {\ text {extract}} \). The original logo can be obtained by reverse linear combination during embedding and reverse singular value decomposition.

Code

embed

origin_A = imread('origin.png');
origin_W = imread('logo.png');
[origin_A_n, origin_A_m] = size(origin_A);
A = imresize(origin_A, [origin_A_n, origin_A_n]);
W = imresize(origin_W, [origin_A_n, origin_A_n]);

alpha = 0.1;

RA = A(:,:,1);
RW = rgb2gray(W);
% figure,imshow(RA);
% figure,imshow(RW);

% dwt2
[LL,LH,HL,HH] = dwt2(RA,'db4');
% HD 
[P,H] = hess(LL);
% SVD on original Sigma
[HU,HS,HV] = svd(H);

% SVD on watermarked picture 
RW = imresize(RW,size(H));
[WU,WS,WV] = svd(double(RW));
% embed the watermark into the original graph
marked_HS = HS + alpha.* WS;
% inverse SVD
marked_H = HU * marked_HS * HV.';
% inverse HD
marked_LL = P * marked_H * P.';
% inverse DWT2
marked_img_Red = idwt2(marked_LL,LH,HL,HH,'db4');

marked_img_Red = imresize(marked_img_Red,size(RA));
marked_img = A;
marked_img(:,:,1) = uint8(marked_img_Red);
% figure,imshow(marked_img);
imwrite(marked_img,'marked_img.png');
key_img_svd = WU* HS *WV';
key_img(:,:,1) = WU;
key_img(:,:,2) = HS;
key_img(:,:,3) = WV;
imwrite(key_img,'key.png');
imwrite(key_img_svd,'keysvd.png');

separate

origin_A = imread('origin.png');
origin_W = imread('logo.png');
% test date collection
marked_A = imread('marked_img.png');
smear = imread('smear.png');
severe_smear = imread('severe_smear.png');
spin = imread('spin.png');
half = imread('half.png');
black_matrix = imread('black_matrix.png');
severe_compress = imread('severe_compress.png');

imwrite(ext(marked_A,origin_A,origin_W),'extract_marked_A.png');
imwrite(ext(smear,origin_A,origin_W),'extract_smear.png');
imwrite(ext(severe_smear,origin_A,origin_W),'extract_severe_smear.png');
imwrite(ext(spin,origin_A,origin_W),'extract_spin.png');
imwrite(ext(half,origin_A,origin_W),'extract_half.png');
imwrite(ext(black_matrix,origin_A,origin_W),'extract_black_matrix.png');
imwrite(ext(severe_compress,origin_A,origin_W),'extract_severe_compress.png');

function [mark] = ext(marked_A, origin_A, origin_W)
    [origin_A_n, origin_A_m] = size(origin_A);
    mA = imresize(marked_A,[origin_A_n,origin_A_n]);
    A = imresize(origin_A,[origin_A_n,origin_A_n]);
    W = imresize(origin_W,[origin_A_n,origin_A_n]);
    RmA = mA(:,:,1);
    RA = A(:,:,1);
    RW = rgb2gray(W);

    alpha =  0.1;

    % DWT
    [LL,LH,HL,HH] = dwt2(RmA,'db4');
    % HD 
    [P,H] = hess(LL);
    % SVD
    [HU, HS, HV] = svd(H);

    % dwt2
    [oLL,oLH,oHL,oHH] = dwt2(RA,'db4');
    % HD 
    [oP,oH] = hess(oLL);
    % SVD on original Sigma
    [oHU,oHS,oHV] = svd(oH);

    S = (HS - oHS)./alpha;

    % SVD on watermark
    RW = imresize(RW,size(S));
    [WU,WS,WV] = svd(double(RW));
    mark = WU * S * WV.';
%     comp = WU * WS * WV.';
%     figure,imshow(uint8(mark));
%     figure,imshow(uint8(comp));
    mark = uint8(mark);
end

Sample

Original image, logo, watermark image

Original drawing

logo

Watermark image

Smear attack

Attack example

Separation results

Serious smear attack

Attack example

Separation results

The contour is not good, but the effect is still not good.

Rotation attack

Attack example

Separation results

It has no effect at all, because all rotation information is discarded after SVD decomposition.

Stain - small square

Attack example

Separation results

Photoshop - automatic color

Attack example

Separation results

The effect is not good, only the outline is visible.

Clipping attack

Attack example

Separation results

Perfect.

Compression attack

Attack example

The effect is outstanding.

Analysis and summary

This algorithm has good robustness to the cutting attack, compression attack and slight image stain of the watermark image. The separated image has good recognition, but the effect in other aspects is not ideal. There are many reasons:

  • The algorithm itself has weak defense against other types of attacks;

  • The optimal selection algorithm of \ (\ alpha \) is not introduced, and the implementation adopts fixed number;

  • The implementation of the code itself and the original paper have simplified changes;

quote

Liu, Junxiu & Huang, Jiadong & Luo, Yuling & Cao, Lvchen & Yang, Su & Wei, Duqu & Zhou, Ronglong. (2019). An optimized image watermarking method based on HD and SVD in DWT domain. IEEE Access. PP. 1-1. 10.1109/ACCESS.2019.2915596.