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

图形图象

开发平台:

Matlab

  1. %Name: Chris Shoemaker
  2. %Course: EER-280 - Digital Watermarking
  3. %Project:  CDMA based using multiple PN sequences embeded into whole object
  4. %           Watermark Recovery
  5. clear all;
  6. % save start time
  7. start_time=cputime;
  8. % read in the watermarked object
  9. file_name='cdma_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_small.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. srand('state',key);
  25. % initalize message to all ones
  26. message_vector=ones(1,Mo*No);
  27. for kk=1:length(message_vector)
  28.     % generate {-1,0,1} PN sequence    
  29.     pn_sequence=round(2*(rand(Mw,Nw)-0.5));
  30.     
  31.     % calculate correlation
  32.     if (watermarked_image == pn_sequence)
  33.         correlation=1;
  34.     else
  35.         correlation(kk)=corr2(watermarked_image,pn_sequence);
  36.     end
  37. end
  38.     
  39. % use the average correlation value as threshold
  40. threshold=mean(correlation);
  41. % if correlation exceeds threshold, set message bit low
  42. for kk=1:length(message_vector)
  43.     if correlation(kk) > threshold
  44.         message_vector(kk)=0;
  45.     end
  46. end
  47. % reshape the message vector and display recovered watermark.
  48. figure(2)
  49. message=reshape(message_vector,Mo,No);
  50. imshow(message,[])
  51. title('Recovered Watermark')
  52. % display processing time
  53. elapsed_time=cputime-start_time,