www.gusucode.com > GUI界面设计范例和ppt资料电信课程设计 > GUI界面设计范例和ppt资料电信课程设计/GUI界面设计范例/电信课程设计/5.compression/image_proc.m

    function varargout = image_proc(varargin)
% IMAGE_PROC M-file for image_proc.fig
%      IMAGE_PROC, by itself, creates a new IMAGE_PROC or raises the existing
%      singleton*.
%
%      H = IMAGE_PROC returns the handle to a new IMAGE_PROC or the handle to
%      the existing singleton*.
%
%      IMAGE_PROC('CALLBACK',hObject,eventData,handles,...) calls the local
%      function named CALLBACK in IMAGE_PROC.M with the given input arguments.
%
%      IMAGE_PROC('Property','Value',...) creates a new IMAGE_PROC or raises the
%      existing singleton*.  Starting from the left, property value pairs are
%      applied to the GUI before image_proc_OpeningFunction gets called.  An
%      unrecognized property name or invalid value makes property application
%      stop.  All inputs are passed to image_proc_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 image_proc

% Last Modified by GUIDE v2.5 22-Nov-2010 18:39:29

% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name',       mfilename, ...
                   'gui_Singleton',  gui_Singleton, ...
                   'gui_OpeningFcn', @image_proc_OpeningFcn, ...
                   'gui_OutputFcn',  @image_proc_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 image_proc is made visible.
function image_proc_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 image_proc (see VARARGIN)

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

% Update handles structure
guidata(hObject, handles);

% UIWAIT makes image_proc wait for user response (see UIRESUME)
% uiwait(handles.figure1);
global img_path                  
global im                 
global choice               
im=0;                        
img_path='';                     
choice=[1 1];  


% --- Outputs from this function are returned to the command line.
function varargout = image_proc_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 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 img_path;
global im;
global choice;
text={'Red Component','Green Component','Blue Component','Gray Image'};

if isempty(img_path)
     msgbox('Select an image first or the image does not exist!');
else
    if choice(1)==4
        rgb2yuv(handles.axes2,im);
      
    else
        show_rgb(handles.axes2,im,choice(1));
    end
      set(handles.text3,'String',text{choice(1)});
end


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


% --- 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 img_path;
global im;
[filename, pathname] = uigetfile( {'*.bmp;*.jpg;*.png;*.jpeg;*.tif;*.gif', 'Image Files (*.bmp, *.jpg, *.png,*.jpeg,*.tif,*.gif)';'*.*', 'All Files (*.*)'}, 'Pick an image');
if isequal(filename,0) || isequal(pathname,0)
return;
end
cla;
axes(handles.axes1);
img_path=[pathname filename];
im=imread(img_path);
imshow(im);
set(handles.edit1,'string',img_path);
 set(handles.text2,'visible','on');
  set(handles.text3,'string','');
 
 if (length(size(im))~=3)
     set(handles.radiobutton1,'enable','off');
     set(handles.radiobutton2,'enable','off');
     set(handles.radiobutton3,'enable','off');
     set(handles.radiobutton4,'enable','off');
     set(handles.pushbutton2,'enable','off');
     set(handles.uipanel2,'title','');
     set(handles.popupmenu1,'enable','off');
 else
      set(handles.radiobutton1,'enable','on');
     set(handles.radiobutton2,'enable','on');
     set(handles.radiobutton3,'enable','on');
     set(handles.radiobutton4,'enable','on');
     set(handles.pushbutton2,'enable','on');
     set(handles.uipanel2,'title','View of RGB componets');
     set(handles.popupmenu1,'enable','on');
 end
 
% --- Executes on button press in radiobutton1.
function radiobutton1_Callback(hObject, eventdata, handles)
% hObject    handle to radiobutton1 (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 radiobutton1
global choice;
choice(1)=1;





% --- Executes on button press in radiobutton2.
function radiobutton2_Callback(hObject, eventdata, handles)
% hObject    handle to radiobutton2 (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 radiobutton2

global choice;
choice(1)=2;





% --- Executes on button press in radiobutton3.
function radiobutton3_Callback(hObject, eventdata, handles)
% hObject    handle to radiobutton3 (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 radiobutton3

global choice;
choice(1)=3;





% --- Executes on button press in radiobutton4.
function radiobutton4_Callback(hObject, eventdata, handles)
% hObject    handle to radiobutton4 (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 radiobutton4

global choice;
choice(1)=4;





% --- Executes on selection change in popupmenu1.
function popupmenu1_Callback(hObject, eventdata, handles)
% hObject    handle to popupmenu1 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: contents = get(hObject,'String') returns popupmenu1 contents as cell array
%        contents{get(hObject,'Value')} returns selected item from popupmenu1


% --- Executes during object creation, after setting all properties.
function popupmenu1_CreateFcn(hObject, eventdata, handles)
% hObject    handle to popupmenu1 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: popupmenu 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


% --- 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 img_path;
global im;
 
 
if isempty(img_path)
     msgbox('Select an image first or the image does not exist!');
else
    model=0;
    histFlag=get(handles.checkbox1,'Value');
    if length(size(im)==3)
        model=get(handles.popupmenu1,'Value');
    end
    
    [im_eq]=equalizations(im,model,histFlag);
    axes(handles.axes2);
    imshow(im_eq);
    set(handles.text3,'string',' Equalized image');
    
end



% --- Executes on button press in checkbox1.
function checkbox1_Callback(hObject, eventdata, handles)
% hObject    handle to checkbox1 (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 checkbox1




% --- 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)

global im;
global im_path;
global flag;
flag=0;
[h,im1]=DCT_compression(handles.figure1,im);
  if flag
axes(handles.axes2);
imshow(im1);
set(handles.text3,'string','DCT compression');
  end