1 引 言

2 小波变换与奇异值分解

2 水印算法

2.2 水印提取算法

## 二、部分源代码

close all;

clc;

%加载要加水印的原始图像

orig_img = imresize(orig_img, [256,256]);

figure, imshow(orig_img); title (‘原始图片’)

[M,N] = size(orig_img);

nblock=M/8;

%加载要在原始图像中加水印的图像

wat_img = imresize(wat_img, [nblock,nblock]); % make it 32 X 32

wat_img=uint8(wat_img);

level = graythresh(wat_img);%找到一个很好的阈值

wat_img = im2bw(wat_img,level); %使水印变成二值图像

figure, imshow(wat_img); title(‘WaterMark Image’);

%现在调用遗传算法，最小值为10，最大值为20

% 值90与线性适应度函数

npop = input(‘No of Iteration (Population Size) = ‘); % 询问人口规模

% 最小值为10，最大值为90，是种群数目大小，适应函数是未知数的平方

[a,b,c] = genetic_algorithm (@(x)x^2,npop,npop,npop,npop,npop,npop,npop,1,150,250,.01);

% 攻击类型

fprintf(’ 1 – Midian Filter
’);

fprintf(’ 2 – Resize the image (scaling four times and then returned to original with bicubicinterpolation)
’);

fprintf(’ 2 – Salt and paper noise
’);

fprintf(’ 4 – Low pass filter
’);

fprintf(’ 5 – Image Jpeg Compression with Quality Factor 40
’);

attack_type = input(‘Attack Type: ‘);

max = 0.0; % 目标函数的最大值

peaksnr_value = 0; % 初始化 PEAKSNR 值

NC = 0; % 初始化归一化相关值

step=0;

final_image = zeros(M,N);

for i=2:npop

step_size = a(i);

Wimg = SVD_Watermarked(orig_img, wat_img, step_size);

% calculation of image quality degradiation after inserting watermark嵌入水印后图像质量退化的计算

[m,n] = size(orig_img);

error = orig_img – Wimg;

MSE = (sum(sum(error.^2)))/(m

n);

if (MSE > 0)

log10(255^2/MSE);

else

peaksnr=99;

end

% fprintf(‘The Peak Signal to noise ratio: %f db
’,peaksnr);

% 攻击水印图片

% 应用中值过滤器

if(attack_type

1)

attacked_Image = medfilt2(Wimg);

end

% 调整图像大小。 第一次缩放（四次）然后回到原来的

% 双三次插值

2)

attacked_Image = imresize(Wimg,4,‘nearest’);

attacked_Image = imresize(attacked_Image, [M N]);

end

%椒盐噪声

if(attack_type

3)

attacked_Image = imnoise(Wimg,‘salt & pepper’,0.002);

end

4)

attacked_Image = uint8(conv2(double(Wimg), double(ones(3,3))/9));

attacked_Image = imresize(attacked_Image, [M N]);

end

if(attack_type == 5)

imwrite(Wimg,‘Watermarked’,‘JPEG’,‘Quality’,40);

end

## 四、matlab版本及参考文献

1 matlab版本

2014a

2 参考文献

[1]王选宏,肖云.基于奇异值分解的小波域水印算法[J].现代电子技术. 2010,33(05)

3 备注