-
Notifications
You must be signed in to change notification settings - Fork 22
/
dwtrecover.m
54 lines (40 loc) · 1.37 KB
/
dwtrecover.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
function [message_vector,Mo,No] = dwtrecover(watermrkd_img,k,message)
watermarked_image= watermrkd_img;
% determine size of watermarked image
Mw=size(watermarked_image,1); %Height
Nw=size(watermarked_image,2); %Width
Ow=size(watermarked_image,3);
% read in original watermark
orig_watermark=double(message);
% determine size of original watermark
Mo=size(orig_watermark,1); %Height
No=size(orig_watermark,2); %Width
% read in key for PN generator
file_name='_key.bmp';
key=double(imread(file_name))./256;
% reset MATLAB's PN generator to state "key"
j = 1;
for i =1:length(key)
rand('state',key(i,j));
end
message_vector=ones(1,Mo*No);
[cA1,cH1,cV1,cD1] = dwt2(watermarked_image,'haar');
% add pn sequences to H1 and V1 componants when message = 0
for (kk=1:length(message_vector))
pn_sequence_h=round(2*(rand(Mw/2,Nw/2,Ow)-0.5));
pn_sequence_v=round(2*(rand(Mw/2,Nw/2,Ow)-0.5));
if (message(kk) == 0)
% cH1(:,:,1)=cH1(:,:,1)+k*pn_sequence_h;
% cV1(:,:,1)=cV1(:,:,1)+k*pn_sequence_v;
cH1=cH1+k*pn_sequence_h;
cV1=cV1+k*pn_sequence_v;
end
cor_h(kk)=corr2(pn_sequence_h(:,:,1),cH1(:,:,1));
cor_v(kk)=corr2(pn_sequence_v(:,:,1),cV1(:,:,1));
if cor_h(kk) > cor_v(kk)
message_vector(kk)=0;
else
message_vector(kk)=1;
end
end
end