当前位置:网站首页>Chapter 25 digital watermarking technology based on Wavelet Transform

Chapter 25 digital watermarking technology based on Wavelet Transform

2022-06-22 02:09:00 Haibao 7

Deep learning machine learning image processing matlab Project practical case series
Digital watermarking technology based on wavelet transform

Digital watermarking technology

As an effective multimedia copyright protection technology, it has attracted more and more attention . An image digital watermarking algorithm based on wavelet transform is proposed . According to human visual characteristics , The digital watermark information is embedded into the high-frequency subband texture region of the image after wavelet transform , It's hard for the human eye to detect , Then the embedded watermark is extracted from the watermarked image and the original image .

Wavelet transform

Wavelet transform (wavelet transform,WT) It is a new transformation analysis method , It inherits and develops the idea of STFT localization , At the same time, it overcomes the disadvantage that the window size does not change with frequency , Can provide a frequency dependent “ Time - frequency ” window , It is an ideal tool for signal time-frequency analysis and processing . Its main feature is that it can fully highlight the characteristics of some aspects of the problem through transformation , To be able to ( Space ) Localized analysis of frequency , Through the expansion and translation operation on the signal ( function ) Step by step multi-scale refinement , Finally, time subdivision at high frequency , Frequency subdivision at low frequencies , It can automatically adapt to the requirements of time-frequency signal analysis , So that any detail of the signal can be focused , It's solved Fourier The difficult problem of transformation , To become a successor Fourier A major breakthrough in scientific methods since the transformation .
Wavelet transform is related to applied mathematics 、 physics 、 Computer science 、 Signal and information processing 、 Image processing and other methods . This method also inherits and develops the idea of short-time Fourier transform localization , At the same time, it overcomes the disadvantage that the window size does not change with frequency , Can provide a frequency dependent “ Time - frequency ” window , It is an ideal tool for signal time-frequency analysis and processing . Its main feature is that it can fully highlight the characteristics of some aspects of the problem through transformation , therefore , Wavelet transform has been successfully applied in many fields , In particular, the discrete digital algorithm of wavelet transform has been widely used in the transformation research of many problems .

Function and file directory

 Insert picture description here
Effect display :
 Insert picture description here
 Insert picture description here
For the main function
main.m

close  all
I = imread('office_5.jpg');
I = rgb2gray(I);
W = imread('logo.tif');
W=W(12:91,17:96);
figure('Name',' Carrier image ')
imshow(I);
title(' Carrier image ')
figure('Name',' Watermark image ')
imshow(W);
title(' Watermark image ')
ntimes=23;
rngseed=59433;
flag=1;
[Iw,psnr]=setdwtwatermark(I,W,ntimes,rngseed,0);
[Wg,nc]=getdwtwatermark(Iw,W,ntimes,rngseed,0);
close all
action={
    'filter','resize','crop','noise','rotate'};
for i=1:numel(action)
    dwtwatermarkattack(action{
    i},Iw,W,ntimes,rngseed);
end

Watermark function 1

function [Wg,nc]=getdwtwatermark(Iw,W,ntimes,rngseed,flag)
[mW,nW]=size(W);
if mW~=nW
    error('GETDWTWATERMARK:ARNOLD','ARNOLD Scrambling requires that the length and width of the watermark image must be equal !')
end
Iw=double(Iw);
W=logical(W);
ca1w=dwt2(Iw,'haar');
ca2w=dwt2(ca1w,'haar');
Wa=W;
rng(rngseed);
idx=randperm(numel(ca2w),numel(Wa));
for i=1:numel(Wa)
    c=ca2w(idx(i));
    z=mod(c,nW);
    if z<nW/2
        Wa(i)=0;
    else
        Wa(i)=1;
    end
end
Wg=Wa;
H=[2 -1;-1,1]^ntimes;
for i=1:nW
    for j=1:nW
        idx=mod(H*[i-1;j-1],nW)+1;
        Wg(idx(1),idx(2))=Wa(i,j);
    end
end
nc=sum(Wg(:).*W(:))/sqrt(sum(Wg(:).^2))/sqrt(sum(W(:).^2));
if flag
    figure('Name',' Digital watermark extraction results ')
    subplot(121)
    imshow(W)
    title(' Original watermark ')
    subplot(122)
    imshow(Wg)
    title([' Extracting watermark ,NC=',num2str(nc)]);
