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

图形图象

开发平台:

Matlab

  1. %Name: Chris Shoemaker
  2. %Course: EER-280 - Digital Watermarking
  3. %Project:  Block DCT Based method, using comparision between mid-band coeffcients
  4. %           Watermark Recovery
  5. clear all;
  6. % save start time
  7. start_time=cputime;
  8. blocksize=8;    % set the size of the block in cover to be used for each bit in watermark
  9. % read in the watermarked object
  10. file_name='dct1_watermarked.bmp';
  11. watermarked_image=double(imread(file_name));
  12. % determine size of watermarked image
  13. Mw=size(watermarked_image,1);         %Height
  14. Nw=size(watermarked_image,2);         %Width
  15. % determine maximum message size based on cover object, and blocksize
  16. max_message=Mw*Nw/(blocksize^2);
  17. % read in original watermark
  18. file_name='_copyright.bmp';
  19. orig_watermark=double(imread(file_name));
  20. % determine size of original watermark
  21. Mo=size(orig_watermark,1); %Height
  22. No=size(orig_watermark,2); %Width
  23. % process the image in blocks
  24. x=1;
  25. y=1;
  26. for (kk = 1:max_message)
  27.     % transform block using DCT
  28.     dct_block=dct2(watermarked_image(y:y+blocksize-1,x:x+blocksize-1));
  29.     
  30.     % if dct_block(5,2) > dct_block(4,3) then message(kk)=0
  31.     % otherwise message(kk)=1
  32.     if dct_block(5,2) > dct_block(4,3)
  33.         message_vector(kk)=0;
  34.     else
  35.         message_vector(kk)=1;
  36.     end
  37.  
  38.     % move on to next block. At and of row move to next row
  39.     if (x+blocksize) >= Nw
  40.         x=1;
  41.         y=y+blocksize;
  42.     else
  43.         x=x+blocksize;
  44.     end
  45. end
  46. % reshape the embeded message
  47. message=reshape(message_vector(1:2000),40,50);
  48. % display processing time
  49. elapsed_time=cputime-start_time,
  50. % display recovered message
  51. figure(2)
  52. imshow(message,[])
  53. title('Recovered Message')