-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathOPAP.m
53 lines (48 loc) · 1.13 KB
/
OPAP.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
function EMPictureVector = OPAP(BinaryList,PictureVector)
P = PictureVector;
NP = P;
B = BinaryList;
sliced_cell = cutbin(B,2);
[col,row] = size(P);
if length(sliced_cell)>col*row
disp('The length of binary list is larger than picture matrix!');
else
for k = 1:length(sliced_cell)
NP(k) = OPAP_Dot(P(k),sliced_cell{k});
end
end
EMPictureVector = NP;
end
%Optimal Pixel Adjustment Process(OPAP)
%Pixel is the original pixel
function MPixel = OPAP_Dot(Pixel,Sliced_Bin)
r = length(Sliced_Bin);
s_bin = num2str(Sliced_Bin);
s = bin2dec(s_bin);
p_bin = dec2bin(Pixel,8);
v_bin = [p_bin(1:length(p_bin)-r),s_bin];%Embeded binary
v = bin2dec(v_bin);
vr_bin = p_bin(length(p_bin)-r+1:end);
vr = bin2dec(vr_bin);
if (vr-s>2^(r-1))&&(v+2^r<=255)
MPixel = v+2^r;
elseif (vr-s<-2^(r-1))&&(v-2^r>=0)
MPixel = v-2^r;
else
MPixel = v;
end
end
%¶þ½øÖƵÄÇÐƬ
function output = cutbin(binvec,r)
Len = length(binvec);
Num = ceil(Len/r);
sliced_cell = cell(1,Num);
for k = 1:Num
if k*r>Len
sliced_cell{k} = binvec(k*r-r+1:end);
else
sliced_cell{k} = binvec(k*r-r+1:k*r);
end
end
output = sliced_cell;
end