-
Notifications
You must be signed in to change notification settings - Fork 25
/
main.m
240 lines (222 loc) · 8.67 KB
/
main.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
%% Digital image watermarking
% Digital Image Watermarking method based on hybrid DWT-HD-SVD Technique:
% Attacks, PSNR, SSIM, NC
%
% Source: https://github.com/Saeid-jhn/Digital-Image-Watermarking
% Referance paper: https://ieeexplore.ieee.org/document/8709684)
% Author: Saeid Jahandar
%% Intilize
clc
clear
close all
%% Import image
cover_image=imread('lena512.bmp');
watermark_logo=imread('cameraman.tif');
%% Plot cover image and watermark image
figure
subplot(1,2,1);
imshow(cover_image);
title('Cover image: 512 x 512');
subplot(1,2,2);
imshow(watermark_logo);
title('Watermark image: 256 x 256');
%% Example: watermark embedding and exraction alpha=0.1 Attack: Sharpening
method = 'DWT-HD-SVD'; % Apply 'DWT-HD-SVD Method
alpha = 0.1;
attack = 'Motion blur'; % You can choose other attacks
param = 0.5; % attack parameter
[watermarked_image, extracted_watermark] = watermark(cover_image,...
watermark_logo,method,alpha,attack,param);
% Plot results
figure;
subplot(2, 2, 1);
imshow(cover_image);
xlabel('a) Cover image');
subplot(2, 2, 2);
imshow(watermarked_image);
xlabel('b) Watermarked image');
subplot(2, 2, 3);
imshow(watermark_logo);
xlabel('c) Watermark logo');
subplot(2, 2, 4);
imshow(extracted_watermark);
xlabel('d) Extracted watermark');
sgtitle(['DWT-HD-SVD method \alpha = '+string(alpha) attack]);
%% NC vs alpha DWT-HD-SVD figure 5
% Plot normalized correlation for different alpha
method = 'DWT-HD-SVD';
alpha =0.005:0.005:0.2;
attacks = {'No Attack'; 'Gaussian low-pass filter'; 'Median';...
'Gaussian noise'; 'Salt and pepper noise';'Speckle noise';...
'JPEG compression'; 'JPEG2000 compression'; 'Sharpening attack';...
'Histogram equalization'; 'Average filter'; 'Motion blur'};
% Attack papameters
params = [0; 3; 3; 0.001; 0; 0; 50; 12; 0.8; 0; 0; 0];
NC = NC_alpha(cover_image,watermark_logo,method,alpha,attacks,params);
%% plot NC vs alpha figure 5
NC_plot(alpha,NC,attacks);
%% PSNR vs alpha DWT-HD-SVD
method = 'DWT-HD-SVD';
alpha =0.005:0.005:0.2;
attacks = {'No Attack'; 'Gaussian low-pass filter'; 'Median'; 'Gaussian noise';...
'Salt and pepper noise';'Speckle noise'; 'JPEG compression';...
'JPEG2000 compression'; 'Sharpening attack'; 'Histogram equalization';...
'Average filter'; 'Motion blur'};
params = [0; 3; 3; 0.001; 0; 0; 50; 12; 0.8; 0; 0; 0];
PSNR = PSNR_alpha(cover_image,watermark_logo,method,alpha,attacks,params);
%% plot PSNR vs alpha
PSNR_plot(alpha,PSNR,attacks);
%% SSIM vs alpha DWT-HD-SVD figure 7 paper (see README)
method = 'DWT-HD-SVD';
alpha =0.005:0.005:0.2;
attacks = {'No Attack'; 'Gaussian low-pass filter'; 'Median'; 'Gaussian noise';...
'Salt and pepper noise';'Speckle noise'; 'JPEG compression';...
'JPEG2000 compression'; 'Sharpening attack'; 'Histogram equalization';...
'Average filter'; 'Motion blur'};
params = [0; 3; 3; 0.001; 0; 0; 50; 12; 0.8; 0; 0; 0];
SSIM = SSIM_alpha(cover_image,watermark_logo,method,alpha,attacks,params);
%% plot SSIM vs alpha
SSIM_plot(alpha,SSIM,attacks);
%% FIGURE 8. Invisibility performance: Watermarked images and corresponding extracted
% watermarks with various sizes and their corresponding PSNRs, SSIMs and NCs.
method = 'DWT-HD-SVD';
alpha =0.05;
attack = 'No Attack';
param = 0;
figure
for i=1:3
watermark_logoi = imresize(watermark_logo,2^(-i+1));
[watermarked_image, extracted_watermark] = watermark(cover_image,watermark_logoi,method,alpha,attack,param);
PSNR = psnr(watermarked_image, cover_image);
SSIM = ssim(watermarked_image, cover_image);
NC = nc(watermark_logoi,extracted_watermark);
subplot(2,3,i);
imshow(watermarked_image);
title(['watermarked image';'watermark size '+string(length(watermark_logoi))+'x'+string(length(watermark_logoi))]);
xlabel(['PSNR='+string(PSNR);'SSIM='+string(SSIM)]);
subplot(2,3,i+3);
imshow(extracted_watermark);
title('extracted watermark');
xlabel('NC='+string(NC));
end
sgtitle('DWT-HD-SVD: Invisibility performance: watermarks with various sizes; alpha='+string(alpha)+'; No Attack');
%% plot watermarked image for different attacks and watermark sizes
method = 'DWT-HD-SVD';
alpha =0.05;
attacks = {'No Attack'; 'Gaussian low-pass filter'; 'Median'; 'Gaussian noise';...
'Salt and pepper noise';'Speckle noise'; 'JPEG compression';...
'JPEG2000 compression'; 'Sharpening attack'; 'Histogram equalization';...
'Average filter'; 'Motion blur'};
params = [0; 3; 3; 0.001; 0; 0; 50; 12; 0.8; 0; 0; 0];
for i=3:-1:1
watermark_logoi = imresize(watermark_logo,2^(1-i));
figure
for j=1:length(attacks)
attack = string(attacks(j));
param = params(j);
[watermarked_image, extracted_watermark] = watermark(cover_image,watermark_logoi,method,alpha,attack,param);
PSNR = psnr(watermarked_image, cover_image);
SSIM = ssim(watermarked_image, cover_image);
subplot(3,4,j);
imshow(watermarked_image);
xlabel(['PSNR='+string(PSNR);'SSIM='+string(SSIM)]);
title(attack);
end
sgtitle(['DWT-HD-SVD: Attacked watermarked image; Size = '+string(length(watermark_logoi))+'x'+string(length(watermark_logoi))+'; \alpha = '+string(alpha)]);
end
%% FIGURE 10. Extracted watermarks from the attacked watermarked images
% Evaluate robustness performance
method = 'DWT-HD-SVD';
alpha =0.05;
attacks = {'No Attack'; 'Gaussian low-pass filter'; 'Median'; 'Gaussian noise';...
'Salt and pepper noise';'Speckle noise'; 'JPEG compression';...
'JPEG2000 compression'; 'Sharpening attack'; 'Histogram equalization';...
'Average filter'; 'Motion blur'};
params = [0; 3; 3; 0.001; 0; 0; 50; 12; 0.8; 0; 0; 0];
for i=3:-1:1
watermark_logoi = imresize(watermark_logo,2^(1-i));
figure
for j=1:length(attacks)
attack = string(attacks(j));
param = params(j);
[watermarked_image, extracted_watermark] = watermark(cover_image,watermark_logoi,method,alpha,attack,param);
NC = nc(watermark_logoi,extracted_watermark);
subplot(3,4,j);
imshow(extracted_watermark);
xlabel([attack 'NC='+string(NC)]);
end
sgtitle(['DWT-HD-SVD: Extracted watermarks image from the attacked watermarked images; Size = '+string(length(watermark_logoi))+'x'+string(length(watermark_logoi))+'; \alpha = '+string(alpha)]);
end
%% FIGURE 11. NC values under different parameters suffering various attacks
watermark_logo1 = watermark_logo;
watermark_logo2 = imresize(watermark_logo,0.5);
watermark_logo3 = imresize(watermark_logo,0.25);
method = 'DWT-HD-SVD';
alpha =0.1;
attacks = {'JPEG compression';'JPEG2000 compression';'Gaussian low-pass filter';...
'Median';'Gaussian noise';'Sharpening attack'};
figure
for j = 1:length(attacks)
attack = string(attacks(j));
params = 0;
switch attack
case 'JPEG compression'
params = 10:10:90;
y = [0.98 1];
x = [0 100];
ticks = string(params);
label = 'Quality Factor (QF)';
case 'JPEG2000 compression'
params = 4:4:36;
y = [0.98 1];
ticks = string(params);
label = 'Compression Ratio (CR)';
case 'Gaussian low-pass filter'
params = 0.5:0.5:4.5;
y = [0.9 1];
ticks = string(params);
label = 'sigma';
case 'Median'
params = 3:7;
y = [0.86 1];
ticks = {'3x3','4x4','5x5','6x6','7x7'};
label = 'Window size';
case 'Gaussian noise'
params = 0.001:0.002:0.009;
y = [0.88 1];
ticks = string(params);
label = 'Variance';
case 'Sharpening attack'
params = 0.1:0.1:0.9;
y = [0.96 1];
ticks = string(params);
label = 'Strength (1-Threshold)';
end
NC1 = 0;
NC2 = 0;
NC3 = 0;
for i = 1:length(params)
[watermarked_image1, extracted_watermark1] = watermark(cover_image,watermark_logo1,method,alpha,attack,params(i));
[watermarked_image2, extracted_watermark2] = watermark(cover_image,watermark_logo2,method,alpha,attack,params(i));
[watermarked_image3, extracted_watermark3] = watermark(cover_image,watermark_logo3,method,alpha,attack,params(i));
NC1(i) = nc(watermark_logo1,extracted_watermark1);
NC2(i) = nc(watermark_logo2,extracted_watermark2);
NC3(i) = nc(watermark_logo3,extracted_watermark3);
end
subplot(3,2,j)
plot(params,NC1,'k<-');
hold on
plot(params,NC2,'rs-');
hold on
plot(params,NC3,'g^-');
hold off
grid on
ylim(y);
xticks(params);
xticklabels(ticks);
xlabel(label);
ylabel('NC(W,W^*)');
legend('256 x 256', '128 x 128', '64 x 64', 'Location', 'southwest');
title(attacks(j));
end
sgtitle('DWT-HD-SVD: NC values under different parameters suffering various attacks.');