Thursday, May 18, 2017

Cara Membuat GUI MATLAB Untuk STUDI KOMPARATIF: TAPIS INVERSE, TAPIS WIENER, DEKONVOLUSI BUTA, DAN ALGORITMA LUCY-RICHARDSON








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

% Last Modified by GUIDE v2.5 28-Nov-2016 19:07:29

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

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

% Update handles structure
guidata(hObject, handles);

% UIWAIT makes komparatif_wiener wait for user response (see UIRESUME)
% uiwait(handles.figure1);


% --- Outputs from this function are returned to the command line.
function varargout = komparatif_wiener_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)

[namafile namapath]=uigetfile('*.jpg;*.bmp;*.jpeg;*.png;*.tif;','Pilih Sebuah Citra');
namacitra=[namapath namafile];


if(size(namacitra,3) == 3)
    namacitra = rgb2gray(namacitra);
end


axes(handles.axes1)
imshow(namacitra);

axes(handles.axes3)
imhist(uint8(namacitra),128);

global I
I = getimage(handles.axes1);


% --- 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 I
size(I)
switch get(handles.popupmenu1,'Value')
    case 1
       H = fspecial('average',11);
       kabur = imfilter(I,H,'replicate');
    case 2
       H = fspecial('motion',20,45);
       kabur = imfilter(I,H,'replicate');
    case 3
       H = fspecial('disk',10);
       kabur = imfilter(I,H,'replicate');
    case 4
       H = fspecial('gaussian',[11 11], 10);
       kabur = imfilter(I,H,'replicate');
end

axes(handles.axes1)
imshow(uint8(kabur));
axes(handles.axes3)
imhist(uint8(kabur),128);

global I_kabur
I_kabur = getimage(handles.axes1);

% --- 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 I_kabur
global I
size(I_kabur)

switch get(handles.popupmenu2,'Value')
    case 1
       derau = imnoise(I_kabur,'gaussian', 0,0.01);
    case 2
       derau = imnoise(I_kabur, 'poisson');
    case 3
       derau = imnoise(I_kabur,'salt & pepper',0.01);
    case 4
       derau = imnoise(I_kabur,'speckle',0.01);
end

axes(handles.axes1)
imshow(uint8(derau));
axes(handles.axes3)
imhist(uint8(derau),128);

figure,
subplot(1,3,1), imshow(uint8(I)); title('Citra Semula');
subplot(1,3,2), imshow(uint8(I_kabur));title('Citra Hasil Pengaburan');
subplot(1,3,3), imshow(uint8(derau)); title('Citra Hasil Pengaburan dan Berderau');

global I_derau
I_derau = derau;

% --- Executes on button press in tapis inverse.
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 I_derau
%global I_kabur
global I
n = str2num(get(handles.edit17,'string'));
%kasus 1
H1 = fspecial('average',11);
kabur1 = imfilter(I,H1,'replicate');
derau1 = imnoise(kabur1,'gaussian', 0,0.01);
[M,N]=size(derau1);
[MSE1,im] = tapise_inverse(I,derau1,H1,n,N);
set(handles.edit1, 'String', num2str(MSE1));

%kasus 2
H2 = fspecial('gaussian',[11 11], 10);
kabur2 = imfilter(I,H2,'replicate');
derau2 = imnoise(kabur2, 'poisson');
[MSE2,im] = tapise_inverse(I,derau2,H2,n,N);
set(handles.edit5, 'String', num2str(MSE2));


%kasus 3
H3 = fspecial('disk',10);
kabur3 = imfilter(I,H3,'replicate');
derau3 = imnoise(kabur3,'salt & pepper',0.01);
[MSE3,im] = tapise_inverse(I,derau3,H3,n,N);
set(handles.edit9, 'String', num2str(MSE3));


%kasus 4
H4 = fspecial('motion',20,45);
kabur4 = imfilter(I,H4,'replicate');
derau4 = imnoise(kabur4,'speckle',0.01);
[MSE4,im] = tapise_inverse(I,derau4,H4,n,N);
set(handles.edit13, 'String', num2str(MSE4));


MSE_Inverse = [MSE1 MSE2 MSE3 MSE4];

global MSE_Inverse

