lsb嵌入水印代码

本文介绍了一种使用最小有效位(LSB)替换的方法来实现数字水印的嵌入过程。通过将消息图像嵌入到载体图像的最低位中,实现了版权保护或认证的目的。文中详细展示了MATLAB代码实现流程。



%Name:        Chris Shoemaker
%Course:    EER-280 - Digital Watermarking
%Project:     Least Significant Bit Substitution
%           Watermark Embeding

clear all;

% save start time
start_time
=cputime;

% read in the cover object
file_name
='_lena_std_bw.bmp';
[cover_object,map]
=imread(file_name);

% read in the message image
file_name
='key.bmp';
[message,map1]
=imread(file_name);
message1
=message;

% convert to double for normalization, then back again
message
=double(message);
message
=fix(message./2);
message
=uint8(message);

% determine size of cover object
Mc
=size(cover_object,1);    %Height
Nc
=size(cover_object,2);    %Width

% determine size of message object
Mm
=size(message,1);            %Height
Nm
=size(message,2);            %Width

% title the message object out to cover object size to generate watermark
for ii = 1:Mc
    
for jj = 1:Nc
        watermark(ii,jj)
=message(mod(ii,Mm)+1,mod(jj,Nm)+1);
    end
end

% now we set the lsb of cover_object(ii,jj) to the value of watermark(ii,jj)
watermarked_image
=cover_object;
for ii = 1:Mc
    
for jj = 1:Nc
        watermarked_image(ii,jj)
=bitset(watermarked_image(ii,jj),1,watermark(ii,jj));
    end
end

% write the watermarked image out to a file
imwrite(watermarked_image,
'lsb_watermarked.bmp','bmp');

% display processing time
elapsed_time
=cputime-start_time,

% calculate the PSNR
psnr
=psnr(cover_object,watermarked_image,Mc,Nc),

% display watermarked image
figure(
1)
imshow(watermarked_image,[])
title(
'Watermarked Image')
figure(
2)
imshow(cover_object,[])
title(
'original  image')
for ii = 1:Mc
    
for jj = 1:Nc
        watermark1(ii,jj)
=message1(mod(ii,Mm)+1,mod(jj,Nm)+1);
    end
end
%watermark1=watermark1*256;
%message1=message1*256;
figure(
3)
imshow(watermark1,[])
title(
'the watermark')
figure(
4)
imshow(message1,[])
title(
'the watermark')
 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

superdont

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值