%------------------------NOTES---------------------------------------------
% Written by : zj - 01/05/07
% Contact : zxxyj0506@sina.com
% CpoyRight@2007-2010
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% p --- the image which want to be embed watermark
% w --- the binary watermark image
% g --- the watermarked image
% delta --- the coefficient (量化系数)
p=imread('baboon512.jpg'); w=imread('shan.png'); delta=75;
[wrow,wcol]=size(w);
[pll,plh,phl,phh]=dwt2(p,'db1');
[row,col]=size(pll);
numblk=row/8;
pll_w=wembed(pll,w,delta,numblk);
pw=idwt2(pll_w,plh,phl,phh,'db1');
g=uint8(pw);
% g=imnoise(g,'gaussian',0,0.005);
% g=imnoise(g,'salt & pepper',0.02);
% g=imnoise(g,'speckle',0.02);
psnr_im=psnr(p,g);
[gll,glh,ghl,ghh]=dwt2(g,'db1');
abw=wabsract(gll,delta);
nc=matrix_nc(w,abw);
subplot(1,4,1);imshow(p);subplot(1,4,2);imshow(w);
subplot(1,4,3);imshow(g);subplot(1,4,4);imshow(abw);