操作系统寒武纪 - 会让企业IT高兴吗?
588
2022-10-19
混沌对图像的置乱
加密函数:
function myencryption%对图像进行加密,采用置乱的方式clear;clc;%key为加密密钥%os原始图像的路径[filename pathname]=uigetfile('*.bmp;*.tiff;*.tif', '读入需要加密的图像'); os=[pathname filename]; [filename pathname]=uiputfile({'*.bmp';'*.tiff';'*.tif'}, '保存加密后的图像'); ozls=[pathname filename]; % key=0.98;%%%%%%%%%%%%读入混沌初始值prompt={'混沌初始值 '};myTitle='initial value';lines=1;def={'98'};mya=inputdlg(prompt,myTitle,lines,def,'on');key11=['0.',mya{1}];key=str2num(key11);%%%%%%%%%%%%o=imread(os);% figure,imshow(o);%计算原始图像的大小[m n]=size(o);%l=zeros(m,n);l=linspace(0,0,m*n);l(1)=key;for i=2:m*n l(i)=1-2*l(i-1)*l(i-1);end% %对生成的混沌序列进行排序% [lsort lindex]=sort(l);% t=linspace(0,0,m*n);% t(1)=0.98;% for i=1:m*n% t(i+1)=1-2*t(i)*t(i);% end% for i=1:m*n% if (l(i)>=0)% l(i)=1;% else% l(i)=0;% end% end% l=~l;% subplot(2,2,2),imshow(l),title('混沌图像');[lsort,lindex]=sort(l);%ozl =original zhi luan 表示置乱后的原始图像ozl=zeros(m,n);for i=1:m*n ozl(i)=o(lindex(i));end% ozl=reshape(ozl,m,n);%%oo =original fu yuan% ofy=zeros(m,n);% for i=1:m*n% ofy(lindex(i))=ozl(i);% end% h= waitbar(0,'程序处理中,请耐心等待。。。');% for i=1:100, % computation here %% waitbar(i/100)% end% close(h) ;%首先保存需要加密的图像ozl=uint8(ozl);ozl=double(ozl);imwrite(ozl,ozls);subplot(1,2,1)imshow(o)% title('原始图像')set(gca,'Title',text('String','原始图像')) subplot(1,2,2),imshow(ozl,[]);set(gca,'Title',text('String','加密后图像')) % title('加密后图像');% [filename pathname]=uiputfile({'*.bmp';'*.tiff';'*.tif'}, '保存加密后图像'); % os=[pathname filename]; % % [filename pathname]=uiputfile({'*.bmp';'*.tiff';'*.tif'}, '保存图像'); % % os=[pathname filename]; % imwrite(ozl,os);% subplot(1,3,3),imshow(ofy,[]),title('复原图像');% [filename pathname]=uiputfile({'*.bmp';'*.tiff';'*.tif'}, '保存加密后的图像'); % os=[pathname filename]; % %进度条% % h= waitbar(0,'程序处理中,请耐心等待。。。');% % for i=1:100, % computation here %% % waitbar(i/100);% % end% % close(h) ;% ozl=uint8(ozl);% imwrite(ozl,os);% figure,imshow(ozl,[]);% test=imread(os);% figure,imshow(test,[]);
解密函数:
function mydecryption%对加密后的图像进行解密clear;clc;% key=0.98%key为解密密钥%os原始图像的路径[filename pathname]=uigetfile('*.bmp;*.tiff;*.tif', '读入需要解密的图像'); os=[pathname filename]; [filename pathname]=uiputfile({'*.bmp';'*.tiff';'*.tif'}, '保存解密后的图像'); ofys=[pathname filename]; ozl=imread(os);% figure,imshow(ozl,[]);%%%%%%%%%%%%%设置混沌初始值prompt={'混沌初始值 '};myTitle='initial value';lines=1;def={'98'};mya=inputdlg(prompt,myTitle,lines,def,'on');key11=['0.',mya{1}];key=str2num(key11);%%%%%%%%%%%%设置混沌初始值%计算原始图像的大小[m n]=size(ozl);%l=zeros(m,n);l=linspace(0,0,m*n);l(1)=key;for i=2:m*n l(i)=1-2*l(i-1)*l(i-1);end% %对生成的混沌序列进行排序% [lsort lindex]=sort(l);% t=linspace(0,0,m*n);% t(1)=0.98;% for i=1:m*n% t(i+1)=1-2*t(i)*t(i);% end% for i=1:m*n% if (l(i)>=0)% l(i)=1;% else% l(i)=0;% end% end% l=~l;% subplot(2,2,2),imshow(l),title('混沌图像');[lsort,lindex]=sort(l);%ozl =original zhi luan 表示置乱后的原始图像% ozl=zeros(m,n);% for i=1:m*n% ozl(i)=o(lindex(i));% end% ozl=reshape(ozl,m,n);%%oo =original fu yuanofy=zeros(m,n);for i=1:m*n ofy(lindex(i))=ozl(i);end% ozl=uint8(ozl);ozl=double(ozl);imwrite(ofy,ofys);h= waitbar(0,'程序处理中,请耐心等待。。。');for i=1:100, % computation here %waitbar(i/100)endclose(h) ;subplot(1,2,1),imshow(ozl,[]);%,title('需要解密的图像');set(gca,'Title',text('String','需要解密的图像')) subplot(1,2,2),imshow(ofy,[]);%,title('解密后图像');set(gca,'Title',text('String','解密后图像')) % [filename pathname]=uiputfile({'*.bmp';'*.tiff';'*.tif'}, '保存加密后图像'); % os=[pathname filename]; % imwrite(ozl,os);% subplot(1,3,3),imshow(ofy,[]),title('复原图像');
版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。
发表评论
暂时没有评论,来抢沙发吧~