cdma_embed.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 Embeding
  5. clear all;
  6. % save start time
  7. start_time=cputime;
  8. k=12;                % set the gain factor for embeding
  9. % read in the cover object
  10. file_name='test.jpg' %'_lena_std_bw.bmp';
  11. cover_object=double(imread(file_name));
  12. figure(1)
  13. imshow(cover_object,[]);
  14. % determine size of watermarked image
  15. Mc=size(cover_object,1); %Height
  16. Nc=size(cover_object,2); %Width
  17. % read in the message image and reshape it into a vector
  18. file_name='_copyright_small.bmp';
  19. message=double(imread(file_name));
  20. Mm=size(message,1);                         %Height
  21. Nm=size(message,2);                         %Width
  22. message_vector=fix(reshape(message,Mm*Nm,1)./2);
  23. % read in key for PN generator
  24. %%file_name='_key.bmp';
  25. %%key=double(imread(file_name))./256;
  26. % reset MATLAB's PN generator to state "key"
  27. rand('state',1);
  28. %rand('state',key);
  29. watermarked_image=cover_object;
  30. % when message contains a '0', add pn sequence with gain k to cover image
  31. pn_sequence=round(2*(rand(Mc,Nc)-0.5));
  32. psnr1=psnr(cover_object,pn_sequence,Mc,Nc),
  33. %for kk=1:length(message_vector)
  34.     
  35.     
  36.     %if message(kk) == 0
  37.  %   if message(kk) == 1
  38.         
  39.   %  end
  40. %end
  41. watermarked_image=watermarked_image+k*pn_sequence;
  42. % convert back to uint8
  43. watermarked_image_uint8=uint8(watermarked_image);
  44. % write watermarked Image to file
  45. imwrite(watermarked_image_uint8,'cdma_watermarked.bmp','bmp');
  46. % display processing time
  47. elapsed_time=cputime-start_time,
  48. % calculate the PSNR
  49. psnr=psnr(cover_object,watermarked_image_uint8,Mc,Nc),
  50. % display watermarked Image
  51. figure(2)
  52. imshow(watermarked_image_uint8,[])
  53. figure(3)
  54. imshow(pn_sequence,[])
  55. title('Watermarked Image')