-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.m
115 lines (101 loc) · 4.89 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
clc;
tic
initb4xecn;
disp('Stego Embedding Process:');
disp('_______________________________________________________________________');
stegoText = 'Hello!';
str2binary = charStringtoBin(stegoText);
pk = 1;
%% =======================================================
for findex=3:size(ImageSetFolder,1)
fprintf('%d. Processing: %s\n',findex-2,ImageSetFolder(findex).name);
[hpathstr,hname,hext] = fileparts(ImageSetFolder(findex).name);
coverImgUrl=strcat(ImageSetDirURL,'\',ImageSetFolder(findex).name);
disp(strcat(' Host Image: <a href="matlab:winopen(''',coverImgUrl,''')" > ',ImageSetFolder(findex).name,'</a>'));
OutputImageFilepath = strcat(StegoDir,hname,'.tif');
coverImage = imread(coverImgUrl);
img2reduced = imresize(coverImage, 0.50);
modifiedImage = img2reduced;
[rows, columns, NoOfchannels] = size(img2reduced);
dimenGrayImg = [rows, columns];
% str2binary = [1 0 1 0 1 0 0 1 1];
startptofstr = 1;
for i=1:dimenGrayImg(1)
% disp('--------------');
if mod(i,2)~=0
for j=3:5:(dimenGrayImg(2)-2)
% disp([i,j]);
p1 = img2reduced (i,j-2,3);
p2 = img2reduced (i,j-1,3);
p3 = img2reduced (i,j,3);
p4 = img2reduced (i,j+1,2);
p5 = img2reduced(i,j+2,2);
% disp([p1,p2,p3,p4,p5]);
[ p1str,p2str,p3str, endpt ] = embeddingAlgo( p1,p2,p3,str2binary,startptofstr );
startptofstr = endpt + 1;
[ p4str1,p5str1,endpt ] = pvd( p4,p5,str2binary,startptofstr );
% [ p4str,p5str ] = fixOverFlowUnderflows( p4str1,p5str1 );
p4str = p4str1;
p5str = p5str1;
startptofstr = endpt + 1;
modifiedImage (i,j-2,3) = p1str;
modifiedImage (i,j-1,3) = p2str;
modifiedImage (i,j,3) = p3str;
modifiedImage (i,j+1,2) = p4str;
modifiedImage (i,j+2,2) = p5str;
% disp('________________');
end
else
for j=(dimenGrayImg(2)-2):-5:3
% disp([i,j]);
p1 = img2reduced (i,j+2,3);
p2 = img2reduced (i,j+1,3);
p3 = img2reduced (i,j,3);
p4 = img2reduced (i,j-1,2);
p5 = img2reduced (i,j-2,2);
% disp([p1,p2,p3,p4,p5]);
[ p1str,p2str,p3str, endpt ] = embeddingAlgo( p1,p2,p3,str2binary,startptofstr );
startptofstr = endpt + 1;
[ p4str1,p5str1,endpt ] = pvd( p4,p5,str2binary,startptofstr );
% [ p4str,p5str ] = fixOverFlowUnderflows( p4str1,p5str1 );
p4str = p4str1;
p5str = p5str1;
startptofstr = endpt + 1;
modifiedImage (i,j+2,3) = p1str;
modifiedImage (i,j+1,3) = p2str;
modifiedImage (i,j,3) = p3str;
modifiedImage (i,j-1,2) = p4str;
modifiedImage (i,j-2,2) = p5str;
% disp('________________');
end
end
end
peaksnr(pk,1) = findex-2;
[peaksnr(pk,2),~]=psnr(double(img2reduced),double(modifiedImage),255);
[ fobp,capacity,bpp ] = measureParamters( img2reduced, modifiedImage );
peaksnr(pk,3) = fobp;
%% Histograms
% % Before Steganography.
imagePath = strcat(HISTODIR,'B4Steg-',ImageSetFolder(findex).name);
imhist(rgb2gray(img2reduced));
saveas(gcf, imagePath);
disp(strcat(' Histogram b4 Stego: <a href="matlab:winopen(''',imagePath,''')" > B4Steg-',ImageSetFolder(findex).name,'</a>'));
%% Steganography, after process.
disp(strcat(' Stego-Image: <a href="matlab:winopen(''',OutputImageFilepath,''')" > ',ImageSetFolder(findex).name,'</a>'));
% % After Steganography.
imagePath = strcat(HISTODIR,'Stego-',ImageSetFolder(findex).name);
imhist(rgb2gray(modifiedImage));
saveas(gcf, imagePath);
disp(strcat(' Histogram After Stego: <a href="matlab:winopen(''',imagePath,''')" > Stego-',ImageSetFolder(findex).name,'</a>'));
% Results: PSNR, FOBP
fprintf(' For %s PSNR = %.4f, FOBP = %.4f \n',ImageSetFolder(findex).name,peaksnr(pk,2),peaksnr(pk,3));
imwrite(modifiedImage,OutputImageFilepath);
pk = pk + 1;
disp('_______________________________________________________________________');
end
clear p1 p2 p3 p4 p5 p1str p2str p3str p4str p5str pk i j;
%% Excel report of Steganographic results.
xlswrite(strcat(EXCELDIR,'\Steganography Results.xlsx'), peaksnr);
disp(' PSNR Report File of Watermarked Images: <a href="matlab:winopen(strcat(EXCELDIR,''\Steganography Results.xlsx''))">Steganography Results.xlsx</a>');
% =======================================================
toc;