📄 guidegrade.m
字号:
function varargout = GUIDegrade(varargin)
% GUIDEGRADE M-file for GUIDegrade.fig
% GUIDEGRADE, by itself, creates a new GUIDEGRADE or raises the existing
% singleton*.
%
% H = GUIDEGRADE returns the handle to a new GUIDEGRADE or the handle to
% the existing singleton*.
%
% GUIDEGRADE('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in GUIDEGRADE.M with the given input arguments.
%
% GUIDEGRADE('Property','Value',...) creates a new GUIDEGRADE or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before GUIDegrade_OpeningFunction gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to GUIDegrade_OpeningFcn via varargin.
%
% *See GUI Options on GUIDE's Tools guidegrade. Choose "GUI allows only one
% instance to run (singleton)".
%
% See also: GUIDE, GUIDATA, GUIHANDLES
% Edit the above text to modify the response to help GUIDegrade
% Last Modified by GUIDE v2.5 13-Apr-2005 12:22:12
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @GUIDegrade_OpeningFcn, ...
'gui_OutputFcn', @GUIDegrade_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 GUIDegrade is made visible.
function GUIDegrade_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 GUIDegrade (see VARARGIN)
% Choose default command line output for GUIDegrade
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
% Hiding the axis
set(handles.axisoriginalimg, 'Visible', 'off');
set(handles.axisdegradedimg, 'Visible', 'off');
%Disabling File->LoadDegraded, LoadRestored & Save menu items
set(handles.FileSave, 'Enable', 'off');
set(handles.FileLoadDegraded, 'Enable', 'off');
set(handles.FileLoadRestored, 'Enable', 'off');
%Disabling the Edit menu item
set(handles.EditUndo, 'Enable', 'off');
set(handles.EditRedo, 'Enable', 'off');
set(handles.EditCrop, 'Enable', 'off');
set(handles.EditZoom, 'Enable', 'off');
%Enabling the menu item to load recently degraded image
if evalin('base', 'degimstatus') == 2
set(handles.FileLoadDegraded, 'Enable', 'on');
end
%Enabling the menu item to load recently restored image
if evalin('base', 'resimstatus') == 2
set(handles.FileLoadRestored, 'Enable', 'on');
end
%Setting the Edit->Degrade menu item
set(handles.FilterDegrade, 'Checked', 'on');
%Initialising global variable to 0 to signify that GUI is freshly opened
global comein; comein = 0;
%Setting the close function
set(gcf, 'CloseRequestFcn', 'my_closereq');
% UIWAIT makes GUIDegrade wait for user response (see UIRESUME)
% uiwait(handles.GUIDegrade);
% --- Outputs from this function are returned to the command line.
function varargout = GUIDegrade_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;
% -------------------Start of GUIDegrade ----------------------function File_Callback(hObject, eventdata, handles)% hObject handle to File (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)
% ----------------------
function FileLoadDegraded_Callback(hObject, eventdata, handles)
% hObject handle to FileLoadDegraded (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
set(handles.lblstatus, 'Foregroundcolor', 'Red');
set(handles.lblstatus, 'String', 'Status: Busy');
set(gcf,'pointer','watch');
global comein;
%Loading the degraded image from the base workspace
originalimg = evalin('base', 'degradedimg');
%Displaying on the axis
axes(handles.axisoriginalimg);
imshow(real(originalimg));
%Storing the image in the base workspace
assignin('base','originalimg',originalimg);
%Hiding the frame
set(handles.frmoriginalimg, 'Visible', 'off');
%Setting image status to signify that image is opened
if evalin('base', 'degimstatus') < 1
assignin('base', 'degimstatus', 1);
end
%Initialising comein to 1 to signify that image is opened
comein = 1;
%Enabling the crop menu item
set(handles.EditCrop, 'Enable', 'on');
set(gcf,'pointer','arrow');
set(handles.lblstatus, 'String', 'Status: Ready', 'Foregroundcolor', 'Black');
% ----------------------
function FileLoadRestored_Callback(hObject, eventdata, handles)
% hObject handle to FileLoadRestored (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
set(handles.lblstatus, 'Foregroundcolor', 'Red');
set(handles.lblstatus, 'String', 'Status: Busy');
set(gcf,'pointer','watch');
global comein;
%Loading the degraded image from the base workspace
originalimg = evalin('base', 'restoredimg');
%Displaying on the axis
axes(handles.axisoriginalimg);
imshow(real(originalimg));
%Storing the image in the base workspace
assignin('base','originalimg',originalimg);
%Hiding the frame
set(handles.frmoriginalimg, 'Visible', 'off');
%Setting image status to signify that image is opened
if evalin('base', 'degimstatus') < 1
assignin('base', 'degimstatus', 1);
end
%Initialising comein to 1 to signify that image is opened
comein = 1;
%Enabling the crop menu item
set(handles.EditCrop, 'Enable', 'on');
set(gcf,'pointer','arrow');
set(handles.lblstatus, 'String', 'Status: Ready', 'Foregroundcolor', 'Black');
% ----------------------function FileOpen_Callback(hObject, eventdata, handles)% hObject handle to FileOpen (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)
set(handles.lblstatus, 'Foregroundcolor', 'Red');
set(handles.lblstatus, 'String', 'Status: Busy');
set(gcf,'pointer','watch');global comein;
[filename, pathname] = uigetfile('*.bmp;*.jpg;*.tif;', 'Open input image');
if filename ~= 0
%Displaying the original image
file = [pathname filename];
originalimg = imread(file);
%Converting to double
originalimg = im2double(originalimg);
%Converting the image to grayshade
if size(originalimg, 3) == 3,
originalimg = rgb2gray(originalimg);
end
%Setting axisoriginalimg as the current axis
axes(handles.axisoriginalimg);
imshow(real(originalimg));
%Storing the image in the base workspace
assignin('base','originalimg',originalimg);
%Setting start to 1 signifying that image is opened
assignin('base', 'degimstatus', 1);
%Initialising comein to 1 to signify that image is opened
comein = 1;
%Hiding the frame
set(handles.frmoriginalimg, 'Visible', 'off');
%Enabling the crop menu item
set(handles.EditCrop, 'Enable', 'on');
end
set(gcf,'pointer','arrow');
set(handles.lblstatus, 'String', 'Status: Ready', 'Foregroundcolor', 'Black');
% ----------------------
function FileSave_Callback(hObject, eventdata, handles)% hObject handle to FileSave (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)set(handles.lblstatus, 'Foregroundcolor', 'Red');
set(handles.lblstatus, 'String', 'Status: Busy');
set(gcf,'pointer','watch');
degradedimg = evalin('base', 'degradedimg');
[filename, pathname] = uiputfile('*.bmp', 'Save image');
if filename ~= 0
file = [pathname, filename, '.bmp'];
%Saving the degraded image
imwrite(degradedimg, file, 'bmp');
end
set(gcf,'pointer','arrow');
set(handles.lblstatus, 'String', 'Status: Ready', 'Foregroundcolor', 'Black');
% ----------------------
function FileExit_Callback(hObject, eventdata, handles)% hObject handle to FileExit (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)close;
% ----------------------
function Edit_Callback(hObject, eventdata, handles)
% hObject handle to Edit (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% ----------------------
function EditUndo_Callback(hObject, eventdata, handles)
% hObject handle to EditUndo (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
set(handles.lblstatus, 'Foregroundcolor', 'Red');
set(handles.lblstatus, 'String', 'Status: Busy');
set(gcf,'pointer','watch');
%Reading the old image for undo
originalimgundo = evalin('base', 'originalimgundo');
%Reading the modified image for redo
originalimgredo = evalin('base', 'originalimg');
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -