📄 vision.m
字号:
function varargout = vision(varargin)
% VISION M-file for vision.fig
% VISION, by itself, creates a new VISION or raises the existing
% singleton*.
%
% H = VISION returns the handle to a new VISION or the handle to
% the existing singleton*.
%
% VISION('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in VISION.M with the given input arguments.
%
% VISION('Property','Value',...) creates a new VISION or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before vision_OpeningFunction gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to vision_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 vision
% Last Modified by GUIDE v2.5 17-Jun-2005 10:48:22
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @vision_OpeningFcn, ...
'gui_OutputFcn', @vision_OutputFcn, ...
'gui_LayoutFcn', [] , ...
'gui_Callback', []);
if nargin & isstr(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 vision is made visible.
function vision_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 vision (see VARARGIN)
% Choose default command line output for vision
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes vision wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
function varargout = vision_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 during object creation, after setting all properties.
function run_edit_CreateFcn(hObject, eventdata, handles)
% hObject handle to run_edit (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
set(hObject,'BackgroundColor','white');
else
set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));
end
function run_edit_Callback(hObject, eventdata, handles)
% hObject handle to run_edit (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 run_edit as text
% str2double(get(hObject,'String')) returns contents of run_edit as a double
filename=get(handles.run_edit,'String');%获得输入的文件名
if length(filename)>4
fid = fopen(filename,'r');%读文件
s = fread(fid,inf,'uchar=>uchar');%把文件中的字符按字节顺序存储在字符串列向量s中
f = s';%把s置换得到f
save initial_data f;%把源数据存储到initial_data
end
% --- Executes on button press in mode_push.
function mode_push_Callback(hObject, eventdata, handles)
% hObject handle to mode_push (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
load initial_data; %导入源数据
[nf,gai,pin]=gailv(f); %调用函数gailv是计算数组f中每个字符的概率gai
[low,high,mode] = area(nf,gai); %调用函数area是计算数组f中每个字符的子区间[low,high]
save mode_data nf low high gai pin; %保存概率模型的相关数据
model;
% --- Executes on button press in encode_push.
function encode_push_Callback(hObject, eventdata, handles)
% hObject handle to encode_push (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
load initial_data; %导入源数据
load mode_data; %导入概率模型的相关数据
time1 = fix(clock); %记下此时的时间time1
[final,mn] = encode(f,nf,low,high); %调用函数encode对源数据进行压缩,输出压缩流final,final是个小数数组
time2 = fix(clock); %记下此时的时间time2
encode_time = time2-time1; %计算编码所用的时间encode_time
compress = length(f)*8/(length(final)*17);
entropy = 0;
for j = 1:length(nf)
entropy = entropy + pin(j) * (-log2(gai(j)));
end
save encode_data final mn encode_time compress entropy; %保存编码的相关数据
set(handles.encode_edit, 'String',length(final)*2);
set(handles.compress_edit, 'String',compress);
% --- Executes on button press in decode_push.
function decode_push_Callback(hObject, eventdata, handles)
% hObject handle to decode_push (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
load initial_data; %导入源数据
load mode_data; %导入概率模型的相关数据
load encode_data; %导入编码的相关数据
time1 = fix(clock); %记下此时的时间time1
result = decode(final,nf,low,high,mn); %调用函数decode对压缩流final实行解压缩得到result
time2 = fix(clock); %记下此时的时间time2
decode_time = time2-time1; %计算解码所用的时间decode_time
h1 = find(double(f)-double(result)>0);%查找出错的字符个数
h2 = find(double(f)-double(result)<0);%查找出错的字符个数
error_sum = length(h1)+length(h2);%计算总共出错的字符个数error_sum
save decode_data result decode_time error_sum; %保存解码的相关数据
set(handles.decode_edit, 'String',error_sum);
% --- Executes on button press in exit_push.
function exit_push_Callback(hObject, eventdata, handles)
% hObject handle to exit_push (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
close(gcf);
% --- Executes during object creation, after setting all properties.
function output_edit_CreateFcn(hObject, eventdata, handles)
% hObject handle to output_edit (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
set(hObject,'BackgroundColor','white');
else
set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));
end
function output_edit_Callback(hObject, eventdata, handles)
% hObject handle to output_edit (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 output_edit as text
% str2double(get(hObject,'String')) returns contents of output_edit
% as a double
% --- Executes on button press in print_push.
function print_push_Callback(hObject, eventdata, handles)
% hObject handle to print_push (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
load encode_data;
load decode_data;
time = encode_time+decode_time;
set(handles.output_edit, 'String',time(5:6));
% --- Executes during object creation, after setting all properties.
function encode_edit_CreateFcn(hObject, eventdata, handles)
% hObject handle to encode_edit (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
set(hObject,'BackgroundColor','white');
else
set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));
end
function encode_edit_Callback(hObject, eventdata, handles)
% hObject handle to encode_edit (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 encode_edit as text
% str2double(get(hObject,'String')) returns contents of encode_edit as a double
% --- Executes during object creation, after setting all properties.
function decode_edit_CreateFcn(hObject, eventdata, handles)
% hObject handle to decode_edit (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
set(hObject,'BackgroundColor','white');
else
set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));
end
function decode_edit_Callback(hObject, eventdata, handles)
% hObject handle to decode_edit (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 decode_edit as text
% str2double(get(hObject,'String')) returns contents of decode_edit as a double
% --- Executes during object creation, after setting all properties.
function compress_edit_CreateFcn(hObject, eventdata, handles)
% hObject handle to compress_edit (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
set(hObject,'BackgroundColor','white');
else
set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));
end
function compress_edit_Callback(hObject, eventdata, handles)
% hObject handle to compress_edit (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 compress_edit as text
% str2double(get(hObject,'String')) returns contents of compress_edit as a double
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -