function varargout = MyGUI(varargin)
% MYGUI MATLAB code for MyGUI.fig
% MYGUI, by itself, creates a new MYGUI or raises the existing
% singleton*.
%
% H = MYGUI returns the handle to a new MYGUI or the handle to
% the existing singleton*.
%
% MYGUI('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in MYGUI.M with the given input arguments.
%
% MYGUI('Property','Value',...) creates a new MYGUI or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before MyGUI_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to MyGUI_OpeningFcn via varargin.
%
% *See GUI Options on GUIDE's Tools about. Choose "GUI allows only one
% instance to run (singleton)".
%
% See also: GUIDE, GUIDATA, GUIHANDLES
% Edit the above text to modify the response to help MyGUI
% Last Modified by GUIDE v2.5 22-May-2014 13:11:11
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @MyGUI_OpeningFcn, ...
'gui_OutputFcn', @MyGUI_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 MyGUI is made visible.
function MyGUI_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 MyGUI (see VARARGIN)
% Choose default command line output for MyGUI
handles.output = hObject;
% *** 初始化 *** %
handles.MyImage = [];
handles.MyFFT2 = [];
handles.MoveBlur = [];
handles.ATMBlur = [];
handles.DenoiseMoveBlur = [];
handles.DenoiseATMBlur = [];
% 是否加载图像的标记
handles.LoadedImage = false;
% 是否进行傅里叶变换
handles.Fourier = false;
% 是否被污染
handles.Polluted = 0;
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes MyGUI wait for user response (see UIRESUME)
% uiwait(handles.FIGURE);
% --- Outputs from this function are returned to the command line.
function varargout = MyGUI_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 FIGURE is resized.
function figure_ResizeFcn(hObject, eventdata, handles)
% hObject handle to FIGURE (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 BN_OPEN_IMAGE.
function BN_OPEN_IMAGE_Callback(hObject, eventdata, handles)
% hObject handle to BN_OPEN_IMAGE (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
[fname, pname] = uigetfile({'*.jpg;*.tif;*.png;*.gif;*.bmp;', 'All Image Files';...
'*.*','All Files' }, '选择图片', 'MultiSelect', 'on');
% fname:返回的文件名
% pname:返回的路径名
if fname == 0
return;
end
Image = imread([pname, fname]);
if size(Image, 3)>1
Image = rgb2gray(Image);
end
% 是否加载图像的标记
handles.LoadedImage = false;
% 是否进行傅里叶变换
handles.Fourier = false;
% 是否被污染
handles.Polluted = 0;
% 显示
subplot(1, 1, 1);
imshow(Image);
% 自定义变量:图像
handles.MyImage = Image;
handles.LoadedImage = true;
guidata(hObject, handles);
% --- Executes on button press in BN_SAVE_IMAGE.
function BN_SAVE_IMAGE_Callback(hObject, eventdata, handles)
% hObject handle to BN_SAVE_IMAGE (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
if ~handles.LoadedImage
return;
end
[fname, pname] = uiputfile({'*.bmp', 'Bitmap(*.bmp)'; '*.jpg', 'JPEG(*.jpg)';
'*.gif', 'GIF(*.gif)'; '*.*' , 'All Files (*.*)'}, '保存图片','NewImage');
if fname == 0
return;
end
Origin = [pname, fname(1:end-4), ' - Origin', fname(end-3:end)];
MoveBlur = [pname, fname(1:end-4), ' - MoveBlur', fname(end-3:end)];
ATMBlur = [pname, fname(1:end-4), ' - ATMBlur', fname(end-3:end)];
DenoiseMoveBlur = [pname, fname(1:end-4), ' - DenoiseMoveBlur', fname(end-3:end)];
DenoiseATMBlur = [pname, fname(1:end-4), ' - DenoiseATMBlur', fname(end-3:end)];
imwrite(handles.MyImage, Origin);
if ~isempty(handles.MoveBlur)
MAX = max(max(handles.MoveBlur));
imwrite(uint8(handles.MoveBlur/MAX*255), MoveBlur);
end
if ~isempty(handles.ATMBlur)
MAX = max(max(handles.ATMBlur));
imwrite(uint8(handles.ATMBlur/MAX*255), ATMBlur);
end
if ~isempty(handles.DenoiseMoveBlur)
MAX = max(max(handles.DenoiseMoveBlur));
imwrite(uint8(handles.DenoiseMoveBlur/MAX*255), DenoiseMoveBlur);
end
if ~isempty(handles.DenoiseATMBlur)
MAX = max(max(handles.DenoiseATMBlur));
imwrite(uint8(handles.DenoiseATMBlur/MAX*255), DenoiseATMBlur);
end
% --- Executes on button press in BN_FFT2.
function BN_FFT2_Callback(hObject, eventdata, handles)
% hObject handle to BN_FFT2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
if ~handles.LoadedImage
return;
end
% 自定义变量:频率,频谱
handles.Fourier = true;
handles.MyFFT2 = fft2(handles.MyImage);
subplot(1, 1, 1);
imshow(log(1+abs(fftshift(handles.MyFFT2))), []);
guidata(hObject, handles);
% --- Executes on button press in BN_BLUR_MOVE.
function BN_BLUR_MOVE_Callback(hObject, eventdata, handles)
% hObject handle to BN_BLUR_MOVE (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
if ~handles.LoadedImage
return;
end
if handles.Polluted == 1%图像已被污染
return;
end
if ~handles.Fourier%未进行傅里叶变换
handles.MyFFT2 = fft2(handles.MyImage);
end
[m, n] = size(handles.MyFFT2);
H = zeros(m, n);
handles.Polluted = 1;
% *** 运动模糊参数 *** %
a = 0.1; b = 0.1; T = 1;
for u = 1:m
for v = 1:n
temp = pi*(u*a+v*b);
H(u, v) = T/temp*sin(temp)*exp(-1i*temp);
end
end
handles.Pollution = H;
handles.MyFFT2 = handles.MyFFT2.*handles.Pollution;
Image = ifft2(handles.MyFFT2);
handles.MoveBlur = real(Image);
subplot(1, 2, 1);
imshow(handles.MyImage);
subplot(1, 2, 2);
imshow(handles.MoveBlur, []);
guidata(hObject, handles);
% --- Executes on button press in BN_BLUR_ATM.
function BN_BLUR_ATM_Callback(hObject, eventdata, handles)
% hObject handle to BN_BLUR_ATM (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
if ~handles.LoadedImage
return;
end
if handles.Polluted == 2%图像已被污染
return;
end
if ~handles.Fourier%未进行傅里叶变换
handles.MyFFT2 = fft2(handles.MyImage);
end
[m, n] = size(handles.MyFFT2);
H = zeros(m, n);
handles.Polluted = 2;
% *** 湍流模糊参数 *** %
k = 0.0025;
for u = 1:m
for v = 1:n
H(u, v) = exp(-k*((u-0.5*m)*(u-0.5*m)+(v-0.5*n)*(v-0.5*n))^(5/6));
end
end
handles.Pollution = H;
handles.MyFFT2 = fftshift(handles.MyFFT2).*handles.Pollution;
Image = ifft2(ifftshift(handles.MyFFT2));
handles.ATMBlur = real(Image);
subplot(1, 2, 1);
imshow(handles.MyImage);
subplot(1, 2, 2);
imshow(handles.ATMBlur, []);
guidata(hObject, handles);
% --- E