📄 dct_detb.m
字号:
function QQ=dct_det(attacked,tao)
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);
chuangai=attacked;
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/2*6);
watermark=zeros(1,m*n/8/8*6);
%比较zig-zag前6个对应系数
wm_cof=[1 1;2 1;1 2;1 3;2 2;3 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 ppp=1:6
% if round((imdct(width+wm_cof(ppp,1),height+wm_cof(ppp,2))-imdct(width+wm_cof(ppp,1)+8,height+wm_cof(ppp,2)))/(Q_table(wm_cof(ppp,1),wm_cof(ppp,2))+1))<tao
% if round((imdct(width+wm_cof(ppp,1),height+wm_cof(ppp,2))-imdct(width+wm_cof(ppp,1)+8,height+wm_cof(ppp,2)))/(Q_table(wm_cof(ppp,1),wm_cof(ppp,2))))<tao
if round(imdct(width+wm_cof(ppp,1),height+wm_cof(ppp,2)))-round(imdct(width+wm_cof(ppp,1)+8,height+wm_cof(ppp,2)))<tao
Q(l+ppp)=0;
else
Q(l+ppp)=1;
end
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];
%em_cof=[4 4;4 5;5 4;2 6;6 2;3 5];
NN=size(em_cof,1);
k=1;
err=0;
for i=1:(m/8/2)
for j=1:(n/8)
width=(i-1)*16;
height=(j-1)*8;
l=(k-1)*6+1;
err_block=0;
for kk=1:3
qstep=Q_table(em_cof(kk,1),em_cof(kk,2))+1;
watermark(l)=mod(round(imdct(width+em_cof(kk,1),height+em_cof(kk,2))/qstep),2);
if watermark(l)~=Q(l)
err_block=err_block+1;
% chuangai((width+1):(width+16),(height+1):(height+8))=1;
end
l=l+1;
end
width=(i-1)*16+8;
height=(j-1)*8;
for kk=4:NN
qstep=Q_table(em_cof(kk,1),em_cof(kk,2))+1;
watermark(l)=mod(round(imdct(width+em_cof(kk,1),height+em_cof(kk,2))/qstep),2);
if watermark(l)~=Q(l)
err_block=err_block+1;
% chuangai((width+1):(width+16),(height+1):(height+8))=1;
end
l=l+1;
end
if err_block>1
err=err+1;
chuangai((width-7):(width+8),(height+1):(height+8))=0;
end
k=k+1;
end
end
figure(2);
imshow(uint8(chuangai));
imwrite(uint8(chuangai),'cuangai.bmp','bmp');
QQ=Q;
err
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -