-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathq3_2_3_DCT8andZigzagScan.m
More file actions
38 lines (37 loc) · 1.07 KB
/
q3_2_3_DCT8andZigzagScan.m
File metadata and controls
38 lines (37 loc) · 1.07 KB
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
function out = q3_2_3_DCT8andZigzagScan(in, hide_msg)
N = 8;
in = in - 128;
zigzag8_ind = [1,9,2,3,10,17,25,18,...
11,4,5,12,19,26,33,41,...
34,27,20,13,6,7,14,21,...
28,35,42,49,57,50,43,36,...
29,22,15,8,16,23,30,37,...
44,51,58,59,52,45,38,31,...
24,32,39,46,53,60,61,54,...
47,40,48,55,62,63,56,64]'; %generate by zigzag.m
%value fixed for enhanced efficiency
QTAB = [16,11,10,16,24,40,51,61;...
12,12,14,19,26,58,60,55;...
14,13,16,24,40,57,69,56;...
14,17,22,29,51,87,80,62;...
18,22,37,56,68,109,103,77;...
24,35,55,64,81,104,113,92;...
49,64,78,87,103,121,120,101;...
72,92,95,98,112,100,103,99]; %adapted from 'JpegCoeff.mat'
n = 0 : 1: N-1;
DCT = sqrt(2/N)*diag([sqrt(1/2), ones(1,N-1)])*cos(n'*(2*n + 1)*pi/(2*N));
in_DCT = DCT*in*DCT';
%in_DCT = dct2(in);
in_DCT = round(in_DCT./QTAB);
%process message hiding
out = in_DCT(zigzag8_ind);
ind = length(out) - find(flip(out),1) + 2;
if(ind > length(out))
ind = length(out);
end
if(hide_msg == 0)
out(ind) = -1;
else
out(ind) = 1;
end
end