您的位置:首页 > 编程语言 > MATLAB

Image processing of watermark with blind extraction

2014-04-30 10:56 495 查看
Hello, this post is about how to hide watermark in images and extract it without compare with the original images which calls blind extraction.

For many reason,like safety and invisible , I will use DCT  . DCT means discrete cosine transform. Actually , I don't know the principle of the DCT . I just know it can transform the image from time domain to frequency domain. So it's fantastical . Also
you can say mathematics is fantastical.

For use DCT, we must block image into 8*8 blocks.Then use DCT for each blocks. We will get  8*8 matrix. Our watermark is binary image .So 1 means black and 0 means white.Then put this watermark in (1,2) of the matrix. Why use the (1,2) of the matrix? Base
on what I know , I think if use(1,1) the image will change a lot , or use other position like(8,8) the watermark will lost in high probability. Then compare the (1,2)'s value, if the value's second number from pot to left is odd and watermark's value is 1
,don't change it .Else change the number to even by plus 1.Also compare the (1,2)'s value, if the value's second number from pot to left is even and watermark's value is 0 ,don't change it .Else change the number to odd by plus 1. The watermark will be hide
into image by bits.

If you understand how to hide the watermark ,you will also know how to blind extract it . So I will skip it.

That's all .Think for reading.

Matlab code:

BlockSize= 8 ; % 分块系数
a = 10; %嵌入因子

% %%%  读取源图像和水印数据 ,并显示  %%
subplot (1 , 4 , 1) ;
Originalbmp = imread ('lena.bmp','bmp') ;
Tranformbmp = Originalbmp;
imshow(Originalbmp) ;
title( '源图像') ;
subplot(1 ,4 ,2) ;
watermark = imread( 'watermark.bmp','bmp') ;
[weith,heigth] = size(watermark);
imshow(watermark) ;
title('水印信息');

% %%%  嵌入水印信息  %%%
for m=1:weith
for n=1:heigth
x=(m-1)*BlockSize +1;
y=(n-1)*BlockSize + 1;
block = Originalbmp(x:x+BlockSize-1,y:y+BlockSize-1);
block_dct = dct2(block);
block_dct1 = block_dct;
if watermark(m,n) ==0
%a = -1;
if mod(floor(block_dct1(1,2)/a),2) ==1
block_dct1(1,2) = block_dct1(1,2)+a;
end
else  %watermark(m,n) ==1
%a = 1;
if mod(floor(block_dct1(1,2)/a),2) ==0
block_dct1(1,2) = block_dct1(1,2)+a;
end
end
block_idct = idct2(block_dct1);
Tranformbmp(x:x+BlockSize-1,y:y+BlockSize-1) = block_idct;
end
end

% %%%%%%显示嵌入水印后的图像  %%%%%%
D1 = round(Tranformbmp) ;
subplot (1 , 4 , 3) ;
imshow (D1) ;
title(' 嵌入水印后') ;
imwrite(D1 ,'withmark.bmp','bmp') ;

%%%%%%%%%%%%盲提取水印%%%%%%%%%
W = zeros(weith,heigth);
for p = 1 :weith
for q = 1 :heigth
x = (p - 1) *BlockSize+ 1 ;
y = (q - 1) * BlockSize+ 1 ;
block = Withmarkbmp(x :x+ BlockSize-1 ,y :y + BlockSize- 1) ;
block_dct_wm = dct2(block);
if mod(floor(block_dct_wm(1,2)/a),2) ==0
W(p,q) = 0;
else
W(p,q) = 1;
end
end
end
%%%% 显示提取的水印  3 3 3 3 3
subplot (1 ,4 ,4) ;
imshow (W) ;
title ('盲提取的水印');

The result:



内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息