clc;
clear;
close all;
warning off;
addpath(genpath(pwd));
rng('default')
% save start time
start_time=cputime;
k=15; % set gain factor for embeding
blocksize=8; % set the dct blocksize
pn_sequence_search='T'; % perform search to find highly uncorrelated pn sequences {T,F}
midband=[ 0,0,0,1,1,1,1,0; % defines the mid-band frequencies of an 8x8 dct
0,0,1,1,1,1,0,0;
0,1,1,1,1,0,0,0;
1,1,1,1,0,0,0,0;
1,1,1,0,0,0,0,0;
1,1,0,0,0,0,0,0;
1,0,0,0,0,0,0,0;
0,0,0,0,0,0,0,0 ];
% read in the cover object
file_name='_lena_std_bw.bmp';
cover_object=double(imread(file_name));
% determine size of cover image
Mc=size(cover_object,1); %Height
Nc=size(cover_object,2); %Width
% determine maximum message size based on cover object, and blocksize
max_message=Mc*Nc/(blocksize^2);
% read in the message image
file_name='_copyright.bmp';
message=double(imread(file_name));
Mm=size(message,1); %Height
Nm=size(message,2); %Width
% reshape the message to a vector
message=round(reshape(message,Mm*Nm,1)./256);
% check that the message isn't too large for cover
if (length(message) > max_message)
error('Message too large to fit in Cover Object')
end
% pad the message out to the maximum message size with ones's
message_vector=ones(1,max_message);
message_vector(1:length(message))=message;
% generate shell of watermarked image
watermarked_image=cover_object;
% read in key for PN generator
file_name='_key.bmp';
key=double(imread(file_name))./256;
% reset MATLAB's PN generator to state "key"
rand('state',1);
% generate PN sequences for "1" and "0"
pn_sequence_one=round(2*(rand(1,sum(sum(midband)))-0.5));
pn_sequence_zero=round(2*(rand(1,sum(sum(midband)))-0.5));
% find two highly un-correlated PN sequences
if (pn_sequence_search=='T')
while (corr2(pn_sequence_one,pn_sequence_zero) > -0.55)
pn_sequence_one=round(2*(rand(1,sum(sum(midband)))-0.5));
pn_sequence_zero=round(2*(rand(1,sum(sum(midband)))-0.5));
end
end
% process the image in blocks
x=1;
y=1;
for (kk = 1:length(message_vector))
% transform block using DCT
dct_block=dct2(cover_object(y:y+blocksize-1,x:x+blocksize-1));
% if message bit contains zero then embed pn_sequence_zero into the mid-band
% componants of the dct_block
ll=1;
if (message_vector(kk)==0)
for ii=1:blocksize
for jj=1:blocksize
if (midband(jj,ii)==1)
dct_block(jj,ii)=dct_block(jj,ii)+k*pn_sequence_zero(ll);
ll=ll+1;
end
end
end
% otherwise, embed pn_sequence_one into the mid-band componants of dct_block
else
for ii=1:blocksize
for jj=1:blocksize
if (midband(jj,ii)==1)
dct_block(jj,ii)=dct_block(jj,ii)+k*pn_sequence_one(ll);
ll=ll+1;
end
end
end
end
% transform block back into spatial domain
watermarked_image(y:y+blocksize-1,x:x+blocksize-1)=idct2(dct_block);
% move on to next block. At and of row move to next row
if (x+blocksize) >= Nc
x=1;
y=y+blocksize;
else
x=x+blocksize;
end
end
% convert to uint8 and write the watermarked image out to a file
watermarked_image_int=uint8(watermarked_image);
imwrite(watermarked_image_int,'dct2_watermarked_mod.bmp','bmp');
% display processing time
elapsed_time=cputime-start_time,
% display psnr of watermarked image
psnr=psnr(cover_object,watermarked_image,Nc,Mc),
% display watermarked image
figure(1)
imshow(watermarked_image,[])
title('Watermarked Image')
数字水印嵌入提取算法matlab性能仿真,对比CDMA,DWT,DCT,COR以及LSB等多种水印方法,含仿真操作录像,理论文档
版权申诉
5星 · 超过95%的资源 23 浏览量
2022-04-19
18:10:36
上传
评论 2
收藏 5.2MB RAR 举报
fpga和matlab
- 粉丝: 15w+
- 资源: 2548
最新资源
- tensorflow-gpu-2.7.4-cp37-cp37m-manylinux2010-x86-64.whl
- 多段线、 圆、弧转多段线(仅我可见)
- tensorflow-2.7.2-cp38-cp38-manylinux2010-x86-64.whl
- yeyue-p8Yi4-ve4a83792.apk
- tensorflow-gpu-2.7.3-cp38-cp38-manylinux2010-x86-64.whl
- 五相感应电机矢量控制模型MATLAB
- RGLED (1) (1).circ
- IMG_20240427_215747.jpg
- python下前端WEB学习笔记
- 田间种植行排号自动生成工具
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