www.gusucode.com > 对bmp文件进行Vector Quantization 运行其中的VQ_GUI.m文件 > VQcoding/VQ_GUI.m

    function varargout = VQ_GUI(varargin)
%Instruction:
%   Provide a Graphic User Interface for user to browse the file system and
%select one .bmp file
%
%   By clicking the OPEN button, you can brown the folders and select a bmp
%   file, show its image and relevant imformation like length and width.
%
%   By clicking the VQ_code button, the program then encode this bmp file 
%using a VQ algorithm withcodebook production using an LBG with centroid
%approximation (LBG-AC).The title "encode complete!!!! "appearing on the
%top mean the encoded image is shown now.
%       1.Generate the codebook by LBG algorithm;
%       2.Encode the bmp file with the generated codebook;
%       3.Show the encoded bmp file.
%
%   By clicking the Info button, you can learn the PSNR(Peak signal to
%    noise ratio) 、search codebook time and encode Time.
%
%   By clicking the Help button, you can read the help text.
%
%   By clicking the Close button, you can clear the image shown on the
%   screen.
gui_Singleton = 1;
gui_State = struct('gui_Name',       mfilename, ...
                   'gui_Singleton',  gui_Singleton, ...
                   'gui_OpeningFcn', @VQ_GUI_OpeningFcn, ...
                   'gui_OutputFcn',  @VQ_GUI_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 VQ_GUI is made visible.
function VQ_GUI_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 VQ_GUI (see VARARGIN)

% Choose default command line output for VQ_GUI
handles.output = hObject;

% Update handles structure
guidata(hObject, handles);

% UIWAIT makes VQ_GUI wait for user response (see UIRESUME)
% uiwait(handles.figure1);
text(0.8,0.5,'Press the "Open" button to open a BMP file', ...
        'HorizontalAlignment','right');
axis off

% --- Outputs from this function are returned to the command line.
function varargout = VQ_GUI_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 when figure1 is resized.
function figure1_ResizeFcn(hObject, eventdata, handles)
% hObject    handle to figure1 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)


% --- Executes on button press in pushbutton_Open.
function pushbutton_Open_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton_Open (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
a=scanimage;
imshow(a)
handles.Data=a;
[x,y,z]=size(a);
title(['Length:',int2str(x), '(pix)   width:',int2str(y),'(pix)']);
guidata(hObject,handles)

% --- Executes on button press in pushbuttonVQ_code.
function pushbuttonVQ_code_Callback(hObject, eventdata, handles)
% hObject    handle to pushbuttonVQ_code (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

a=handles.Data;
[aa,t1,t2,n]=vqcode1(a);
imshow(aa);
handles.Data2=aa;
handles.Time1=t1;
handles.Time2=t2;
handles.Noise=n;
title(' encode complete!!!! ');
guidata(hObject,handles)
% --- Executes on button press in pushbutton_Save.
function pushbutton_Save_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton_Save (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
aa=handles.Data2;
saveimage(aa)

% --- Executes on button press in pushbutton_Info.
function pushbutton_Info_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton_Info (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

t1=handles.Time1;
t2=handles.Time2;
n=handles.Noise;
title(['PSNR:',int2str(n), '   search codebook time:',int2str(t1),...
    's,encode Time:',int2str(t2),'s']);

% --- Executes on button press in pushbutton_Help.
function pushbutton_Help_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton_Help (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
helpwin VQ_GUI



% --- Executes on button press in pushbutton_Close.
function pushbutton_Close_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton_Close (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
plot(zeros());
text(1.6,0.5,'Press the "Open" button to open a BMP file', ...
        'HorizontalAlignment','right');
axis off





% --- Executes on button press in Original.
function Original_Callback(hObject, eventdata, handles)
% hObject    handle to Original (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
a=handles.Data;
imshow(a);
% --- Executes on button press in Encoded.
function Encoded_Callback(hObject, eventdata, handles)
% hObject    handle to Encoded (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
aa=handles.Data2;
imshow(aa);