end

Watermark function

function dwtwatermarkattack(action,Iw,W,ntimes,rngseed)
switch lower(action)
    case 'filter'
        Ia=imfilter(Iw,ones(3)/9);
    case 'resize'
        Ia=imresize(Iw,0.5);
        Ia=imresize(Ia,2);
    case 'noise'
        Ia=imnoise(Iw,'salt & pepper',0.01);
    case 'crop'
        Ia=Iw;
        Ia(50:400,50:400)=randn();
    case 'rotate'
        Ia=imrotate(Iw,45,'nearest','crop');
        Ia=imrotate(Ia,-45,'nearest','crop');
end
[Wg,nc]=getdwtwatermark(Ia,W,ntimes,rngseed,0);
figure('Name',[' Digital watermark  ',upper(action),'  Attack test '],'Position',[287,108,943,557]);
subplot(221)
imshow(Iw)
title(' Embedded watermark image ')
subplot(222)
imshow(Ia)
title([' Suffer  ',upper(action), '  attack '])
subplot(223)
imshow(W)
title(' Original watermark image ')
subplot(224)
imshow(Wg)
title([' Extracting watermark ,NC=',num2str(nc)]);

Watermark processing function

function [Iw,psnr]=setdwtwatermark(I,W,ntimes,rngseed,flag)
type=class(I);
I=double(I);
W=logical(W);
[mI,nI]=size(I);
[mW,nW]=size(W);
if mW~=nW
    error('SETDWTWATERMARK:ARNOLD','ARNOLD Scrambling requires that the length and width of the watermark image must be equal !')
end
[ca1,ch1,cv1,cd1]=dwt2(I,'haar');
[ca2,ch2,cv2,cd2]=dwt2(ca1,'haar');

if flag
    figure('Name',' Carrier wavelet decomposition ')
    subplot(121)
    imagesc([wcodemat(ca1),wcodemat(ch1);wcodemat(cv1),wcodemat(cd1)])
    title(' First level wavelet decomposition ')
    subplot(122)
    imagesc([wcodemat(ca2),wcodemat(ch2);wcodemat(cv2),wcodemat(cd2)])
    title(' Two level wavelet decomposition ')
end
Wa=W;
H=[1,1;1,2]^ntimes; 
for i=1:nW
    for j=1:nW
        idx=mod(H*[i-1;j-1],nW)+1;
        Wa(idx(1),idx(2))=W(i,j);
    end
end

if flag
    figure('Name',' Watermark scrambling effect ')
    subplot(121)
    imshow(W)
    title(' Original watermark ')
    subplot(122)
    imshow(Wa)
    title([' Scrambling watermark , Transformation Times =',num2str(ntimes)]);
end
ca2w=ca2;
rng(rngseed);
idx=randperm(numel(ca2),numel(Wa));
for i=1:numel(Wa)
    c=ca2(idx(i));
    z=mod(c,nW);
    if Wa(i)
        if z<nW/4
            f=c-nW/4-z;
        else
            f=c+nW*3/4-z;
        end
    else 
        if z<nW*3/4
            f=c+nW/4-z;
        else
            f=c+nW*5/4-z;
        end
    end
    ca2w(idx(i))=f;
end
ca1w=idwt2(ca2w,ch2,cv2,cd2,'haar');
Iw=idwt2(ca1w,ch1,cv1,cd1,'haar');
Iw=Iw(1:mI,1:nI);
mn=numel(I);
Imax=max(I(:));
psnr=10*log10(mn*Imax^2/sum((I(:)-Iw(:)).^2));
I=cast(I,type);
Iw=cast(Iw,type);
if flag
    figure('Name',' Embedded watermark image ')
    subplot(121)
    imshow(I);
    title(' original image ')
    subplot(122);
    imshow(Iw);
    title([' Add watermark ,PSNR=',num2str(psnr)]);
end

Mainly the addition of watermark 、 Get and process related . Embedded development .hhh
 Insert picture description here
 Insert picture description here

 Insert picture description here
This article is a complete set The source code file –—> Portal

原网站

版权声明
本文为[Haibao 7]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/173/202206220101377072.html