WMW
  NEWS     ABOUT     PARTNERS     CONTACT  
  HELP
WATERMARKING
  • Biography
  • FAQ
MAILINGLIST
  • Management
  • Archive
CONFERENCES
  • Calls
BENCHMARKING
  • Stirmark
  • CheckMark
  • Optimark
BOOKS
LINKS
  • Companies
  • Research
  • Others
WEBRING
DISCLAIMER

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [WM]: Need help with implemetation of Hybrid algorithm by Deguillaume,Voloshynovskiy and Pun



Hello again,

I just found out that the attached files did not come through.
Hence i have copied and pasted the files down here:


% Robust Watermarking Part

%Encoding PART
clear all;close all;
% Generate Watermark : pseudo random sequence of size
178
size_m =178; % Size of the vector of pseudo random sequence

% c is the codeword ie watermark
c = randn(1,size_m);

% map codeword c to a set of {-1,1}
idx = find(c < 1);
c(idx) = -1;
idx = find(c >= 1);
c(idx) = 1;


% create a t1 x t2 matrix of zeros 
size_of_t1t2=16;

% 16 x 16 = 256 , 178 Winf - robust position , 42 Wref
- fragile position ,36 bit empty - could be used for
fragile position

positions=ones(size_of_t1t2,size_of_t1t2);% this
matrix is just to track the positions of ref,info, and
empty bits

%Phase 1:Inserting the Reference position (total 42
ref positions)
for i=2:2:size_of_t1t2
    for j=2:3:size_of_t1t2
         positions(i,j)=-1;
    end
end
positions(3,3)=-1;
positions(15,15)=-1;

%Phase 2:Inserting the Empty part (total 36 empty
positions)
for i=1:3:size_of_t1t2
    for j=1:3:size_of_t1t2
        positions(i,j)=0;
    end
end

%Phase 3:The remaining zeros belong to the Information
watermark winfo (total 178 info positions)
%ref=-1, empty=0, info=1
no_of_ref = find(positions == -1);
no_of_empty = find(positions == 0);
no_of_info = find(positions == 1);


%copy the codeword c in the matrix in the information
bits only;
%t1t2=positions; %create a matrix similar to position
matrix
t1t2=zeros(size_of_t1t2,size_of_t1t2);
count=1;

for i=1:size_of_t1t2
        for j=1:size_of_t1t2
            
            if (count <= size_m)
                if(positions(i,j) == 1)
                t1t2(i,j)=c(count);
                count=count+1; 
                end
               
            end
        end
    end
        
%Upsample the matrix t1t2 by a factor of 2
t1t2_upsampled = imresize(t1t2, 2);
pos_upsampled=imresize(positions, 2);

F1 = fliplr(t1t2_upsampled);%flipright
F2 = flipud(F1);%flipdown
F3 = fliplr(F2);%flipleft

P1 = fliplr(pos_upsampled);%flipright
P2 = flipud(P1);%flipdown
P3 = fliplr(P2);%flipleft

Wpattern = [t1t2_upsampled F1; F3 F2]; % 64x64
position_matrix=[pos_upsampled P1; P3 P2]; %64x64

WM=[Wpattern Wpattern; Wpattern Wpattern]; %128x128
position1=[position_matrix
position_matrix;position_matrix position_matrix];
%128x128

%tiled watermark
watermark=[WM WM;WM WM]; %256x256
%tiled position matrix
position_matrix_tiled=[position1 position1;position1
position1]; %256x256

% read in the cover object
file_name='Lena256gray.bmp'; %256x265 image size
cover_object=imread(file_name);

%Using Discrete Wavelet Transform- Debachies 8 level 5
 
 tic  % starts a stopwatch timer.
	
% step 1a: decompose Image into 5 levels with
Daubechies-8 filter

%EMBEDDING PART

    Img=cover_object;
    Levels = 5;  % Five sub bands decomposition
	[C,S] = wavedec2(Img,Levels,'db8');  % why not this
