- 课题介绍
本课题为基于MATLAB的小波变换dwt和离散余弦dct的多方法对比数字水印系统。带GUI交互界面。有一个主界面GUI,可以调用dwt方法的子界面和dct方法的子界面。流程包括,读取宿主图像和水印图像,嵌入,多种方法的攻击(剪切,加噪,旋转等),提取,最后利用psnr峰值信噪比进行评价不同攻击下,鲁棒性的好坏。
- GUI界面
- 源码
- 读取宿主图像
[name,path]=uigetfile({'*.bmp';'gif'},'载入图像');
X=imread([path,name]); %获取位置
axes(handles.axes1);%axes表示获取位置,这里选取的位置为axes1;
imshow(X); %显示图像
save('X'); %保存变量
guidata(hObject,handles) %更新结构体;
- 读取水印图像
[name,path]=uigetfile({'*.bmp';'gif'},'载入图像');
W=imread([path,name]); %获取位置
axes(handles.axes2);%axes表示获取位置,这里选取的位置为axes1;
W=rgb2gray(W)
W=imresize(W,[64 64])
imshow(W); %显示图像
save('W'); %保存变量
guidata(hObject,handles) %更新结构体;
- 嵌入
for i = 1:64
ref1(i)=mean(lowarray(:,i)); %对矩阵每列求均值
ref2(i)=mean(lowarray(i,:)); %对矩阵每行求均值
for j=1:64
w(i,j,:)=int8(dec2bin(W(i,j),8))-48; %dec2bin将矩阵W的每个元素转换成二进制值,每个二进制长度为8
result(i,j,1)=xor(w(i,j,1),(lowarray(i,j)>ref1(i)));
result(i,j,2)=xor(w(i,j,2),(lowarray(i,j)>ref2(i)));
end
end
for i=1:4096
ref3tmp=[XCsource(16381+4*i:16384+4*i)];%128*128=16384
ref3(i)=mean(ref3tmp);
ref4tmp=[XCsource(32765+4*i:32768+4*i)];%128*256=32768
ref4(i)=mean(ref3tmp);
ref5tmp=[XCsource(49149+4*i:49152+4*i)];%(128+64)*256=49152 or (128+256)*128=49152
ref5(i)=mean(ref5tmp);
ref6(i)=mean(ref6tmp);
ref7tmp=[XCsource(131057+16*i:131072+16*i)];%256*512=131072
ref7(i)=mean(ref7tmp);
ref8tmp=[XCsource(196593+16*i:196608+16*i)];%(128+256)*512=196608
ref8(i)=mean(ref8tmp);
end
- 攻击
if get(handles.radiobutton1,'value')
option=1;
q=num2str(get(handles.edit3,'string'))
Z = imrotate(Z,q,'crop');%旋转 角度可以控制
elseif get(handles.radiobutton2,'value')
option=2;
q1=str2num(get(handles.edit4,'string'))
q2=str2num(get(handles.edit6,'string'))
q3=str2num(get(handles.edit7,'string'))
q4=str2num(get(handles.edit8,'string'))
Z(q1:q2,q3:q4)=255;%剪切 区间和嵌入值可以控制
elseif get(handles.radiobutton3,'value')
option=3;
q=str2num(get(handles.edit5,'string'))
Z=imnoise(Z,'gaussian',q);%加噪声 选择参数 help imnoise
elseif get(handles.radiobutton4,'value')
option=4;
Z=Z
end
axes(handles.axes4)
imshow(Z,[]);
- 提取
for i =1:64
for j=1:64
pick(i,j,3)=xor(std(i,j,3),(lowarray(i,j)>(alaph3*reref3(i,j))));
pick(i,j,4)=xor(std(i,j,4),(lowarray(i,j)>(alaph4*reref4(i,j))));
pick(i,j,5)=xor(std(i,j,5),(lowarray(i,j)>(alaph5*reref5(i,j))));
pick(i,j,6)=xor(std(i,j,6),(lowarray(i,j)>(alaph6*reref6(i,j))));
pick(i,j,7)=xor(std(i,j,7),(lowarray(i,j)>(alaph7*reref7(i,j))));
pick(i,j,8)=xor(std(i,j,8),(lowarray(i,j)>(alaph8*reref8(i,j))));
end
end
for i=1:64
for j=1:64
od=double(reshape(pick(i,j,:),1,8));
dec(i,j)=bin2dec(char(od+48));
end
end
- psnr计算
origImg = double(origImg);
distImg = double(distImg);
[M N] = size(origImg);
error = origImg - distImg;
MSE = sum(sum(error .* error)) / (M * N);
if(MSE > 0)
PSNR = 10*log(255*255/MSE) / log(10);
else
PSNR = 99;
end
标签:end,get,lowarray,系统,handles,64,MATLAB,数字水印,mean From: https://blog.csdn.net/2401_86539719/article/details/142667818