【圖像加密】基于不變像素、可變像素、采樣像素分類置亂圖像加密解密含Matlab源碼
1 簡介
分析了當前一類基于混沌系統(tǒng)的圖像加密算法,指出普遍存在安全性方面的不足.基于此,提出了一種全新的不變像素、可變像素、采樣像素分類置亂的混沌圖像加密算法.
2 部分代碼
% Separable and error-free reversible data hiding in encrypted images .
%可以有不大于最大嵌入率的任意嵌入率.
clc;tic;
clear;
close all;
tic
%閾值.
Tn=-2%負數(shù) (滿足|Tn-1|<Tp)
Tp=1%正數(shù)
im=imread('lena512.bmp');
%im=rgb2gray(img);
figure(1);
imshow(im)
title('原始圖像');
im=double(im);
[m,n]=size(im)
%% 預處理
[pre, HHist,L1]=pretreatment(im,Tn,Tp);%pre表示與處理后圖像,HHist表示直方圖,L1記錄溢出位
?figure(2);
% ?imshow(uint8(pre))
?H1=bar(-255:255,HHist);
box off;xlabel('插值誤差');ylabel('出現(xiàn)次數(shù)');title('原始插值誤差直方圖');set(gcf,'color','white');
% 將位置映射壓縮作為邊信息(游長編碼)
L1_C=mycode(L1); ?
%% 圖像加密
enkey=1:14;
[encrypted,mm,Mm,p,fb]=encryption_Xu(pre,enkey,Tn,Tp);
?figure(3);
?imshow(uint8(encrypted));
?title('加密圖像');%加密圖像
encrypted_p=psnr(im,encrypted)
%% 信息隱藏,total1為閾值為[-2 1]時可嵌入的最大容量
?%max_embed_rate=total1/(512*512)
?%w為待嵌入的秘密比特
?nn=ceil(log((Tp-Tn)+1)/log(2));
?rand('state',20);
?[m,n]=size(encrypted);
w = rand(1,mm*(8-nn)-Mm)>=0.5; ?
w_l=length(w);
?embed=embedding_Xu(encrypted,w,mm,Tn,Tp,Mm);
?figure(4);
imshow(uint8(embed));
title('標記加密圖像');
%% 數(shù)據(jù)提取和恢復
%case1:只提取數(shù)據(jù)
extrab=extract_Xu(embed,Tn,Tp,w_l,mm,Mm);
a=length(extrab);
?actually_embed_rate=a/(m*n);%嵌入率 ? ?
%% 恢復圖像
decrypted=decryption_Xu(embed,enkey,Tn,Tp,mm,L1_C,Mm,p,fb);
figure(5);
imshow(uint8(decrypted)); ?
title('恢復圖像');
recovery_p=psnr(im, decrypted) ?; ?
%
% %case3:從解密域提取數(shù)據(jù)并恢復圖像,即先對圖像解密,再提取數(shù)據(jù),恢復圖像.
% [extrab,recovery_image]=recover1(embed,L1_C,enkey,Tn,Tp,w_l);
%
% %case4:從加密域提取數(shù)據(jù)并恢復圖像,即先提取數(shù)據(jù),再對圖像解密,恢復圖像.
% [extrab,recovery_image]=recover2_Xu(embed,L1_C,enkey,Tn,Tp,w_l);
%
% figure(7);
% imshow(uint8( recovery_image)); ?
% title('recovery image');
% recovery_p=psnr(im, recovery_image) ?
%
% ?%計算提取的錯誤率
% ? l=length(w);
% ? s=0;
% ? for i=1:l
% ? ? ? if ?extrab(i)~=w(i)
% ? ? ? ? ? s=s+1;
% ? ? ? end
% ? end
% ? error_rate=s/l
? toc
3 仿真結(jié)果




4 參考文獻
[1]謝國波, 王添. 基于像素置亂和比特替換的混沌圖像加密算法[J]. 微電子學與計算機, 2016, 33(3):6.
博主簡介:擅長智能優(yōu)化算法、神經(jīng)網(wǎng)絡預測、信號處理、元胞自動機、圖像處理、路徑規(guī)劃、無人機等多種領(lǐng)域的Matlab仿真,相關(guān)matlab代碼問題可私信交流。
部分理論引用網(wǎng)絡文獻,若有侵權(quán)聯(lián)系博主刪除。
