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

图形图象

开发平台:

Matlab

  1. %Name: Chris Shoemaker
  2. %Course: EER-280 - Digital Watermarking
  3. %Project:  Least Significant Bit Substitution
  4. %           Watermark Embeding
  5. clear all;
  6. % save start time
  7. start_time=cputime;
  8. % read in the cover object
  9. file_name='_lena_std_bw.bmp';
  10. [cover_object,map]=imread(file_name);
  11. % read in the message image
  12. file_name='key.bmp';
  13. [message,map1]=imread(file_name);
  14. message1=message;
  15. % convert to double for normalization, then back again
  16. message=double(message);
  17. message=fix(message./2);
  18. message=uint8(message);
  19. % determine size of cover object
  20. Mc=size(cover_object,1); %Height
  21. Nc=size(cover_object,2); %Width
  22. % determine size of message object
  23. Mm=size(message,1);         %Height
  24. Nm=size(message,2);         %Width
  25. % title the message object out to cover object size to generate watermark
  26. for ii = 1:Mc
  27.     for jj = 1:Nc
  28.         watermark(ii,jj)=message(mod(ii,Mm)+1,mod(jj,Nm)+1);
  29.     end
  30. end
  31. % now we set the lsb of cover_object(ii,jj) to the value of watermark(ii,jj)
  32. watermarked_image=cover_object;
  33. for ii = 1:Mc
  34.     for jj = 1:Nc
  35.         watermarked_image(ii,jj)=bitset(watermarked_image(ii,jj),1,watermark(ii,jj));
  36.     end
  37. end
  38. % write the watermarked image out to a file
  39. imwrite(watermarked_image,'lsb_watermarked.bmp','bmp');
  40. % display processing time
  41. elapsed_time=cputime-start_time,
  42. % calculate the PSNR
  43. psnr=psnr(cover_object,watermarked_image,Mc,Nc),
  44. % display watermarked image
  45. figure(1)
  46. imshow(watermarked_image,[])
  47. title('Watermarked Image')
  48. figure(2)
  49. imshow(cover_object,[])
  50. title('original  image')
  51. for ii = 1:Mc
  52.     for jj = 1:Nc
  53.         watermark1(ii,jj)=message1(mod(ii,Mm)+1,mod(jj,Nm)+1);
  54.     end
  55. end
  56. %watermark1=watermark1*256;
  57. %message1=message1*256;
  58. figure(3)
  59. imshow(watermark1,[])
  60. title('the watermark')
  61. figure(4)
  62. imshow(message1,[])
  63. title('the watermark')