% --- 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 = cellstr(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 selection change in popupmenu2.
function popupmenu2_Callback(hObject, eventdata, handles)
% hObject    handle to popupmenu2 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

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


% --- Executes during object creation, after setting all properties.
function popupmenu2_CreateFcn(hObject, eventdata, handles)
% hObject    handle to popupmenu2 (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 pushbutton5.
function pushbutton5_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton5 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

global I
lambda = str2num(get(handles.edit19,'string'));
iterasi = str2num(get(handles.edit20,'string'));
     
%kasus 1
H1 = fspecial('average',11);
kabur1 = imfilter(I,H1,'replicate');
derau1 = imnoise(kabur1,'gaussian', 0,0.01);
[M,N]=size(derau1);
[MSE1,iTerestorasi] = tapise_wiener(I,derau1,H1,lambda,iterasi,N);
set(handles.edit2, 'String', num2str(MSE1));


%kasus 2
H2 = fspecial('gaussian',[11 11], 10);
kabur2 = imfilter(I,H2,'replicate');
derau2 = imnoise(kabur2, 'poisson');
[MSE2,iTerestorasi] = tapise_wiener(I,derau2,H2,lambda,iterasi,N);
set(handles.edit6, 'String', num2str(MSE2));


%kasus 3
H3 = fspecial('disk',10);
kabur3 = imfilter(I,H3,'replicate');
derau3 = imnoise(kabur3,'salt & pepper',0.01);
[MSE3,im] = tapise_wiener(I,derau3,H3,lambda,iterasi,N);
set(handles.edit10, 'String', num2str(MSE3));


%kasus 4
H4 = fspecial('motion',20,45);
kabur4 = imfilter(I,H4,'replicate');
derau4 = imnoise(kabur4,'speckle',0.01);
[MSE4,im] = tapise_wiener(I,derau4,H4,lambda,iterasi,N);
set(handles.edit14, 'String', num2str(MSE4));

MSE_Wiener = [MSE1 MSE2 MSE3 MSE4];

global MSE_Wiener


% --- Executes on button press in pushbutton6.
function pushbutton6_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton6 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

global I
[M,N]=size(I);

iterasi = str2num(get(handles.edit21,'string'));

%kasus 1
H1 = fspecial('average',11);
kabur1 = imfilter(I,H1,'replicate');
derau1 = imnoise(kabur1,'gaussian', 0,0.01);

[J P] = deconvblind(derau1,H1,iterasi);  
error = double(I) - double(J);
MSE1 = sum(sum(error .* error)) / (M * N);
set(handles.edit3, 'String', num2str(MSE1));


%kasus 2
H2 = fspecial('gaussian',[11 11], 10);
kabur2 = imfilter(I,H2,'replicate');
derau2 = imnoise(kabur2, 'poisson');

[J2 P] = deconvblind(derau2,H2,iterasi);  
error = double(I) - double(J2);
MSE2 = sum(sum(error .* error)) / (M * N);
set(handles.edit7, 'String', num2str(MSE2));


%kasus 3
H3 = fspecial('disk',10);
kabur3 = imfilter(I,H3,'replicate');
derau3 = imnoise(kabur3,'salt & pepper',0.01);

[J3 P] = deconvblind(derau3,H3,iterasi);  
error = double(I) - double(J3);
MSE3 = sum(sum(error .* error)) / (M * N);
set(handles.edit11, 'String', num2str(MSE3));

%kasus 4
H4 = fspecial('motion',20,45);
kabur4 = imfilter(I,H4,'replicate');
derau4 = imnoise(kabur4,'speckle',0.01);

[J4 P] = deconvblind(derau4,H4,iterasi);  
error = double(I) - double(J4);
MSE4 = sum(sum(error .* error)) / (M * N);
set(handles.edit15, 'String', num2str(MSE4));

MSE_Buta = [MSE1 MSE2 MSE3 MSE4];

global MSE_Buta


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

iterasi = str2num(get(handles.edit22,'string'));

global I
[M,N]=size(I);

%kasus 1
H1 = fspecial('average',11);
kabur1 = imfilter(I,H1,'replicate');
derau1 = imnoise(kabur1,'gaussian', 0,0.01);

J1 = deconvlucy(derau1,H1,iterasi);
error = double(I) - double(J1);
MSE1 = sum(sum(error .* error)) / (M * N);
set(handles.edit4, 'String', num2str(MSE1));


%kasus 2
H2 = fspecial('gaussian',[11 11], 10);
kabur2 = imfilter(I,H2,'replicate');
derau2 = imnoise(kabur2, 'poisson');

J2 = deconvlucy(derau2,H2,iterasi);  
error = double(I) - double(J2);
MSE2 = sum(sum(error .* error)) / (M * N);
set(handles.edit8, 'String', num2str(MSE2));


%kasus 3
H3 = fspecial('disk',10);
kabur3 = imfilter(I,H3,'replicate');
derau3 = imnoise(kabur3,'salt & pepper',0.01);

J3 = deconvlucy(derau3,H3,iterasi);  
error = double(I) - double(J3);
MSE3 = sum(sum(error .* error)) / (M * N);
set(handles.edit12, 'String', num2str(MSE3));

%kasus 4
H4 = fspecial('motion',20,45);
kabur4 = imfilter(I,H4,'replicate');
derau4 = imnoise(kabur4,'speckle',0.01);

J4 = deconvlucy(derau4,H4,iterasi);  
error = double(I) - double(J4);
MSE4 = sum(sum(error .* error)) / (M * N);
set(handles.edit16, 'String', num2str(MSE4));


MSE_Lucy= [MSE1 MSE2 MSE3 MSE4];

global MSE_Lucy

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



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



function edit2_Callback(hObject, eventdata, handles)
% hObject    handle to edit2 (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 edit2 as text
%        str2double(get(hObject,'String')) returns contents of edit2 as a double


% --- Executes during object creation, after setting all properties.
function edit2_CreateFcn(hObject, eventdata, handles)
% hObject    handle to edit2 (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



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 && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
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 && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end


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

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


% --- Executes during object creation, after setting all properties.
function popupmenu4_CreateFcn(hObject, eventdata, handles)
% hObject    handle to popupmenu4 (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 selection change in popupmenu3.
function popupmenu3_Callback(hObject, eventdata, handles)
% hObject    handle to popupmenu3 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

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


% --- Executes during object creation, after setting all properties.
function popupmenu3_CreateFcn(hObject, eventdata, handles)
% hObject    handle to popupmenu3 (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 pushbutton14.
function pushbutton14_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton14 (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 pushbutton13.
function pushbutton13_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton13 (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 pushbutton12.
function pushbutton12_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton12 (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 pushbutton9.
function pushbutton9_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton9 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)



function edit5_Callback(hObject, eventdata, handles)
% hObject    handle to edit5 (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 edit5 as text
%        str2double(get(hObject,'String')) returns contents of edit5 as a double


% --- Executes during object creation, after setting all properties.
function edit5_CreateFcn(hObject, eventdata, handles)
% hObject    handle to edit5 (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



function edit6_Callback(hObject, eventdata, handles)
% hObject    handle to edit6 (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 edit6 as text
%        str2double(get(hObject,'String')) returns contents of edit6 as a double


% --- Executes during object creation, after setting all properties.
function edit6_CreateFcn(hObject, eventdata, handles)
% hObject    handle to edit6 (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



function edit7_Callback(hObject, eventdata, handles)
% hObject    handle to edit7 (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 edit7 as text
%        str2double(get(hObject,'String')) returns contents of edit7 as a double


% --- Executes during object creation, after setting all properties.
function edit7_CreateFcn(hObject, eventdata, handles)
% hObject    handle to edit7 (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



function edit8_Callback(hObject, eventdata, handles)
% hObject    handle to edit8 (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 edit8 as text
%        str2double(get(hObject,'String')) returns contents of edit8 as a double


% --- Executes during object creation, after setting all properties.
function edit8_CreateFcn(hObject, eventdata, handles)
% hObject    handle to edit8 (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 pushbutton10.
function pushbutton10_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton10 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)



function edit9_Callback(hObject, eventdata, handles)
% hObject    handle to edit9 (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 edit9 as text
%        str2double(get(hObject,'String')) returns contents of edit9 as a double


% --- Executes during object creation, after setting all properties.
function edit9_CreateFcn(hObject, eventdata, handles)
% hObject    handle to edit9 (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



function edit10_Callback(hObject, eventdata, handles)
% hObject    handle to edit10 (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 edit10 as text
%        str2double(get(hObject,'String')) returns contents of edit10 as a double


% --- Executes during object creation, after setting all properties.
function edit10_CreateFcn(hObject, eventdata, handles)
% hObject    handle to edit10 (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



function edit11_Callback(hObject, eventdata, handles)
% hObject    handle to edit11 (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 edit11 as text
%        str2double(get(hObject,'String')) returns contents of edit11 as a double


% --- Executes during object creation, after setting all properties.
function edit11_CreateFcn(hObject, eventdata, handles)
% hObject    handle to edit11 (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



function edit12_Callback(hObject, eventdata, handles)
% hObject    handle to edit12 (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 edit12 as text
%        str2double(get(hObject,'String')) returns contents of edit12 as a double


% --- Executes during object creation, after setting all properties.
function edit12_CreateFcn(hObject, eventdata, handles)
% hObject    handle to edit12 (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 pushbutton11.
function pushbutton11_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton11 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)



function edit13_Callback(hObject, eventdata, handles)
% hObject    handle to edit13 (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 edit13 as text
%        str2double(get(hObject,'String')) returns contents of edit13 as a double


% --- Executes during object creation, after setting all properties.
function edit13_CreateFcn(hObject, eventdata, handles)
% hObject    handle to edit13 (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



function edit14_Callback(hObject, eventdata, handles)
% hObject    handle to edit14 (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 edit14 as text
%        str2double(get(hObject,'String')) returns contents of edit14 as a double


% --- Executes during object creation, after setting all properties.
function edit14_CreateFcn(hObject, eventdata, handles)
% hObject    handle to edit14 (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



function edit15_Callback(hObject, eventdata, handles)
% hObject    handle to edit15 (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 edit15 as text
%        str2double(get(hObject,'String')) returns contents of edit15 as a double


% --- Executes during object creation, after setting all properties.
function edit15_CreateFcn(hObject, eventdata, handles)
% hObject    handle to edit15 (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



function edit16_Callback(hObject, eventdata, handles)
% hObject    handle to edit16 (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 edit16 as text
%        str2double(get(hObject,'String')) returns contents of edit16 as a double


% --- Executes during object creation, after setting all properties.
function edit16_CreateFcn(hObject, eventdata, handles)
% hObject    handle to edit16 (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 pushbutton15.
function pushbutton15_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton15 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

cla(handles.axes1,'reset');
cla(handles.axes2,'reset');
cla(handles.axes3,'reset');
cla(handles.axes4,'reset');
cla(handles.axes5,'reset');

set(handles.edit1, 'String', num2str(0));
set(handles.edit2, 'String', num2str(0));
set(handles.edit3, 'String', num2str(0));
set(handles.edit4, 'String', num2str(0));

set(handles.edit5, 'String', num2str(0));
set(handles.edit6, 'String', num2str(0));
set(handles.edit7, 'String', num2str(0));
set(handles.edit8, 'String', num2str(0));

set(handles.edit9, 'String', num2str(0));
set(handles.edit10, 'String', num2str(0));
set(handles.edit11, 'String', num2str(0));
set(handles.edit12, 'String', num2str(0));

set(handles.edit13, 'String', num2str(0));
set(handles.edit14, 'String', num2str(0));
set(handles.edit15, 'String', num2str(0));
set(handles.edit16, 'String', num2str(0));

set(handles.edit18, 'String', num2str(0));

% --- Executes on button press in pushbutton16.
function pushbutton16_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton16 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)


% --- Executes when selected object is changed in uipanel4.
function uipanel4_SelectionChangeFcn(hObject, eventdata, handles)
% hObject    handle to the selected object in uipanel4
% eventdata  structure with the following fields (see UIBUTTONGROUP)
% EventName: string 'SelectionChanged' (read only)
% OldValue: handle of the previously selected object or empty if none was selected
% NewValue: handle of the currently selected object
% handles    structure with handles and user data (see GUIDATA)

global I_derau
global I
g = I_derau;
[N,M]=size(g);

        switch get(handles.popupmenu1,'Value')
           case 1
              H = fspecial('average',11);
           case 2
              H = fspecial('motion',20,45);
           case 3
              H = fspecial('disk',10);
           case 4
              H = fspecial('gaussian',[11 11], 10);
        end
     
switch get(eventdata.NewValue,'Tag') % Get Tag of selected object.
    case 'radiobutton1'
        display('Tapis Inverse');
        G=fft2(g);
        %n = get(handles.slider2, 'Value');
        %set(handles.edit17, 'String', num2str(n));
        n = str2num(get(handles.edit17,'string'));
     
        B=fft2(H,N,N);
        BF=find(abs(B)<n);
     
        B(BF)=n;
        H=ones(N,N)./B;
       
        I2=G.*H;
        im=abs(ifft2(I2));
     
        axes(handles.axes2)
        imshow(uint8(im));
        axes(handles.axes4)
        imhist(uint8(im),128);
     
        error = double(I) - im;
     
        MSE1 = sum(sum(error .* error)) / (M * N);
        set(handles.edit18, 'String', num2str(MSE1));
     
        figure,
        subplot(1,3,1), imshow(uint8(I)); title('Citra Semula');
        subplot(1,3,2), imshow(uint8(I_derau)); title('Citra Berderau dan Kabur');
        subplot(1,3,3), imshow(uint8(im)); title('Citra Hasil Tapis Inverse');

    case 'radiobutton2'
        display('Tapis Wiener');
        %G=fft2(g);
        B=fft2(H,N,N);
     
        lambda = str2num(get(handles.edit19,'string'));
        iterasi = str2num(get(handles.edit20,'string'));
        K = linspace(0.001,lambda,iterasi);
        vektorError = zeros(1,iterasi);

        for i=1:length(K)
           % Menghasilkan tapis Wiener
           W = conj(B)./(abs(B).^2 + K(i));

           % Menerapkan tapis
           G = fft2(g);
           F = W.*G;
           iTerestorasi = uint8(ifft2(F));

           % Menghitung error
           error = uint8(I) - iTerestorasi;
           vektorError(i) = mean(error(:))^2;
        end

        % Membaca error minimum
        [nilaiErrorMin minErrorPos] = min(vektorError);
        idealK = K(minErrorPos);
        W = conj(B)./(abs(B).^2 + idealK);
        G = fft2(g);
        F = W.*G;
        iTerestorasi = ifft2(F);
     
        axes(handles.axes2)
        imshow(uint8(iTerestorasi));
        axes(handles.axes4)
        imhist(uint8(iTerestorasi),128);
     
        error = double(I) - iTerestorasi;
     
        MSE2 = sum(sum(error .* error)) / (M * N);
        set(handles.edit18, 'String', num2str(MSE2));
     
        figure,
        subplot(1,3,1), imshow(uint8(I)); title('Citra Semula');
        subplot(1,3,2), imshow(uint8(I_derau)); title('Citra Berderau dan Kabur');
        subplot(1,3,3), imshow(uint8(iTerestorasi)); title('Citra Hasil Tapis Wiener');
     
    case 'radiobutton3'
        display('Dekonvolusi Buta');
        iterasi = str2num(get(handles.edit21,'string'));
        [J P] = deconvblind(g,H,iterasi);
     
        axes(handles.axes2)
        imshow(uint8(J));
        axes(handles.axes4)
        imhist(uint8(J),128);
     
        error = double(I) - double(J);
     
        MSE3 = sum(sum(error .* error)) / (M * N);
        set(handles.edit18, 'String', num2str(MSE3));
     
        figure,
        subplot(1,3,1), imshow(uint8(I)); title('Citra Semula');
        subplot(1,3,2), imshow(uint8(I_derau)); title('Citra Berderau dan Kabur');
        subplot(1,3,3), imshow(uint8(J)); title('Citra Hasil Dekonvolusi Buta');
     
     
    case 'radiobutton4'
        display('Algoritma Lucy-Richardson');
     
        iterasi = str2num(get(handles.edit22,'string'));
        lucy = deconvlucy(g,H,iterasi);
     
        axes(handles.axes2)
        imshow(uint8(lucy));
        axes(handles.axes4)
        imhist(uint8(lucy),128);
     
        error = double(I) - double(lucy);
     
        MSE4 = sum(sum(error .* error)) / (M * N);
        set(handles.edit18, 'String', num2str(MSE4));
     
        figure,
        subplot(1,3,1), imshow(uint8(I)); title('Citra Semula');
        subplot(1,3,2), imshow(uint8(I_derau)); title('Citra Berderau dan Kabur');
        subplot(1,3,3), imshow(uint8(lucy)); title('Citra Hasil Lucy-Richardson');
end



function edit17_Callback(hObject, eventdata, handles)
% hObject    handle to edit17 (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 edit17 as text
%        str2double(get(hObject,'String')) returns contents of edit17 as a double


% --- Executes during object creation, after setting all properties.
function edit17_CreateFcn(hObject, eventdata, handles)
% hObject    handle to edit17 (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 slider movement.
function slider2_Callback(hObject, eventdata, handles)
% hObject    handle to slider2 (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,'Value') returns position of slider
%        get(hObject,'Min') and get(hObject,'Max') to determine range of slider


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

% Hint: slider controls usually have a light gray background.
if isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor',[.9 .9 .9]);
end



function edit18_Callback(hObject, eventdata, handles)
% hObject    handle to edit18 (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 edit18 as text
%        str2double(get(hObject,'String')) returns contents of edit18 as a double


% --- Executes during object creation, after setting all properties.
function edit18_CreateFcn(hObject, eventdata, handles)
% hObject    handle to edit18 (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



function edit19_Callback(hObject, eventdata, handles)
% hObject    handle to edit19 (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 edit19 as text
%        str2double(get(hObject,'String')) returns contents of edit19 as a double


% --- Executes during object creation, after setting all properties.
function edit19_CreateFcn(hObject, eventdata, handles)
% hObject    handle to edit19 (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



function edit20_Callback(hObject, eventdata, handles)
% hObject    handle to edit20 (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 edit20 as text
%        str2double(get(hObject,'String')) returns contents of edit20 as a double


% --- Executes during object creation, after setting all properties.
function edit20_CreateFcn(hObject, eventdata, handles)
% hObject    handle to edit20 (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



function edit21_Callback(hObject, eventdata, handles)
% hObject    handle to edit21 (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 edit21 as text
%        str2double(get(hObject,'String')) returns contents of edit21 as a double


% --- Executes during object creation, after setting all properties.
function edit21_CreateFcn(hObject, eventdata, handles)
% hObject    handle to edit21 (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



function edit22_Callback(hObject, eventdata, handles)
% hObject    handle to edit22 (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 edit22 as text
%        str2double(get(hObject,'String')) returns contents of edit22 as a double


% --- Executes during object creation, after setting all properties.
function edit22_CreateFcn(hObject, eventdata, handles)
% hObject    handle to edit22 (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 pushbutton17.
function pushbutton17_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton17 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)


global MSE_Lucy
global MSE_Wiener
global MSE_Buta
global MSE_Inverse

%MSE = [MSE_Inverse MSE_Wiener MSE_Buta MSE_Lucy];

axes(handles.axes5)
plot(MSE_Inverse,'-.r*')
hold on
plot(MSE_Wiener,'--mo')
plot(MSE_Buta,':bs')
plot(MSE_Lucy,'-kd')
hold off
legend('Inverse','Wiener', 'Buta', 'Lucy');
title('Perbandingan MSE dari empat teknik deblurring citra');

figure,
plot(MSE_Inverse,'-.r*')
hold on
plot(MSE_Wiener,'--mo')
plot(MSE_Buta,':bs')
plot(MSE_Lucy,'-kd')
hold off
legend('Inverse','Wiener', 'Buta', 'L-R');
title('Perbandingan MSE dari empat teknik deblurring citra');
xlabel('Nomor Citra');
ylabel('MSE (Error Terkuadrat)');

figure,
MAE_Inverse = 20*log10(sqrt(MSE_Inverse));
MAE_Wiener = 20*log10(sqrt(MSE_Wiener));
PSNR_Buta = 20*log10(sqrt(MSE_Buta));
MAE_Lucy = 20*log10(sqrt(MSE_Lucy));

plot(MAE_Inverse,'-.r*')
hold on
plot(MAE_Wiener,'--mo')
plot(PSNR_Buta,':bs')
plot(MAE_Lucy,'-kd')
hold off
legend('Inverse','Wiener', 'Buta', 'L-R');
title('Perbandingan PSNR dari empat teknik deblurring citra');
xlabel('Nomor Citra');
ylabel('PSNR (dB)');

figure,
MAE_Inverse = MSE_Inverse/(255*255);
MAE_Wiener = MSE_Wiener/(255*255);
MAE_Buta = MSE_Buta/(255*255);
MAE_Lucy = MSE_Lucy/(255*255);

plot(MAE_Inverse,'-.r*')
hold on
plot(MAE_Wiener,'--mo')
plot(MAE_Buta,':bs')
plot(MAE_Lucy,'-kd')
hold off
legend('Inverse','Wiener', 'Buta', 'L-R');
title('Perbandingan MAE dari empat teknik deblurring citra');
xlabel('Nomor Citra');
ylabel('MAE (Error Rerata)');




No comments: