-
Notifications
You must be signed in to change notification settings - Fork 0
/
waveletstego.m
79 lines (60 loc) · 1.83 KB
/
waveletstego.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
% Wavelet steganography scheme
close all;
clear all;
%% 1
% Read in the input data and set script parameters
im = imread("coverimage1024.jpg");
im_stego = imread("stegoimage512.png");
im = im2gray(im);
im_stego = im2gray(im_stego);
% normalize hidden image
im_stego = double(im_stego)/255;
%set wavelet
wvlet = 'haar'
%% 2
% Call the waveletSteganography() routine to process the image data
stegoimage = waveletSteganography(im,im_stego,wvlet);
imshow(uint8(stegoimage));
%% 3
% Reconstruct the hidden image
[c,s] = wavedec2(stegoimage,2,wvlet);
[H1,V1,D1] = detcoef2('all',c,s,1);
rec = H1(1:size(im_stego,1),1:size(im_stego,2));
figure;
imshow(rec)
%% 4
% Do comparisons
% Print and visualize results
psnrCover = psnr(im,uint8(stegoimage));
l2errorCover = norm(double(im(:)) - stegoimage(:)) /norm(double(im(:)));
structsimCover = ssim(double(im),stegoimage);
fprintf("Cover Image PSNR=%1.2f, Relative L2 Error %1.2f, SSIM %1.2f \n",...
psnrCover,l2errorCover,structsimCover);
psnrHidden = psnr(rec,im_stego);
l2errorHidden = norm(im_stego(:) - rec(:)) /norm(im_stego(:));
structsimHidden = ssim(im_stego,rec);
fprintf("Recovered Hidden Image PSNR=%1.2f, Relative L2 Error %1.2f, SSIM %1.2f\n",...
psnrHidden,l2errorHidden,structsimHidden);
%% 5
% Visualize the method by checking the wavelet coefficients of the
% acquired stegoimage
[H1,V1,D1] = detcoef2('all',c,s,1);
A1 = appcoef2(c,s,wvlet,1);
V1img = wcodemat(V1,255,'mat',1);
H1img = wcodemat(H1,255,'mat',1);
D1img = wcodemat(D1,255,'mat',1);
A1img = wcodemat(A1,255,'mat',1);
figure;
subplot(2,2,1)
imagesc(A1img)
colormap pink(255)
title('Approximation Coef. of Level 1')
subplot(2,2,2)
imagesc(H1img)
title('Horizontal Detail Coef. of Level 1')
subplot(2,2,3)
imagesc(V1img)
title('Vertical Detail Coef. of Level 1')
subplot(2,2,4)
imagesc(D1img)
title('Diagonal Detail Coef. of Level 1')