数字水印技术LSB算法MATLAB源代码
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
close all
clear all;
% save start time
start_time=cputime;
% read in the cover object
file_name='E:\Phd\My Paper\Second paper -- Experiment\Experiment\Cover and Secret Image\lena.bmp';
[cover_object,map]=imread(file_name);
% read in the secret image
file_name='E:\Phd\My Paper\Second paper -- Experiment\Experiment\Cover and Secret Image\hat.bmp';
[secret,map1]=imread(file_name);
secret1=secret;
% convert to double for normalization, then back again
secret=double(secret);
secret=fix(secret./2); %rounds the elements of A toward zero, resulting in an array of integers secret=uint8(secret);
% determine size of cover object
Mc=size(cover_object,1); %Height
Nc=size(cover_object,2); %Width
% determine size of secret object
Mm=size(secret,1); %Height
Nm=size(secret,2); %Width
% title the secret object out to cover object size to generate watermark
for ii = 1:Mc
for jj = 1:Nc
if (secret(ii,jj)>75)
watermark(ii,jj)=255;
else
watermark(ii,jj)=0;
end
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
if (watermark(ii,jj)==0)
watermarked_image(ii,jj)=bitset(watermarked_image(ii,jj),1,0); %Set bit at certain position
else
watermarked_image(ii,jj)=bitset(watermarked_image(ii,jj),1,1); %Set bit at certain position
end
end
end
% write the watermarked image out to a file
imwrite(watermarked_image,'lsb_watermarked.bmp','bmp');
%==================================Extraction=========================== ========================
% determine size of watermarked image
Mw=size(watermarked_image,1); %Height
Nw=size(watermarked_image,2); %Width
% use lsb of watermarked image to recover watermark
for ii = 1:Mw
for jj = 1:Nw
RecoveryWatermark(ii,jj)=bitget(watermarked_image(ii,jj),1);
end
end
% scale the recovered watermark
RecoveryWatermark=2*double(RecoveryWatermark);
%==================================================================== ===============================
%===========================SharpAttack================= SharpedWatermarkImage = watermarked_image;
H = fspecial('unsharp',0.001); %the alpha from 0.005 to 0.1 20 numbers sharpImage = imfilter(SharpedWatermarkImage,H,'replicate');
figure(6);
colormap(gray(256));
imshow(sharpImage);
title('sharp Image');