?? dct_det.asv
字號:
function dct_det(attacked)
Q_table=[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
];
ZT=attacked;
[m n]=size(ZT);
chuangai=zeros(m,n);
quality=50;
%塊dct變換
for i=1:(m/8);
for j=1:(n/8);
width=(i-1)*8+1;
height=(j-1)*8+1;
imdct(width:(width+7),height:(height+7))=dct2(ZT(width:(width+7),height:(height+7)));
end
end
%開辟要比較的數據空間
Q=zeros(1,m*n/8/8*6);
watermark=zeros(1,m*n/8/8*6);
%比較zig-zag前6個對應系數
k=1;
for i=1:(m/8/2);
for j=1:(n/8);
width=(i-1)*16+1;
height=(j-1)*8+1;
l=(k-1)*6+1;
if imdct(width,height)-imdct(width+8,height)<0
Q(l)=0;
else
Q(l)=1;
end
if imdct(width+1,height)-imdct(width+9,height)<0
Q(l+1)=0;
else
Q(l+1)=1;
end
if imdct(width,height+1)-imdct(width+8,height+1)<0
Q(l+2)=0;
else
Q(l+2)=1;
end
if imdct(width,height+2)-imdct(width+8,height+2)<0
Q(l+3)=0;
else
Q(l+3)=1;
end
if imdct(width+1,height+1)-imdct(width+9,height+1)<0
Q(l+4)=0;
else
Q(l+4)=1;
end
if imdct(width+2,height)-imdct(width+10,height)<0
Q(l+5)=0;
else
Q(l+5)=1;
end
k=k+1;
end
end
% imwrite(uint8(J2),'lena256.jpg','quality',quality);
% yy=imread('lena256.jpg');
em_cof=[1 4;2 3;3 2;4 1;4 2;3 3];
NN=size(em_cof,1);
k=1;
for i=1:(m/8/2)
for j=1:(n/8)
width=(i-1)*16;
height=(j-1)*8;
l=(k-1)*6+1;
for kk=1:3
qstep=Q_table(em_cof(kk,1),em_cof(kk,2));
orcof=imdct(width+em_cof(kk,1),height+em_cof(kk,2));
watermark(l)=mod(round(imdct(width+em_cof(kk,1),height+em_cof(kk,2))/qstep),2);
if watermarked(l)~=Q(l)
end
l=l+1;
end
width=(i-1)*16;
height=(j-1)*8+8;
for kk=4:NN
qstep=Q_table(em_cof(kk,1),em_cof(kk,2));
orcof=imdct(width+em_cof(kk,1),height+em_cof(kk,2));
imdct(width+em_cof(kk,1),height+em_cof(kk,2))=round(orcof/qstep)*qstep;
if mod(round(imdct(width+em_cof(kk,1),height+em_cof(kk,2))/qstep),2)~=Q(l)
err=err+1;
if orcof>imdct(width+em_cof(kk,1),height+em_cof(kk,2))
imdct(width+em_cof(kk,1),height+em_cof(kk,2))=imdct(width+em_cof(kk,1),height+em_cof(kk,2))-qstep;
else
imdct(width+em_cof(kk,1),height+em_cof(kk,2))=imdct(width+em_cof(kk,1),height+em_cof(kk,2))+qstep;
end
end
l=l+1;
end
k=k+1;
end
end
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -