This repository was archived by the owner on Mar 7, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathRecover.m
86 lines (78 loc) · 2.17 KB
/
Recover.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
%file: Recovery.m
%to recover the image
%origin: the image after decipher progress
%blocksize: size of block
%MSB: the number of every bit in adjustment area used for adjustment
function ReImage = Recover( origin , blocksize , MSB )
ReImage = origin;
[M,N] = size(origin);
m = M/blocksize;
n = N/blocksize;
%divide all pixel into two different sets: CH & NC
%(whether it is changable)
%CH: EZ & EN & CN --- changable
%NC: not changable
DATA = zeros(1,((blocksize-2)*(blocksize-2))/2*m*n);%store the embedded message
no = 0; %means the number of elements in data
for i = 1 : m
for j = 1 : n
x = (i-1)*blocksize+1;
y = (j-1)*blocksize+1;
for p = x+1 : 1 : x+blocksize-2
for q = y+1 : 2 : y+blocksize-2
l = floor((origin(p,q)+origin(p,q+1))/2);
h = double(double(origin(p,q))-double(origin(p,q+1)));
min = 2*(255-l);
b = 2*l+1;
if b < min
min = b;
end
if abs(2*floor(h/2)+1) < min %changable
no = no+1;
a = Dec2bin(h);
[~,len] = size(a);
DATA(no) = a(len)-'0'; %the lowest of h is the embedded message
end
end
end
end
end
%calculate every block's data according to the DATA
board =zeros(1,m*n);
mess = zeros(1,((blocksize-2)*(blocksize-2))/2*m*n);
j = 1;%index of board
i = 1;%index of DATA
no = 1;%index of mess
temp = [1,1,1,1,1,1,1,1,0];
ending = [0,1,1,1,1,1,1,1,1,1,0];
while j <= m*n
if DATA(i:i+10) == ending(1:11)
board(j) = no-1;
j = j+1;
i = i+11;
elseif DATA(i:i+8) == temp(1:9)
mess(no:no+7) = temp(1:8);
no = no+8;
i = i+9;
else
mess(no) = DATA(i);
no = no+1;
i = i+1;
end
end
b = 0;
for i = 1 : m
for j = 1 : n
data = [];
x = (i-1)*blocksize+1;
y = (j-1)*blocksize+1;
t = (i-1)*m+j;
a = uint32(board(t));
if t > 1
b = uint32(board(t-1));
end
data(1:a-b) = mess(b+1:a);
ReImage = Extraction(ReImage,blocksize,x,y,MSB,data);
end
end
end