www.gusucode.com > 自己编写的一个基于matlab的图像压缩程序,有GUI界面,不能程度的压缩效果以及信噪比 > 自己编写的一个基于matlab的图像压缩程序,有GUI界面,不能程度的压缩效果以及信噪比/BP神经网络的图像压缩/GUI_2.m
function varargout = GUI_2(varargin) % GUI_2 M-file for GUI_2.fig % GUI_2, by itself, creates a new GUI_2 or raises the existing % singleton*. % % H = GUI_2 returns the handle to a new GUI_2 or the handle to % the existing singleton*. % % GUI_2('CALLBACK',hObject,eventData,handles,...) calls the local % function named CALLBACK in GUI_2.M with the given input arguments. % % GUI_2('Property','Value',...) creates a new GUI_2 or raises the % existing singleton*. Starting from the left, property value pairs are % applied to the GUI before GUI_2_OpeningFunction gets called. An % unrecognized property name or invalid value makes property application % stop. All inputs are passed to GUI_2_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 GUI_2 % Last Modified by GUIDE v2.5 22-Apr-2011 15:28:32 % Begin initialization code - DO NOT EDIT gui_Singleton = 1; gui_State = struct('gui_Name', mfilename, ... 'gui_Singleton', gui_Singleton, ... 'gui_OpeningFcn', @GUI_2_OpeningFcn, ... 'gui_OutputFcn', @GUI_2_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 GUI_2 is made visible. function GUI_2_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 GUI_2 (see VARARGIN) % Choose default command line output for GUI_2 handles.output = hObject; % Update handles structure guidata(hObject, handles); % UIWAIT makes GUI_2 wait for user response (see UIRESUME) % uiwait(handles.figure1); % --- Outputs from this function are returned to the command line. function varargout = GUI_2_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 im [filename,pathname]=... uigetfile({'*.*';'*.jpg';'*.bmp';'*.gif';'*.tif'},''); if pathname == 0 return; end str=[pathname filename]; im=imread(str); axes(handles.axes1); imshow(im);title('') % --- 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) clc close all close(gcf); % -------------------------------------------------------------------- function uipanel1_SelectionChangeFcn(hObject, eventdata, handles) % hObject handle to uipanel1 (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 kj4. function kj4_Callback(hObject, eventdata, handles) % hObject handle to kj4 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) global im global I global P global I2 global i3 global II global P_1 global T global net global Y_chonggou global Ychonggou_ceshi global YYchonggou_ceshi global YYchonggou_ceshi1 global Ychonggou_ce global current_Obj global index I=rgb2gray(im); I=imresize(I,[128,128]);%128*128 P=[];%¨ for i=1:32 for j=1:32 I2=I((i-1)*4+1:i*4,(j-1)*4+1:j*4);%§§1024¨4*4¨ i3=reshape(I2,16,1);%¨§§16*1¨ II=double(i3); P_1=II/255;%[0,1]§§ì¨¨ P=[P,P_1];%16*1024¨ end end T=P;%¨ axes(handles.axes2); if index==1 net=newff(minmax(P),[8,16],{'tansig','logsig'},'trainlm');%§§§ elseif index==2 net=newff(minmax(P),[4,16],{'tansig','logsig'},'trainlm'); elseif index==3 net=newff(minmax(P),[2,16],{'tansig','logsig'},'trainlm'); end %§bp8trainlm§§§{} P270 net.trainParam.goal=0.01;%¨¨§¨¨§§¨¨§§ net.trainParam.epochs=500; %§§ tic net=train(net,P,T);%train§§ toc %tic,toc¨ì§§ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %¨§§§§¨ Y_chonggou=sim(net,P);%sim§§ % Ychonggou_ceshi=[]; for k=1:1024 Ychonggou_ceshi1=reshape(Y_chonggou(:,k),4,4); Ychonggou_ceshi=[Ychonggou_ceshi,Ychonggou_ceshi1]; end YYchonggou_ceshi=[]; for k=1:32 YYchonggou_ceshi1=Ychonggou_ceshi(:,(k-1)*128+1:k*128); YYchonggou_ceshi=[YYchonggou_ceshi;YYchonggou_ceshi1]; end Ychonggou_ce=uint8(YYchonggou_ceshi*255); %YYchonggou_ceshi16*1024¨¨*255[0,1][0255] %¨¨¨¨¨¨ imshow(Ychonggou_ce);title('¨'); % -------------------------------------------------------------------- function uipanel2_SelectionChangeFcn(hObject, eventdata, handles) % hObject handle to uipanel2 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) global index switch get(hObject,'Tag') case 'kj1' index=1; case 'kj2' index=2; case 'kj3' index=3; end % --- Executes on button press in pushbutton7. function pushbutton7_Callback(hObject, eventdata, handles) % hObject handle to pushbutton7 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) global index global I global Ychonggou_ce global Q if index==1 Q = 255; [m,n]=size(I); MSE1 = sum(sum((I-Ychonggou_ce).^2))/(m*n); else if index==2 Q = 255; [m,n]=size(I); MSE1 = sum(sum((I-Ychonggou_ce).^2))/(m*n); else if index==3 Q = 255; [m,n]=size(I); MSE1 = sum(sum((I-Ychonggou_ce).^2))/(m*n); end set(handles.edit4,'string',num2str(10*log10(Q*Q/MSE1))); % --- Executes on button press in pushbutton8. function pushbutton8_Callback(hObject, eventdata, handles) % hObject handle to pushbutton8 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) global index global I global Ychonggou_ce if index==1 A1=sum(sum(I)); B1=abs(sum(sum(Ychonggou_ce-I))); else if index==2 A1=sum(sum(I)); B1=abs(sum(sum(Ychonggou_ce-I))); else if index==3 A1=sum(sum(I)); B1=abs(sum(sum(Ychonggou_ce-I))); end set(handles.edit3,'string',num2str(A1/B1)); function edit3_Callback(hObject, eventdata, handles) % hObject handle to edit3 (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 edit3 as text % str2double(get(hObject,'String')) returns contents of edit3 as a double % --- Executes during object creation, after setting all properties. function edit3_CreateFcn(hObject, eventdata, handles) % hObject handle to edit3 (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 edit4_Callback(hObject, eventdata, handles) % hObject handle to edit4 (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 edit4 as text % str2double(get(hObject,'String')) returns contents of edit4 as a double % --- Executes during object creation, after setting all properties. function edit4_CreateFcn(hObject, eventdata, handles) % hObject handle to edit4 (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 % --- Executes during object creation, after setting all properties. function uipanel2_CreateFcn(hObject, eventdata, handles) % hObject handle to uipanel2 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles empty - handles not created until after all CreateFcns called % --- Executes on button press in kj1. function kj1_Callback(hObject, eventdata, handles) % hObject handle to kj1 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Hint: get(hObject,'Value') returns toggle state of kj1 % --- Executes on button press in kj3. function kj3_Callback(hObject, eventdata, handles) % hObject handle to kj3 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Hint: get(hObject,'Value') returns toggle state of kj3