• 大小: 123KB
    文件类型: .rar
    金币: 1
    下载: 0 次
    发布日期: 2021-05-18
  • 语言: Matlab
  • 标签: SNR  PNR  

资源简介

在matlab2011a中编写的程序,根据atpeace童鞋发布资源中doc文档理解修改后得到,包含水印图片和载体图片。有兴趣的可以看看。

资源截图

代码片段和文件信息

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%图像水印的LSB算法子程序
%%************************************************************************
%%将水印图像按质量不重要位(LSB)方法嵌入到载体图像中,再把水印从载体图像中提取
%%出来
%%注:整个算法分水印嵌入部分和水印提取部分。
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%这里算法十分容易理解,嵌入就是将图像最低位替换为水印信息,提取就是从最低位将信
%%息提取出来,使用了bitset(A1v)将A中最低位替换为v中替代信息及bitget(B1)将
%%B中最低位信息提取出来即是水印信息
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
close all;
clear all;
clc;
cd E:\matlab\lsb_algorithm %设置地址

%这里1指代最低位平面(即LSB),若使用8,可以很明显看到水印信息
bit_position=1;
%..................LSB水印嵌入算法...........................
% 读入载体图像
file_name=‘lena_256.bmp‘;
cover_object=rgb2gray(imread(file_name));


% 读入水印图像
file_name=‘test2.bmp‘;
message=rgb2gray(imread(file_name));
message=double(message);
message=message./256;
messagec=uint8(message);
message=messagec;


% 确定载体图像大小
Mc=size(cover_object1);
Nc=size(cover_object2);


% 确定水印图像大小
Mm=size(message1);
Nm=size(message2);

for ii=1:Mc
   for jj=1:Nc
         watermark(iijj)=message(mod(iiMm)+1mod(jjNm)+1);
         %这里将watermark扩大为Mc*Nc大小,有Mc*Nc/(Mm*Nm)块重复
       end
end
watermarked_image=cover_object;%构建一个与原图片相同大小的矩阵用于存储结果
for ii=1:Mc
   for jj=1:Nc
         watermarked_image(iijj)=bitset(watermarked_image(iijj)bit_positionwatermark(iijj));
end
end
imwrite(watermarked_image‘lsb_watermarked.bmp‘‘bmp‘);

% 计算嵌入水印后图像的PSNR
psnr=PSNR(cover_objectwatermarked_image);
% 计算嵌入水印后图像的SNR
snr=SNR(cover_objectwatermarked_image);

% 显示已嵌入水印的图像
figure;
imshow(watermarked_image[]);
title(‘Watermarked Image‘)

%···············LSB水印提取算法················
file_name=‘lsb_watermarked.bmp‘;
watermarked_image=imread(file_name);
Mw=size(watermarked_image1);
Nw=size(watermarked_image2);
for ii=1:Mw
     for jj=1:Nw
             watermark(iijj)=bitget(watermarked_image(iijj)bit_position);
     end
end
watermark=256*double(watermark);

%显示提取的水印图像
figure;
imshow(watermark[])
title(‘Recovered Watermark‘)

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

     文件     196662  2011-08-02 11:11  lsb\lena_256.bmp

     文件       2420  2011-08-02 16:19  lsb\lsb_sub.m

     文件      66614  2011-08-02 15:58  lsb\lsb_watermarked.bmp

     文件       1945  2011-08-02 16:20  lsb\PSNR.m

     文件        104  2011-08-02 16:23  lsb\readme.txt.txt

     文件       1077  2011-08-02 15:40  lsb\SNR.m

     目录          0  2011-08-02 16:20  lsb

----------- ---------  ---------- -----  ----

               268822                    7


评论

共有 条评论