[swa,swh,swv,swd] = swt2(Img,Levels,'db6');
	% extract all sub bands 
	coA1 = appcoef2(C,S,'db8',1);
	coA2 = appcoef2(C,S,'db8',2);
	coA3 = appcoef2(C,S,'db8',3);
	coA4 = appcoef2(C,S,'db8',4);
   	coA5 = appcoef2(C,S,'db8',5);
	[coH1,coV1,coD1] = detcoef2('all',C,S,1); 
	[coH2,coV2,coD2] = detcoef2('all',C,S,2); 
	[coH3,coV3,coD3] = detcoef2('all',C,S,3); 
	[coH4,coV4,coD4] = detcoef2('all',C,S,4); 
	[coH5,coV5,coD5] = detcoef2('all',C,S,5); 

% step 1b: decompose Watermark into 5 levels with
Daubechies-8 filter
    
    [Cw,Sw] = wavedec2(watermark,Levels,'db8');  % why
not this [swa,swh,swv,swd] = swt2(Img,Levels,'db6');
	% extract all sub bands 
	coA1w = appcoef2(Cw,Sw,'db8',1);
	coA2w = appcoef2(Cw,Sw,'db8',2);
	coA3w = appcoef2(Cw,Sw,'db8',3);
	coA4w = appcoef2(Cw,Sw,'db8',4);
   	coA5w = appcoef2(Cw,Sw,'db8',5);
	[coH1w,coV1w,coD1w] = detcoef2('all',Cw,Sw,1); 
	[coH2w,coV2w,coD2w] = detcoef2('all',Cw,Sw,2); 
	[coH3w,coV3w,coD3w] = detcoef2('all',Cw,Sw,3); 
	[coH4w,coV4w,coD4w] = detcoef2('all',Cw,Sw,4); 
	[coH5w,coV5w,coD5w] = detcoef2('all',Cw,Sw,5); 


%Step 2  Do an additive embedding ie:  x'= x +
(alpha*w)
alpha=1;
%Level 1
coH1x=coH1+(alpha*coH1w);
coV1x=coV1+(alpha*coV1w);    
coD1x=coD1+(alpha*coD1w);    
clear coH1 coV1 coD1 coH1w coV1w coD1w;

%Level 2
coH2x=coH2+(alpha*coH2w);
coV2x=coV2+(alpha*coV2w);    
coD2x=coD2+(alpha*coD2w);    
clear coH2 coV2 coD2 coH2w coV2w coD2w;

%Level 3
coH3x=coH3+(alpha*coH3w);
coV3x=coV3+(alpha*coV3w);    
coD3x=coD3+(alpha*coD3w);    
clear coH3 coV3 coD3 coH3w coV3w coD3w;

%Level 4
coH4x=coH4+(alpha*coH4w);
coV4x=coV4+(alpha*coV4w);    
coD4x=coD4+(alpha*coD4w);    
clear coH4 coV4 coD4 coH4w coV4w coD4w;

%Level 5
coH5x=coH5+(alpha*coH5w);
coV5x=coV5+(alpha*coV5w);    
coD5x=coD5+(alpha*coD5w);    
clear coH5 coV5 coD5 coH5w coV5w coD5w;



