D=imread('new.bmp');
I=D;
%原始带水印图像
figure(1);
subplot(3,2,1);imshow(D,[]);title('原始带水印图像');
%高斯噪声
D1=imnoise(D,'gaussian',0,0.001);
figure(1);
subplot(3,2,3);imshow(D1,[]);title('加入高斯噪声图像');
%椒盐噪声
D2=imnoise(D,'salt',0.02);
figure(1);
subplot(3,2,5);imshow(D2,[]);title('加入椒盐噪声图像');
%JPEG压缩攻击
imwrite(D,'attack.jpg','jpeg','Quality',15); %压缩比默认75
H=imread('attack.jpg','jpeg');
figure(1);
subplot(3,2,4);imshow(H,[]);title('压缩攻击图像');
%旋转攻击 只能旋转1度
%R=imrotate(D,10,'bilinear','crop');
R=imrotate(D,3,'bilinear','crop'); %‘bilinear’:双线性插值(Bilinear interpolation) ,crop保持与原图片大小一致
figure(1);
subplot(3,2,6);imshow(R,[]);title('旋转攻击图像');
%剪切攻击:
D(1:256,1:128)=0;
Q2=D;
figure(1);
subplot(3,2,2);imshow(Q2,[]);title('剪切攻击图像');
%------------------------水印提取---------------%
%未受攻击提取的水印
R1=imread('gmark2.bmp');
R1=im2bw(R1);
pic11=bitxor(R1,Fuck2);
figure(2);
subplot(3,2,1);
imshow(pic11);
title('从含水印图像中提取的水印');
%高斯噪声
w3=tiqu(D1);
gran3= Arnold2(w3);
%gran11=im2uint8(gran1);
gran3=im2bw(gran3);
pic3=bitxor(gran3,Fuck2);
figure(2);
subplot(3,2,3);
imshow(pic3);
title('经过高斯噪声攻击水印图像中提取的水印');
%椒盐噪声
w5=tiqu(D2);
gran5= Arnold2(w5);
gran5=im2bw(gran5);
pic5=bitxor(gran5,Fuck2);
figure(2);
subplot(3,2,5);
imshow(pic5);
title('经过椒盐噪声攻击水印图像中提取的水印');
%压缩攻击提取水印
w4=tiqu(H);
gran4=Arnold2(w4);
gran4=im2bw(gran4);
pic4=bitxor(gran4,Fuck2);
figure(2);
subplot(3,2,4);
imshow(pic4);
title('经过压缩攻击水印图像中提取的水印');
%剪切攻击提取水印
w2=tiqu(Q2);
gran2=Arnold2(w2);
gran2=im2bw(gran2);
pic2=bitxor(gran2,Fuck2);
figure(2);
subplot(3,2,2);
imshow(pic2);
title('经过剪切攻击水印图像中提取的水印');
%旋转攻击
w6=tiqu(R);
gran6=Arnold2(w6);
gran6=im2bw(gran6);
pic6=bitxor(gran6,Fuck2);
figure(2);
subplot(3,2,6);
imshow(pic6);
title('经过旋转攻击水印图像中提取的水印');
%------------------相关性分析-----------------%
NC=correlation(W,w2);
disp('原水印与剪切攻击后水印的相关性');
disp(NC);
NC1=correlation(W,w3);
disp('原水印与高斯噪声攻击后水印的相关性');
disp(NC1);
NC5=correlation(W,w5);
disp('原水印与椒盐噪声攻击后水印的相关性');
disp(NC5);
NC4=correlation(W,w4);
disp('原水印与压缩攻击后水印的相关性');
disp(NC4);
NC6=correlation(W,w6);
disp('原水印与旋转攻击后水印的相关性');
disp(NC6);