dct2_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 in DCT mid-band
  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=8;                    % set the dct blocksize
  10. pn_sequence_search='T';         % perform search to find highly uncorrelated pn sequences {T,F}
  11. midband=[   0,0,0,1,1,1,1,0;    % defines the mid-band frequencies of an 8x8 dct
  12.             0,0,1,1,1,1,0,0;
  13.             0,1,1,1,1,0,0,0;
  14.             1,1,1,1,0,0,0,0;
  15.             1,1,1,0,0,0,0,0;
  16.             1,1,0,0,0,0,0,0;
  17.             1,0,0,0,0,0,0,0;
  18.             0,0,0,0,0,0,0,0 ];
  19.         
  20. % read in the watermarked object
  21. file_name='dct2_watermarked_mod.bmp';
  22. watermarked_image=double(imread(file_name));
  23. % determine size of watermarked image
  24. Mw=size(watermarked_image,1);         %Height
  25. Nw=size(watermarked_image,2);         %Width
  26. % determine maximum message size based on cover object, and blocksize
  27. max_message=Mw*Nw/(blocksize^2);
  28. % read in original watermark
  29. file_name='_copyright.bmp';
  30. orig_watermark=double(imread(file_name));
  31. % determine size of original watermark
  32. Mo=size(orig_watermark,1); %Height
  33. No=size(orig_watermark,2); %Width
  34. % read in key for PN generator
  35. file_name='_key.bmp';
  36. key=double(imread(file_name))./256;
  37. % reset MATLAB's PN generator to state "key"
  38. rand('state',key);
  39. % generate PN sequences for "1" and "0"
  40. pn_sequence_one=round(2*(rand(1,sum(sum(midband)))-0.5));
  41. pn_sequence_zero=round(2*(rand(1,sum(sum(midband)))-0.5));
  42. % find two highly un-correlated PN sequences
  43. if (pn_sequence_search=='T')
  44.     while (corr2(pn_sequence_one,pn_sequence_zero) > -0.55)
  45.         pn_sequence_one=round(2*(rand(1,sum(sum(midband)))-0.5));
  46.         pn_sequence_zero=round(2*(rand(1,sum(sum(midband)))-0.5));
  47.     end
  48. end
  49. % process the image in blocks
  50. x=1;
  51. y=1;
  52. for (kk = 1:max_message)
  53.     % transform block using DCT
  54.     dct_block=dct2(watermarked_image(y:y+blocksize-1,x:x+blocksize-1));
  55.     
  56.     % extract the middle band coeffcients
  57.     ll=1;
  58.     for ii=1:blocksize
  59.         for jj=1:blocksize
  60.             if (midband(jj,ii)==1)
  61.                 sequence(ll)=dct_block(jj,ii);
  62.                 ll=ll+1;
  63.             end
  64.         end
  65.     end
  66.     
  67.     % calculate the correlation of the middle band sequence with pn_sequences
  68.     % and choose the value with the higher correlation for message
  69.     cor_one(kk)=corr2(pn_sequence_one,sequence);
  70.     cor_zero(kk)=corr2(pn_sequence_zero,sequence);
  71.     if cor_zero(kk) > cor_one(kk)
  72.         message_vector(kk)=0;
  73.     else
  74.         message_vector(kk)=1;
  75.     end
  76.     
  77.     
  78.     % move on to next block. At and of row move to next row
  79.     if (x+blocksize) >= Nw
  80.         x=1;
  81.         y=y+blocksize;
  82.     else
  83.         x=x+blocksize;
  84.     end
  85. end
  86. % reshape the embeded message
  87. message=reshape(message_vector(1:Mo*No),Mo,No);
  88. % display processing time
  89. elapsed_time=cputime-start_time,
  90. % display recovered message
  91. figure(2)
  92. imshow(message,[])
  93. title('Recovered Message')