1.软件版本
MATLAB2013b
2.本算法理论知识
针对这个要求,我进一步做了部分改进,改进思路如下:
这里,考虑一种logistic-map的混合混沌序列替代传统的logistic序列。
logistic序列
程序对应的是:
logistic-map改进公式进行设计,如下:
我根据这种改进公式进行设计,代码如下:
3.部分核心代码
function varargout = topss(varargin)
% TOPSS MATLAB code for topss.fig
% TOPSS, by itself, creates a new TOPSS or raises the existing
% singleton*.
%
% H = TOPSS returns the handle to a new TOPSS or the handle to
% the existing singleton*.
%
% TOPSS('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in TOPSS.M with the given input arguments.
%
% TOPSS('Property','Value',...) creates a new TOPSS or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before topss_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to topss_OpeningFcn via varargin.
%
% *See GUI Options on GUIDE's Tools menu. Choose "GUI allows only one
% instance to run (singleton)".
%
% See also: GUIDE, GUIDATA, GUIHANDLES
% Edit the above text to modify the response to help topss
% Last Modified by GUIDE v2.5 19-Apr-2019 18:31:39
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @topss_OpeningFcn, ...
'gui_OutputFcn', @topss_OutputFcn, ...
'gui_LayoutFcn', [] , ...
'gui_Callback', []);
if nargin && ischar(varargin{1})
gui_State.gui_Callback = str2func(varargin{1});
end
if nargout
[varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT
% --- Executes just before topss is made visible.
function topss_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% varargin command line arguments to topss (see VARARGIN)
% Choose default command line output for topss
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes topss wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
function varargout = topss_OutputFcn(hObject, eventdata, handles)
% varargout cell array for returning output args (see VARARGOUT);
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Get default command line output from handles structure
varargout{1} = handles.output;
% --- Executes on button press in pushbutton1.
function pushbutton1_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global types;
global Ijpg;
global Iwav;
global Itxt;
global signals1;
global y1;
global y2;
global Iter;
global Lens;
global Len;
global RR;
global vmin;
[filename,pathname]=uigetfile({'*.*';'*.jpg';'*.m';'*.wav'},'选择文件类型');
if isequal(filename,0)||isequal(pathname,0)
errordlg('您还没有选取图片!!','温馨提示');%如果没有输入,则创建错误对话框
return;
else
file=[pathname,filename];%合成路径+文件名
type=file(end-2:end);
if type=='jpg'
types=1;
end
if type=='wav'
types=2;
end
if type(end)=='m'
types=3;
end
end
if types==1
Ijpg = imread(file);
Ijpg = imresize(Ijpg,0.5, 'bicubic');
axes(handles.axes1);
imshow(Ijpg)
[R,C,K] = size(Ijpg);
if K == 1
signals2 = Ijpg;
else
signals2 = rgb2gray(Ijpg);
end
% figure;
% imhist(signals2)
end
if types==2
[Iwav,Fs] = audioread(file);
axes(handles.axes1);
plot(Iwav)
end
if types==3
run(file)
data;
%将文本转换为数字
Itxt= letter2num(data);
axes(handles.axes1);
plot(Itxt)
end
% --- Executes on button press in pushbutton2.
function pushbutton2_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
paras;
if types==1
[R,C,K] = size(Ijpg);
if K == 1
signals = Ijpg;
else
signals = [Ijpg(:,:,1),Ijpg(:,:,2),Ijpg(:,:,3)];
end
end
if types==2
signals = Iwav;
vmin = min(signals);
signals = uint8(round(250*(signals-vmin)));
RR = 400;
Len = length(signals)-RR*floor(length(signals)/RR);
signals2 = [signals;zeros(RR-Len,1)];
Lens = length(signals2);
signals3 = reshape(signals2,[RR,floor(length(signals2)/RR)]);
signals=signals3;
end
if types==3
signals = Itxt';
vmin = min(signals);
signals = uint8(round(signals-vmin));
RR = 400;
Len = length(signals)-RR*floor(length(signals)/RR);
signals2 = [signals;zeros(RR-Len,1)];
Lens = length(signals2);
signals3 = reshape(signals2,[RR,floor(length(signals2)/RR)]);
signals=signals3;
end
[M,N]=size(signals);
%logistic u值
r1 = 1.8;
r2 = 1.8;
tic;
%多次迭代,每次迭代初始值改变
Iter = str2num(get(handles.edit1, 'string'));
for i = 1:Iter
%logistic初值
if i == 1
x1(1)= 0.6;
x2(1)= 0.7;
else
x1(1)= x0;
x2(1)= y0;
end
%通过baker映射对logistic混沌映射初值进行扰动
[x0,y0] = func_baker(x1(1),x2(1));
if i==1
[signals1{i},y1{i},y2{i}] = func_jiami(signals,r1,r2,x0,y0,M,N);
else
[signals1{i},y1{i},y2{i}] = func_jiami(signals1{i-1},r1,r2,x0,y0,M,N);
end
end
result=imgentropy(signals1{Iter});
%信息熵
disp('信息熵');
result
toc
axes(handles.axes2);
if types==1
if K==1
imshow(signals1{Iter});
else
tmps = signals1{Iter};
tmps2(:,:,1) = tmps(:,1:C);
tmps2(:,:,2) = tmps(:,C+1:2*C);
tmps2(:,:,3) = tmps(:,2*C+1:3*C);
imshow(tmps2);
end
[R,C,K] = size(Ijpg);
if K == 1
signals2 = tmps2;
else
signals2 = rgb2gray(tmps2);
end
% figure;
% imhist(signals2)
end
if types==2
xx=reshape(signals1{Iter},[1,Lens]);
plot(xx)
end
if types==3
xx=reshape(signals1{Iter},[1,Lens]);
plot(xx)
end
% --- Executes on button press in pushbutton3.
function pushbutton3_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton3 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
paras;
Pow = str2num(get(handles.edit2, 'string'));
Rs = signals1{Iter};
Rs = uint8(double(Rs)+Pow/100*randn(size(Rs)));
axes(handles.axes3);
if types==1
if K==1
imshow(Rs);;
else
tmps = Rs;
tmps2(:,:,1) = tmps(:,1:C);
tmps2(:,:,2) = tmps(:,C+1:2*C);
tmps2(:,:,3) = tmps(:,2*C+1:3*C);
imshow(tmps2);
end
[R,C,K] = size(Ijpg);
if K == 1
signals2 = tmps2;
else
signals2 = rgb2gray(tmps2);
end
% figure;
% imhist(signals2)
end
if types==2
xx=reshape(Rs,[1,Lens]);
plot(xx)
end
if types==3
xx=reshape(Rs,[1,Lens]);
plot(xx)
end
% --- Executes on button press in pushbutton4.
function pushbutton4_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton4 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
paras;
for i = 1:Iter
if i == 1
signals2 = func_jiemi(Rs,y1{Iter-i+1},y2{Iter-i+1},M,N);
else
signals2 = func_jiemi(signals2,y1{Iter-i+1},y2{Iter-i+1},M,N);
end
end
axes(handles.axes4);
if types==1
if K==1
data = signals2;
else
data(:,:,1) = signals2(:,1:C);
data(:,:,2) = signals2(:,C+1:2*C);
data(:,:,3) = signals2(:,2*C+1:3*C);
end
imshow(data);
[R,C,K] = size(Ijpg);
if K == 1
signals3 = data;
else
signals3 = rgb2gray(data);
end
% figure;
% imhist(signals3)
end
if types==2
signals2b=reshape(signals2,[1,Lens]);
signals2b=double(signals2b)/250+vmin;
plot(signals2b(1:end-(RR-Len)));
end
if types==3
signals2b=reshape(signals2,[1,Lens]);
signals2b=double(signals2b);
plot(signals2b(1:end-(RR-Len)));
%输出文字
disp('解密文字');
signals2b(1:end-(RR-Len))+32
str=num2letter(signals2b(1:end-(RR-Len))+32)
str
end
% --- Executes on button press in pushbutton5.
function pushbutton5_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton5 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
clc;
clear;
close all;
function edit1_Callback(hObject, eventdata, handles)
% hObject handle to edit1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of edit1 as text
% str2double(get(hObject,'String')) returns contents of edit1 as a double
% --- Executes during object creation, after setting all properties.
function edit1_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function edit2_Callback(hObject, eventdata, handles)
% hObject handle to edit2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of edit2 as text
% str2double(get(hObject,'String')) returns contents of edit2 as a double
% --- Executes during object creation, after setting all properties.
function edit2_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
4.操作步骤与仿真结论
参考文献A29-04: