dwt_recover.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 Recovery
  5. clear all;
  6. % save start time
  7. start_time=cputime;
  8. % read in the watermarked object
  9. file_name='dwt_watermarked.bmp';
  10. watermarked_image=double(imread(file_name));
  11. % determine size of watermarked image
  12. Mw=size(watermarked_image,1);         %Height
  13. Nw=size(watermarked_image,2);         %Width
  14. % read in original watermark
  15. file_name='_copyright.bmp';
  16. orig_watermark=double(imread(file_name));
  17. % determine size of original watermark
  18. Mo=size(orig_watermark,1); %Height
  19. No=size(orig_watermark,2); %Width
  20. % read in key for PN generator
  21. %file_name='_key.bmp';
  22. %key=double(imread(file_name))./256;
  23. % reset MATLAB's PN generator to state "key"
  24. rand('state',16);
  25. % initalize message to all ones
  26. message_vector=ones(1,Mo*No);
  27. [cA1,cH1,cV1,cD1] = dwt2(watermarked_image,'haar');
  28. % add pn sequences to H1 and V1 componants when message = 0 
  29.   pn_sequence_h=round(2*(rand(Mw/2,Nw/2)-0.5));
  30.   pn_sequence_v=round(2*(rand(Mw/2,Nw/2)-0.5));
  31.     
  32.  
  33. for (kk=1:length(message_vector))
  34.     correlation_h(kk)=corr2(cH1,pn_sequence_h);
  35.     correlation_v(kk)=corr2(cV1,pn_sequence_v);
  36.     correlation(kk)=(correlation_h(kk)+correlation_v(kk))/2;
  37.   
  38. end
  39. for (kk=1:length(message_vector))
  40.     if (correlation(kk) > mean(correlation))
  41.         message_vector(kk)=0;
  42.     end
  43. end
  44. % reshape the message vector and display recovered watermark.
  45. figure(2)
  46. message=reshape(message_vector,Mo,No);
  47. imshow(message,[])
  48. title('Recovered Watermark')
  49. % display processing time
  50. elapsed_time=cputime-start_time,