dwt_embed.m
上传用户:haoweisi88
上传日期:2010-02-03
资源大小:1950k
文件大小:2k
源码类别:

图形图象

开发平台:

Matlab

  1. %Name: Chris Shoemaker
  2. %Course: EER-280 - Digital Watermarking
  3. %Project:  Embeding of CDMA watermark into H1,V1,D1 componants of a 1-scale DWT
  4. %           Watermark Embeding
  5. clear all;
  6. % save start time
  7. start_time=cputime;
  8. k=2;            % set the gain factor for embeding
  9. % read in the cover object
  10. file_name='_lena_std_bw.bmp';
  11. cover_object=double(imread(file_name));
  12. % determine size of watermarked image
  13. Mc=size(cover_object,1); %Height
  14. Nc=size(cover_object,2); %Width
  15. % read in the message image and reshape it into a vector
  16. file_name='_copyright.bmp';
  17. message=double(imread(file_name));
  18. Mm=size(message,1);                         %Height
  19. Nm=size(message,2);                         %Width
  20. message_vector=fix(reshape(message,Mm*Nm,1)./2);
  21. % read in key for PN generator
  22. %file_name='_key.bmp';
  23. %key=double(imread(file_name))./2;%256
  24. % reset MATLAB's PN generator to state "key"
  25. rand('state',16);
  26. %三层harr小波变换
  27. [cA1,cH1,cV1,cD1] = dwt2(cover_object,'haar');
  28. [cA2,cH2,cV2,cD2] = dwt2(cA1,'haar');
  29. [cA3,cH3,cV3,cD3] = dwt2(cA2,'haar');
  30. [r1,c1] = size(cA3);
  31. pn_sequence_h1=round(2*(rand(r1,c1)-0.5));
  32. cA3=cA3+20*pn_sequence_h1;
  33. % add pn sequences to H1 and V1 componants when message = 0 
  34.  pn_sequence_h=round(2*(rand(Mc/2,Nc/2)-0.5));
  35.  pn_sequence_v=round(2*(rand(Mc/2,Nc/2)-0.5));
  36. for (kk=1:length(message_vector))  
  37.     
  38.     if (message(kk) == 0)
  39.         cH1=cH1+k*pn_sequence_h;
  40.         cV1=cV1+k*pn_sequence_v;
  41.     end
  42. end
  43. % perform IDWT
  44. cA2 = idwt2(cA3,cH3,cV3,cD3,'haar',[Mc/4,Nc/4]);
  45. cA1 = idwt2(cA2,cH2,cV2,cD2,'haar',[Mc/2,Nc/2]);
  46. watermarked_image = idwt2(cA1,cH1,cV1,cD1,'haar',[Mc,Nc]); 
  47. % convert back to uint8
  48. watermarked_image_uint8=uint8(watermarked_image);
  49. % write watermarked Image to file
  50. imwrite(watermarked_image_uint8,'dwt_watermarked.bmp','bmp');
  51. % display processing time
  52. elapsed_time=cputime-start_time,
  53. % calculate the PSNR
  54. psnr=psnr(cover_object,watermarked_image_uint8,Mc,Nc),
  55. % display watermarked image
  56. figure(1)
  57. imshow(watermarked_image_uint8,[])
  58. title('Watermarked Image')
  59. figure(2)
  60. subplot(2,2,1);
  61. imshow(cA1,[]);
  62. subplot(2,2,2);imshow(cA2,[]);
  63. subplot(2,2,3);imshow(cA3,[]);
  64. subplot(2,2,4);imshow(cD1,[]);
  65. figure(3)
  66. imshow(cA3,[]);