(绝对可运行)加密图像中的可逆数据隐藏算法matlab代码(基于张新鹏教授的算法)

整理文档很辛苦,赏杯茶钱您下走!

免费阅读已结束,点击下载阅读编辑剩下 ...

阅读已结束,您可以下载文档离线阅读编辑

资源描述

%ThisistheprogramofReversibleDataHidinginEncryptedDomainclc;clear;%===============Readimage===========================original_p=rgb2gray(imread('LENA.tif'));[m,n]=size(original_p);%==============Imageencryption======================random_bits=rand(m,n*8)=0.5;%伪随机序列fori=1:mforj=1:ns=0;fork=0:7b(k+1)=mod(fix(double(original_p(i,j))/(2^k)),2);eb(k+1)=xor(b(k+1),random_bits(i,8*j+k-7));s=s+eb(k+1)*(2^k);endencrypted_image(i,j)=s;endendfigure(1);subplot(1,2,1);imshow(original_p);holdon;title('Originalimage','fontsize',16);subplot(1,2,2);encrypted_image=uint8(encrypted_image);imshow(encrypted_image);title('Encryptedimage','fontsize',16);%================Dataembedding======================size=8;%分块大小N=6;%置乱周期number1=3;number2=N-number1;lim_row=fix(m/size);%图像的分块数lim_col=fix(n/size);%图像的分块数bitts=3;watermessage=rand(lim_row,lim_col)0.5;%水印信息%======pseudo_randomly=======fori=1:lim_rowforj=1:lim_colblock_image{i,j}=encrypted_image((size*i-size+1):size*i,(size*j-size+1):size*j);%分块fork=1:sizefort=1:sizeindex=arnold(k,t,size,number1);%arnoldispermutateionfunction;arno_block_image{i,j}(index(1)+1,index(2)+1)=block_image{i,j}(k,t);endend%数据嵌入sum0=zeros(size/2,size);ifwatermessage(i,j)==0fork=0:7bbb{k+1}=mod(fix(double(arno_block_image{i,j}(1:size/2,:))/(2^k)),2);ifkbittsbbb{k+1}=~bbb{k+1};endsum0=sum0+bbb{k+1}*(2^k);enddata_image{i,j}=[sum0;double(arno_block_image{i,j}(size/2+1:size,:))];endsum1=zeros(size/2,size);ifwatermessage(i,j)==1fork=0:7bbb{k+1}=mod(fix(double(arno_block_image{i,j}(size/2+1:size,:))/(2^k)),2);ifkbittsbbb{k+1}=~bbb{k+1};endsum1=sum1+bbb{k+1}*(2^k);enddata_image{i,j}=[double(arno_block_image{i,j}(1:size/2,:));sum1];endfork=1:sizefort=1:sizeindex=arnold(k,t,size,number2);%arnoldispermutateionfunction;re_data_image{i,j}(index(1)+1,index(2)+1)=data_image{i,j}(k,t);endend%合成嵌入数据后的图像data_en_image((size*i-size+1):size*i,(size*j-size+1):size*j)=re_data_image{i,j};endend%=====Encryptimagewhichcontainsdata====fori=1:lim_row*sizeforj=1:lim_col*sizes=0;fork=0:7b(k+1)=mod(fix(data_en_image(i,j)/(2^k)),2);eb(k+1)=xor(b(k+1),random_bits(i,8*j+k-7));s=s+eb(k+1)*(2^k);endde_data_image(i,j)=s;endendfigure(2);holdon;subplot(1,2,1);imshow(original_p);title('Originalimage','fontsize',16);subplot(1,2,2);imshow(uint8(de_data_image));title('Decryptedimagecontainsdata','fontsize',16);%直接解密图像的峰值信噪比sumsss=0;fori=1:lim_row*sizeforj=1:lim_col*sizesumsss=(de_data_image(i,j)-double(original_p(i,j)))^2+sumsss;endendmse=sumsss/((lim_row*size)*(lim_row*size));psnr=10*log10(255^2/mse);%======Extractdataandrecoverimage=======fori=1:lim_rowforj=1:lim_colblock_de_image{i,j}=de_data_image((size*i-size+1):size*i,(size*j-size+1):size*j);%分块fork=1:sizefort=1:sizeindex=arnold(k,t,size,number1);%arnoldispermutateionfunction;ar_block_de_image{i,j}(index(1)+1,index(2)+1)=block_de_image{i,j}(k,t);endendsum0=zeros(size/2,size);sum1=zeros(size/2,size);fork=0:7bbb0{k+1}=mod(fix(ar_block_de_image{i,j}(1:size/2,:)/(2^k)),2);bbb1{k+1}=mod(fix(ar_block_de_image{i,j}(size/2+1:size,:)/(2^k)),2);ifkbittsbbb0{k+1}=~bbb0{k+1};bbb1{k+1}=~bbb1{k+1};endsum0=sum0+bbb0{k+1}*(2^k);sum1=sum1+bbb1{k+1}*(2^k);endar_H0_image{i,j}=[sum0;ar_block_de_image{i,j}(size/2+1:size,:)];ar_H1_image{i,j}=[ar_block_de_image{i,j}(1:size/2,:);sum1];fork=1:sizefort=1:sizeindex=arnold(k,t,size,number2);%arnoldispermutateionfunction;H0_image{i,j}(index(1)+1,index(2)+1)=ar_H0_image{i,j}(k,t);H1_image{i,j}(index(1)+1,index(2)+1)=ar_H1_image{i,j}(k,t);endendf0=0;f1=0;foru=2:size-1forv=2:size-1f0=f0+abs(H0_image{i,j}(u,v)-(H0_image{i,j}(u-1,v)+H0_image{i,j}(u,v-1)+H0_image{i,j}(u+1,v)+H0_image{i,j}(u,v+1))/4);f1=f1+abs(H1_image{i,j}(u,v)-(H1_image{i,j}(u-1,v)+H1_image{i,j}(u,v-1)+H1_image{i,j}(u+1,v)+H1_image{i,j}(u,v+1))/4);endendif(f0-f1)0extract_bits(i,j)=0;recover_image(size*i-size+1:size*i,size*j-size+1:size*j)=H0_image{i,j};elseextract_bits(i,j)=1;recover_image(size*i-size+1:size*i,size*j-size+1:size*j)=H1_image{i,j};endendendfigure(3);subplot(1,2,1);imshow(original_p);holdon;title('Originalimage','fontsize',16);subplot(1,2,2);recover_image=uint8(recover_image);imshow(recover_image);holdon;title('Recoveredimage','fontsize',16);%==============analysis============diff=original_p(1:lim_row*size,1:lim_col*size)-recover_image;counts=0;fori=1:lim_rowforj=1:lim_colblock_diff{i,j}=diff((size*i-size+1):size*i,(size*j-size+1):size*j);%分块ifextract_bits(i,j)~=watermessage(i,j)block_diff{i,j}=ones(size,size)*255;counts=counts+1;elseblock_diff{i,j}=original_p((size*i-size+1):size*i,(size*j-size+1):size*j);enddiff_image((size*i-size+1):size*i,(size*j-size+1):size*j)=block_diff{i,j};endendfigure(4);imshow(diff_image);holdon;%title('Blocksofincorrect','fontsize',16);%错误率与分块大小的关系rate=counts/((lim_row)*(lim_col))

1 / 5
下载文档,编辑使用

©2015-2020 m.777doc.com 三七文档.

备案号:鲁ICP备2024069028号-1 客服联系 QQ:2149211541

×
保存成功