%Step:Perform the IDWT starting from level 5
  	Level5_IDWT= idwt2(coA5,coH5x,coV5x,coD5x,'db8');
  %  figure; imshow(uint8(Level5_IDWT)); title('IDWT
Level 5');
    
 %Step:Perform the IDWT starting from level 4
    Level4_IDWT=
idwt2(Level5_IDWT,coH4x,coV4x,coD4x,'db8',45);   
%Level_4_IDWT is a 46 x 46 matrix, we need to convert
it to 45x45
   % figure; imshow(uint8(Level4_IDWT)); title('IDWT
Level 4');
  
    %hence take one row and one column off
    
    
 %Step:Perform the IDWT starting from level 3
  	Level3_IDWT=
idwt2(Level4_IDWT,coH3x,coV3x,coD3x,'db8',75);
   % figure; imshow(uint8(Level3_IDWT)); title('IDWT
Level 3');
    
 
 %Step:Perform the IDWT starting from level 2
  	Level2_IDWT=
idwt2(Level3_IDWT,coH2x,coV2x,coD2x,'db8',135);
   % figure; imshow(uint8(Level2_IDWT)); title('IDWT
Level 2');

 %Step:Perform the IDWT starting from level 1
  	Level1_IDWT =
idwt2(Level2_IDWT,coH1x,coV1x,coD1x,'db8');
    figure; imshow(Level1_IDWT,[]); title('Watermaked
Recomposed to IDWT Level 1');
    figure; imshow(cover_object,[]);
title('Original');
    figure; imshow(watermark); title('Tiled Wmarked');
 
 rob_marked=uint8(Level1_IDWT);
 imwrite(rob_marked,'robust.bmp','bmp');

 save('markedInfo.mat', 'Level1_IDWT', 'watermark',
'cover_object','position_matrix_tiled'); 
%  	EmbedTime = toc;   % the elapsed time since tic
was used. 

------------------------------------------
END OF EMBED FILE
-----------------------------------

Now the detect file
------------------------

% Robust Watermarking Part

%DETECTION OF THE WATERMARK

clear all;close all;
load('markedInfo.mat');  % load 'Level1_IDWT',
'watermark', 'cover_object','position_tiled_matrix

figure; imshow(watermark); title('Watermark');

%Finding the local variance of the stego image

%First need to find local neighbourhood varianve of
the stego image of
%neghbours 5x5

Var_Stego_Image= nlfilter(Level1_IDWT, [3 3],
'var(x(:))');  % for a 3x3


%the global mean value of the of the watermark
variance is:
global_mean_watermark=mean2(Var_Stego_Image);

%Obtaing a varaince matrix of x
x_var=Var_Stego_Image-global_mean_watermark;
%Since we need to take the maxium
max{0,x_var(n1,n2)..I will create a
%matrix to do that

x_var_max=zeros(256,256);
for i=1:256
    for j=1:256
        if(x_var(i,j)>0)
            x_var_max(i,j)=x_var(i,j);
        end
    end
end

%local mean of stego image y is:

%Mean_Stego_Image
Y_mean= nlfilter(Level1_IDWT, [3 3], 'mean2');  % for
a 3x3
%load('Y_mean.mat'); %Load up Y_mean matrix
%y'-y' mean
Y_bar_less_mean=Level1_IDWT-Y_mean;
w_denominator=global_mean_watermark+x_var_max;

watermark_estimate = global_mean_watermark *
(Y_bar_less_mean ./ w_denominator);


figure; imshow(watermark_estimate,[]);
title('Estimated Watermark');

save('d_robust_Info.mat','watermark_estimate','watermark');


%obtaining the peaks
        WMfft = fft2(watermark_estimate);
 		WMfft1 = abs(WMfft);
 		WMfftest = WMfft1 .* WMfft1;
        InvWMfftest=ifft2(WMfftest);
   
        % these should show watermark template
patterns
        figure; imshow(Mfftest,[]); title('fft
estimated WM peaks')
        figure; imshow(InvWMfftest,[]); title('Inv
estimated WM peaks')
 		

        % check original embedded watermark peaks
        watermark_embedded = watermark;
  		WMfft = fft2(watermark_embedded);
 		WMfft2 = abs(WMfft);
 		WMfftemb = WMfft2 .* WMfft2;
 		InvWMfftemb=ifft2(WMfftemb);
        
        figure; imshow(WMfftemb,[]); title('fft
embedded WM peaks')
        figure; imshow(InvWMfftemb,[]); title('Inv
embedded WM peaks')
        
----------------------
End of detect file
--------------------  



______________________________________________________________________________

Watermarking Mailing List - http://www.watermarkingworld.org/ml.html
To unsubscribe send email to "majordomo@watermarkingworld.org" with
"unsubscribe watermarking YOURMAIL" in the body.
______________________________________________________________________________




© 2000-2002 by WatermarkingWorld
Design and Concept by Martin Kutter