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

图形图象

开发平台:

Matlab

  1. %Name: Chris Shoemaker
  2. %Course: EER-280 - Digital Watermarking
  3. %Project:  Comparison-Based Correlation using block processing in the spatial domain
  4. %           Uses two PN sequences; one for a "0" and another for a "1"
  5. %           Watermark Recovery
  6. clear all;
  7. % save start time
  8. start_time=cputime;
  9. blocksize=16;      % set the size of the block in cover to be used for each bit in watermark
  10. % read in the watermarked object
  11. file_name='cor_watermarked_mod.bmp';
  12. watermarked_image=double(imread(file_name));
  13. % determine size of watermarked image
  14. Mw=size(watermarked_image,1); %Height
  15. Nw=size(watermarked_image,2); %Width
  16. % determine maximum possible message size in object
  17. max_message=Mw*Nw/(blocksize^2);
  18. % read in original watermark
  19. file_name='_copyright.bmp';
  20. orig_watermark=double(imread(file_name));
  21. % determine size of original watermark
  22. Mo=size(orig_watermark,1); %Height
  23. No=size(orig_watermark,2); %Width
  24. % read in key for PN generator
  25. file_name='_key.bmp';
  26. key=double(imread(file_name))./256;
  27. % reset MATLAB's PN generator to state "key"
  28. rand('state',key);
  29. % generate PN sequences to designate "1" and "0"
  30. watermark_one=round(2*(rand(blocksize,blocksize)-0.5));
  31. watermark_zero=round(2*(rand(blocksize,blocksize)-0.5));
  32. % find two highly un-correlated PN sequences
  33. while (corr2(watermark_one,watermark_zero) > -0.1)
  34.     watermark_one=round(2*(rand(blocksize,blocksize)-0.5));
  35.     watermark_zero=round(2*(rand(blocksize,blocksize)-0.5));
  36. end
  37. % pad message out to maximum message size with ones
  38. message_vector=ones(max_message,1);
  39. % process the image in blocks
  40. % for each block determine it's correlation with base pn sequence
  41. x=1;
  42. y=1;
  43. for (kk = 1:length(message_vector))
  44.     % calculate correlations for both PN sequences
  45.     correlation_one(kk)=corr2(watermarked_image(y:y+blocksize-1,x:x+blocksize-1),watermark_one);
  46.     correlation_zero(kk)=corr2(watermarked_image(y:y+blocksize-1,x:x+blocksize-1),watermark_zero);
  47.     
  48.     % choose which ever correlation is higher
  49.     if correlation_one(kk) > correlation_zero(kk)
  50.         message_vector(kk)=1;
  51.     else
  52.         message_vector(kk)=0;
  53.     end
  54.     
  55.     % move on to next block. At and of row move to next row
  56.     if (x+blocksize) >= Nw
  57.         x=1;
  58.         y=y+blocksize;
  59.     else
  60.         x=x+blocksize;
  61.     end
  62. end
  63. % reshape the message
  64. message=reshape(message_vector(1:Mo*No),Mo,No);
  65. % display processing time
  66. elapsed_time=cputime-start_time,
  67. % display the recovered message
  68. figure(2)
  69. imshow(message,[])
  70. title('Recovered Message')