📄 guicompare.m
字号:
function varargout = GUICompare(varargin)
% GUICOMPARE M-file for GUICompare.fig
% GUICOMPARE, by itself, creates a new GUICOMPARE or raises the existing
% singleton*.
%
% H = GUICOMPARE returns the handle to a new GUICOMPARE or the handle to
% the existing singleton*.
%
% GUICOMPARE('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in GUICOMPARE.M with the given input arguments.
%
% GUICOMPARE('Property','Value',...) creates a new GUICOMPARE or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before GUICompare_OpeningFunction gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to GUICompare_OpeningFcn via varargin.
%
% *See GUI Options on GUIDE's Tools guicompare. Choose "GUI allows only one
% instance to run (singleton)".
%
% See also: GUIDE, GUIDATA, GUIHANDLES
% Edit the above text to modify the response to help GUICompare
% Last Modified by GUIDE v2.5 20-Sep-2004 07:25:06
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @GUICompare_OpeningFcn, ...
'gui_OutputFcn', @GUICompare_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 GUICompare is made visible.
function GUICompare_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 GUICompare (see VARARGIN)
% Choose default command line output for GUICompare
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
%Initialising image status to signify that image is not opened yet
assignin('base', 'cmpdegimstatus', 0);
assignin('base', 'cmpresimstatus', 0);
% Hiding the axis
set(handles.axisoriginalimg, 'Visible', 'off');
set(handles.axisdegradedimg, 'Visible', 'off');
set(handles.axisinverse, 'Visible', 'off');
set(handles.axiswiener, 'Visible', 'off');
set(handles.axislucy, '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');
%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 GUICompare wait for user response (see UIRESUME)
% uiwait(handles.GUICompare);
% --- Outputs from this function are returned to the command line.
function varargout = GUICompare_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 GUICompare ----------------------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)
% ----------------------
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)
% ----------------------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 by eliminating hue and saturation
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', 'cmpdegimstatus', 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)
% ----------------------
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');
%Storing the modified image for redo
assignin('base', 'originalimgredo', originalimgredo);
%Storing the old image as current image
assignin('base', 'originalimg', originalimgundo);
%Displaying the old image
axes(handles.axisoriginalimg);
imshow(real(originalimgundo));
%Enabling the Redo & Disabling Undo menu item
set(handles.EditRedo, 'Enable', 'on');
set(handles.EditUndo, 'Enable', 'off');
set(gcf,'pointer','arrow');
set(handles.lblstatus, 'String', 'Status: Ready', 'Foregroundcolor', 'Black');
% ----------------------
function EditRedo_Callback(hObject, eventdata, handles)
% hObject handle to EditRedo (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 redo
originalimgredo = evalin('base', 'originalimgredo');
%Storing the modified image as current image
assignin('base', 'originalimg', originalimgredo);
%Displaying the old image
axes(handles.axisoriginalimg);
imshow(real(originalimgredo));
%Diabling the Redo & Enabling Undo menu item
set(handles.EditRedo, 'Enable', 'off');
set(handles.EditUndo, 'Enable', 'on');
set(gcf,'pointer','arrow');
set(handles.lblstatus, 'String', 'Status: Ready', 'Foregroundcolor', 'Black');
% ----------------------
function EditCrop_Callback(hObject, eventdata, handles)
% hObject handle to EditCrop (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
axes(handles.axisoriginalimg);
global comein;
%Enter only if image is opened first
if evalin('base', 'cmpdegimstatus') >= 1 & comein >= 1
set(handles.lbleditstatus, 'Visible', 'on');
set(gcf,'pointer','crosshair');
set(handles.lblstatus, 'Foregroundcolor', 'Red');
set(handles.lblstatus, 'String', 'Status: Starting Point');
status = waitforbuttonpress;
if status==0
point1 = get(gca, 'CurrentPoint');
point1 = round(point1(1,1:2)); % extract x1 and y1
set(handles.lblstatus, 'String', 'Status: Ending Point');
status = waitforbuttonpress;
if status==0
point2 = get(gca, 'CurrentPoint');
point2 = round(point2(1,1:2)); % extract x2 and y2
set(handles.lblstatus, 'String', 'Status: Busy');
set(gcf,'pointer','watch');
%Reading the original image
originalimg = evalin('base', 'originalimg');
%Storing the start and the end points irrespective of the
%actual positions on the image
startx = min(point1(2), point2(2));
endx = max(point1(2), point2(2));
starty = min(point1(1), point2(1));
endy = max(point1(1), point2(1));
%Cropping the image
croppedimg = originalimg(startx:endx, starty:endy);
%Backingup the old original image for Undo
assignin('base', 'originalimgundo', originalimg);
%Storing the cropped image
assignin('base', 'originalimg', croppedimg);
imshow(real(croppedimg));
%Enabling the Undo menu item
set(handles.EditUndo, 'Enable', 'on');
end
end
else
uiwait(errordlg('Please open a file first.', 'Error', 'modal'));
end
set(handles.lbleditstatus, 'Visible', 'off');
set(gcf,'pointer','arrow');
set(handles.lblstatus, 'String', 'Status: Ready', 'Foregroundcolor', 'Black');
% ----------------------
function EditZoom_Callback(hObject, eventdata, handles)
% hObject handle to EditZoom (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% ----------------------
function Filter_Callback(hObject, eventdata, handles)% hObject handle to Filter (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)% ----------------------
function FilterDegrade_Callback(hObject, eventdata, handles)% hObject handle to FilterDegrade (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)delete(gcf);
GUIDegrade;% ----------------------
function FilterRestore_Callback(hObject, eventdata, handles)% hObject handle to FilterRestore (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)% ----------------------
function RestoreInverse_Callback(hObject, eventdata, handles)% hObject handle to RestoreInverse (see GCBO)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -