function varargout = software(varargin)
% SOFTWARE M-file for software.fig
% SOFTWARE, by itself, creates a new SOFTWARE or raises the existing
% singleton*.
%
% H = SOFTWARE returns the handle to a new SOFTWARE or the handle to
% the existing singleton*.
%
% SOFTWARE('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in SOFTWARE.M with the given input arguments.
%
% SOFTWARE('Property','Value',...) creates a new SOFTWARE or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before software_OpeningFunction gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to software_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
% Copyright 2002-2003 The MathWorks, Inc.
% Edit the above text to modify the response to help software
% Last Modified by GUIDE v2.5 15-Dec-2008 12:02:41
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @software_OpeningFcn, ...
'gui_OutputFcn', @software_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 software is made visible.
function software_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 software (see VARARGIN)
% Choose default command line output for software
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes software wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
function varargout = software_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 a
[filename,pathname]=...
uigetfile({'*.jpg';'*.bmp';'*.gif'},'选择图片');
str=[pathname filename];
%提示选择图片
if length(filename)<4
errordlg('请选择图片');
return;
end
a=imread(str);
axes(handles.axes1);
imshow(a);
set(handles.edit3,'string',str);
% --- 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)
%加密程序
global a
%提示选择加密图片
[x,y,z]=size(a);
if x<1
errordlg('请选择加密图片');
return;
end
s=get(handles.edit1,'string');
s=str2num(s);
%提示输入s
if length(s)<1
errordlg('请输入s');
return;
end
h=get(handles.edit2,'string');
h=str2num(h);
%提示输入h
if length(h)<1
errordlg('请输入h');
return;
end
%加密开始
hr=waitbar(0,'等待正在加密...');
[m1,n1]=size(a(:,:,1));
x=zeros(1,m1+n1);
y=[1:m1+n1];
%然后, 用Logitic 映射产生混沌序列:
for n=1:m1+n1-1
x(1)=s;
q=h;
x(n+1)=q*x(n)*(1- x(n));
end
%排序行置乱
for f=1:m1-1
for h=f:m1
if x(f)>x(h)
k=x(f);
x(f)=x(h);
x(h)=k;
m=y(f);
y(f)=y(h);
y(h)=m;
c1=a(f,:,:);
a(f,:,:)=a(h,:,:);
a(h,:,:)=c1;
end
end
waitbar(f/(m1+n1-1),hr,'等待正在加密...');
end
%列置乱
for f=m1+1:m1+n1-1
for h=f:m1+n1
if x(f)>x(h)
k=x(f);
x(f)=x(h);
x(h)=k;
m=y(f);
y(f)=y(h);
y(h)=m;
c1=a(:,f-m1,:);
a(:,f-m1,:)=a(:,h-m1,:);
a(:,h-m1,:)=c1;
end
end
waitbar(f/(m1+n1-1),hr,'等待正在加密...');
end
waitbar(1,hr,'完成!');
delete(hr);
pause(0.5);
b=a;
axes(handles.axes1);
imshow(real(b));
imwrite(b,'a.bmp');
% --- 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)
%解密程序
global a
[x,y,z]=size(a);
%提示选择解密图片
if x<1
errordlg('请选择解密图片');
return;
end
%提示输入s
s=get(handles.edit1,'string');
s=str2num(s);
if length(s)<1
errordlg('请输入s');
return;
end
%提示输入h
h=get(handles.edit2,'string');
h=str2num(h);
if length(h)<1
errordlg('请输入h');
return;
end
%解密开始
hr=waitbar(0,'等待正在解密...');
[m1,n1]=size(a(:,:,1));
x=zeros(1,m1+n1);
y=[1:m1+n1];
%然后, 用Logitic 映射产生混沌序列:
for n=1:m1+n1-1
x(1)=s;
q=h;
x(n+1)=q*x(n)*(1- x(n));
end
%行置乱
for f=1:m1-1
for h=f:m1
if x(f)>x(h)
k=x(f);
x(f)=x(h);
x(h)=k;
m=y(f);
y(f)=y(h);
y(h)=m;
end
end
end
%列置乱
for f=m1+1:m1+n1-1
for h=f:m1+n1
if x(f)>x(h)
k=x(f);
x(f)=x(h);
x(h)=k;
m=y(f);
y(f)=y(h);
y(h)=m;
end
end
end
%行解密
for f=1:m1-1
for h=f:m1
if y(f)>y(h)
m=y(f);
y(f)=y(h);
y(h)=m;
c1=a(f,:,:);
a(f,:,:)=a(h,:,:);
a(h,:,:)=c1;
end
end
waitbar(f/(m1+n1-1),hr,'等待正在解密...');
end
%列解密
for f=m1+1:m1+n1-1
for h=f:m1+n1
if y(f)>y(h)
m=y(f);
y(f)=y(h);
y(h)=m;
c1=a(:,f-m1,:);
a(:,f-m1,:)=a(:,h-m1,:);
a(:,h-m1,:)=c1;
end
end
waitbar(f/(m1+n1-1),hr,'等待正在解密...');
end
waitbar(1,hr,'完成!');
delete(hr);
pause(0.5);
%图像去噪修复
for f=2:n1
if a(1,f,:)<=0
a(1,f,:)=a(1,f-1,:);
end
end
for g=2:m1
if a(g,1,:)<=0
a(g,1,:)=a(g-1,1,:);
end
end
for g=2:m1
for f=2:n1
if a(g,f,:)<=0
a(g,f,:)=a(g-1,f,:)/2+a(g,f-1,:)/2;
end
end
end
b=a;
axes(handles.axes1);
imshow(real(b));
imwrite(b,'b.bmp');
% --- 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)
clear all;
close(gcf);
function edit1_Callback(hObject, eventdata, handles)
% hObject handle t