-
Notifications
You must be signed in to change notification settings - Fork 1
/
Histogram_shifting_embedding.m
70 lines (59 loc) · 1.42 KB
/
Histogram_shifting_embedding.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
clc;
clear all;
close all;
%-----Import the Cover Image-----%
I = imread('lena2.tif');
if ndims(I) > 2
I = rgb2gray(I);
end
[m, n] = size(I);
b = [];
%-----Histogram Processing-----%
[counts, binLoc] = imhist(I);
P = binLoc(counts == max(counts));
Zeros = binLoc(counts == 0);
diff = abs(Zeros - P);
Z = Zeros(diff == min(diff));
%-----Secret Data Embedding-----%
I = I(:);
count = 1;
s = I;
if P > Z
for ii = 1:length(I)
if I(ii) > Z && I(ii) <= P
if I(ii) == P
b(count) = randi([0, 1]);
s(ii) = s(ii) - 1 + b(count);
count = count + 1;
else
s(ii) = s(ii) - 1;
end
end
% if count > length(b) % Uncomment if length of b is known
% break
% end
end
elseif P < Z
for ii = 1:length(I)
if I(ii) >= P && I(ii) < Z
if I(ii) == P
b(count) = randi([0, 1]);
s(ii) = s(ii) + 1 - b(count);
count = count + 1;
else
s(ii) = s(ii) + 1;
end
end
% if count > length(b) % Uncomment if length of b is known
% break
% end
end
end
s = reshape(s, m, n);
subplot(1, 2, 1);
imhist(I);
title("Cover Image Histogram");
subplot(1, 2, 2);
imhist(s);
title('Stego Image Histogram');
save('Histogram_Shifting_Embedding', 's', 'b', 'P', 'Z');