LAMPIRAN A: LISTING PROGRAM
function varargout = FigUtama(varargin) % FIGUTAMA M-file for FigUtama.fig
% FIGUTAMA, by itself, creates a new FIGUTAMA or raises the % existing
% singleton*. %
% H = FIGUTAMA returns the handle to a new FIGUTAMA or the % handle to
% the existing singleton*. %
% FIGUTAMA('CALLBACK',hObject,eventData,handles,...) calls % the local
% function named CALLBACK in FIGUTAMA.M with the given input % arguments.
%
% FIGUTAMA('Property','Value',...) creates a new FIGUTAMA or % raises the
% existing singleton*. Starting from the left, property % value pairs are
% applied to the GUI before FigUtama_OpeningFunction gets % called. An
% unrecognized property name or invalid value makes property % application
% stop. All inputs are passed to FigUtama_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 % Copyright 2002-2003 The MathWorks, Inc.
% Edit the above text to modify the response to help FigUtama % Last Modified by GUIDE v2.5 22-Oct-2010 02:00:19
% Begin initialization code - DO NOT EDIT if nargin == 0 % LAUNCH GUI
fig = openfig(mfilename,'reuse'); % Use system color scheme for figure:
set(fig,'Color',get(0,'defaultUicontrolBackgroundColor')); % Generate a structure of handles to pass to callbacks, and % store it. handles = guihandles(fig); guidata(fig, handles); if nargout > 0 varargout{1} = fig; end
elseif ischar(varargin{1}) % INVOKE NAMED SUBFUNCTION OR CALLBACK try
if (nargout)
[varargout{1:nargout}] = feval(varargin{:}); % FEVAL switchyard
else
feval(varargin{:}); % FEVAL switchyard end
catch
disp(lasterr); end
end
% End initialization code - DO NOT EDIT
% --- Executes just before FigUtama is made visible.
function FigUtama_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 FigUtama (see VARARGIN)
% Choose default command line output for FigUtama handles.output = hObject;
% Update handles structure guidata(hObject, handles);
% UIWAIT makes FigUtama wait for user response (see UIRESUME) % uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line. function varargout = FigUtama_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;
function enode_layar_tersembunyi_Callback(hObject, eventdata, handles)
% hObject handle to enode_layar_tersembunyi (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 enode_layar_tersembunyi as text % str2double(get(hObject,'String')) returns % contents of enode_layar_tersembunyi as a double
% --- Executes during object creation, after setting all % properties.
function enode_layar_tersembunyi_CreateFcn(hObject, eventdata, handles)
% hObject handle to enode_layar_tersembunyi (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 set(hObject,'BackgroundColor','white'); else set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundCol or')); end
function ekonstanta_belajar_Callback(hObject, eventdata, handles) % hObject handle to ekonstanta_belajar (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
% ekonstanta_belajar as text
% str2double(get(hObject,'String')) returns contents of % ekonstanta_belajar as a double
% --- Executes during object creation, after setting all % properties.
function ekonstanta_belajar_CreateFcn(hObject, eventdata, handles) % hObject handle to ekonstanta_belajar (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 set(hObject,'BackgroundColor','white'); else set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundCol or')); 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 set(hObject,'BackgroundColor','white'); else set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundCol or')); end
function ebesar_galat_Callback(hObject, eventdata, handles) % hObject handle to ebesar_galat (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 ebesar_galat as % text
% str2double(get(hObject,'String')) returns contents of % ebesar_galat as a double
% --- Executes during object creation, after setting all % properties.
function ebesar_galat_CreateFcn(hObject, eventdata, handles) % hObject handle to ebesar_galat (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 set(hObject,'BackgroundColor','white'); else set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundCol or')); end
function ebatas_iterasi_Callback(hObject, eventdata, handles) % hObject handle to ebatas_iterasi (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 ebatas_iterasi % as text
% str2double(get(hObject,'String')) returns contents of % ebatas_iterasi as a double
% --- Executes during object creation, after setting all % properties.
function ebatas_iterasi_CreateFcn(hObject, eventdata, handles) % hObject handle to ebatas_iterasi (see GCBO)
% eventdata reserved - to be defined in a future version of % MATLAB
% handles empty - handles not created until after all % CreateFcns called
% See ISPC and COMPUTER. if ispc set(hObject,'BackgroundColor','white'); else set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundCol or')); end
% --- Executes on button press in btn_buka.
function btn_buka_Callback(hObject, eventdata, handles) % hObject handle to btn_buka (see GCBO)
% eventdata reserved - to be defined in a future version of % MATLAB
% handles structure with handles and user data (see GUIDATA) proyek=guidata(gcbo);
[namafile, direktori] = uigetfile({'*.bmp';'*.jpg';'*.gif';'*.*'}, 'Buka Gambar'); if isequal(namafile,0) return; end S = imread([direktori,namafile]); axes(handles.axes1); imshow(S); handles.S = S; set(proyek.text_nama,'string',namafile); set(proyek.text_panjang,'string',size(S,1)); set(proyek.text_lebar,'string',size(S,2)); guidata(hObject, handles);
% --- Executes on button press in btn_latih.
function btn_latih_Callback(hObject, eventdata, handles) % hObject handle to btn_latih (see GCBO)
% eventdata reserved - to be defined in a future version of % MATLAB
% handles structure with handles and user data (see GUIDATA) clc; proyek=guidata(gcbo); load('Target.txt'); for i = 1:100 TrainImages=imread(strcat('Latih','\', (strcat(num2str(i),'.bmp')))); patterns = img_preprocess(TrainImages); out(:,i) = patterns; end S2 = str2double(get(proyek.enode_layar_tersembunyi,'String')); eta = str2double(get(proyek.ekonstanta_belajar,'String')); tol = str2double(get(proyek.ebesar_galat,'String')); iter = str2double(get(proyek.ebatas_iterasi,'String')); p = out(:,1:i); %nilai masukan
t=Target;
t= t'; % nilai keluaran yang diinginkan
%Pembuatan dan Pelatihan Jaringan Saraf Tiruan dengan Propagasi %Balik
[S1,Q] = size(p); [S3,Q] = size(t);
net = newff(minmax(p),[S2 S3],{'logsig' 'logsig' },'traingd'); %inisialisasi jaringan
net.IW{1,1} = net.IW{1,1}*0.05; %inisialisasi bobot masukan %dengan nilai acak (-0.5) - (0.5) net.b{1} = net.b{1}*0.05; %inisialisasi bobot bias
%masukan dengan nilai acak (-0.5) - (0.5) net.LW{2,1} = net.LW{2,1}*0.05; %inisialisasi bobot
%tersembunyi-keluaran dengan %nilai acak (-0.5) - (0.5) net.b{2} = net.b{2}*0.05; %inisialisasi bobot bias
%tersembunyi-keluaran dengan %nilai acak (-0.5) - (0.5) net.performFcn = 'mse';
net.trainParam.goal = tol; %batas nilai MSE/toleransi error net.trainParam.lr = eta; %konstanta pembelajaran
net.trainParam.show = 20; %selang tampilan
net.trainParam.epochs = iter; %maksimum iterasi/epoch [net,tr] = train(net,p,t);
handles.net = net;
assignin('base','net',net);
guidata(hObject, handles);
% --- Executes on button press in btn_keluar.
function btn_keluar_Callback(hObject, eventdata, handles) % hObject handle to btn_keluar (see GCBO)
% eventdata reserved - to be defined in a future version of % MATLAB
% handles structure with handles and user data (see GUIDATA) close;
% --- Executes on button press in btnsimpan.
function btnsimpan_Callback(hObject, eventdata, handles) % hObject handle to btnsimpan (see GCBO)
% eventdata reserved - to be defined in a future version of % MATLAB
% handles structure with handles and user data (see GUIDATA) net = handles.net ;
save bobotakhir net;
guidata(hObject, handles);
% --- Executes on button press in btn_pengenalan.
function btn_pengenalan_Callback(hObject, eventdata, handles) % hObject handle to btn_pengenalan (see GCBO)
% eventdata reserved - to be defined in a future version of % MATLAB
% handles structure with handles and user data (see GUIDATA) clc; load bobotakhir; proyek=guidata(gcbo); S = handles.S; axes(handles.axes1); patterns=img_preprocess(S); patterns=patterns'; [result] = sim(net,patterns); r=round(result); if r==[0; 0; 0; 1]
msgbox('Dikenal Sebagai Tanda Tangan SARI','Hasil Pengujian'); elseif r==[0; 0; 1; 0]
msgbox('Dikenal Sebagai Tanda Tangan SELLI','Hasil Pengujian');
elseif r==[0; 0; 1; 1]
msgbox('Dikenal Sebagai Tanda Tangan UTRI','Hasil Pengujian'); elseif r==[0; 1; 0; 0]
msgbox('Dikenal Sebagai Tanda Tangan EWID','Hasil Pengujian'); elseif r==[0; 1; 0; 1]
msgbox('Dikenal Sebagai Tanda Tangan BENNI','Hasil Pengujian');
elseif r==[0; 1; 1; 0]
msgbox('Dikenal Sebagai Tanda Tangan DESI','Hasil Pengujian'); elseif r==[0; 1; 1; 1]
msgbox('Dikenal Sebagai Tanda Tangan ANDRIANY','Hasil Pengujian');
elseif r==[1; 0; 0; 0]
msgbox('Dikenal Sebagai Tanda Tangan ARNEN','Hasil Pengujian');
elseif r==[1; 0; 0; 1]
msgbox('Dikenal Sebagai Tanda Tangan DEDI','Hasil Pengujian'); elseif r==[1; 0; 1; 0]
msgbox('Dikenal Sebagai Tanda Tangan ELLEN','Hasil Pengujian');
else
msgbox('Tanda Tangan Diluar Database','Hasil Pengujian'); end
guidata(hObject, handles);
function ekolom_Callback(hObject, eventdata, handles) % hObject handle to ekolom (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 ekolom as text % str2double(get(hObject,'String')) returns contents of % ekolom as a double
% --- Executes during object creation, after setting all % properties.
function ekolom_CreateFcn(hObject, eventdata, handles) % hObject handle to ekolom (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 set(hObject,'BackgroundColor','white'); else set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundCol or')); end
function ebaris_Callback(hObject, eventdata, handles) % hObject handle to ebaris (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 ebaris as text % str2double(get(hObject,'String')) returns contents of % ebaris as a double
% --- Executes during object creation, after setting all % properties.
function ebaris_CreateFcn(hObject, eventdata, handles) % hObject handle to ebaris (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 set(hObject,'BackgroundColor','white'); else set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundCol or')); 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 set(hObject,'BackgroundColor','white'); else set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundCol or')); end
function edesired_out2_Callback(hObject, eventdata, handles) % hObject handle to edesired_out2 (see GCBO)
% MATLAB
% handles structure with handles and user data (see GUIDATA) % Hints: get(hObject,'String') returns contents of edesired_out2 % as text
% str2double(get(hObject,'String')) returns contents of % edesired_out2 as a double
% --- Executes during object creation, after setting all % properties.
function edesired_out2_CreateFcn(hObject, eventdata, handles) % hObject handle to edesired_out2 (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 set(hObject,'BackgroundColor','white'); else set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundCol or')); end
% --- Executes on button press in btn_uji_memorisasi.
function btn_uji_memorisasi_Callback(hObject, eventdata, handles) % hObject handle to btn_uji_memorisasi (see GCBO)
% eventdata reserved - to be defined in a future version of % MATLAB
% handles structure with handles and user data (see GUIDATA) clear all; clc; load bobotakhir; load('Target.txt'); for i = 1:100 TestImages=imread(strcat('Latih','\', (strcat(num2str(i),'.bmp')))); patterns = img_preprocess(TestImages); out(:,i) = patterns; end
p = out(:,1:i); %nilai masukan t=Target;
t= t'; % nilai keluaran yang diinginkan [n,N]= size(p); [result] = sim(net,p); r=round(result); benar=0; for i=1:N Hasil=r(:,i); Target=t(:,i); if Hasil==Target
disp(['Data ke-',num2str(i),' = BENAR']);
fprintf('Hasil Keluarannya =\n'); %Hasil keluaran jaringan
fprintf('%9.0f\n',Hasil); fprintf('\n');
else
disp(['Data ke-',num2str(i),' = SALAH']);
fprintf('Hasil Keluarannya =\n'); %Hasil keluaran jaringan fprintf('%9.0f\n',Hasil); fprintf('\n'); end end persen=(benar/N)*100;
disp(['Banyak Data =>' num2str(N)]); disp(['Jumlah Yang Benar =>' num2str(benar)]);
disp(['Persentase Kebenaran Memorisasi =>' num2str(persen) '%']);
% --- Executes on button press in btn_uji_generalisasi.
function btn_uji_generalisasi_Callback(hObject, eventdata, handles)
% hObject handle to btn_uji_generalisasi (see GCBO)
% eventdata reserved - to be defined in a future version of % MATLAB
% handles structure with handles and user data (see GUIDATA) clear all; clc; load bobotakhir; load('Target_uji.txt'); for i = 1:50 TestImages=imread(strcat('Uji','\', (strcat(num2str(i),'.bmp')))); patterns = img_preprocess(TestImages); out(:,i) = patterns; end
p = out(:,1:i); % nilai masukan t=Target_uji;
t= t'; % nilai keluaran yang diinginkan [n,N]= size(p); [result] = sim(net,p); r=round(result); benar=0; for i=1:N Hasil=r(:,i); Target=t(:,i); if Hasil==Target
disp(['Data ke-',num2str(i),' = BENAR']);
fprintf('Hasil Keluarannya =\n'); %Hasil keluaran jaringan
fprintf('%9.0f\n',Hasil); fprintf('\n');
benar=benar+1; else
disp(['Data ke-',num2str(i),' = SALAH']);
fprintf('Hasil Keluarannya =\n'); %Hasil keluaran jaringan fprintf('%9.0f\n',Hasil); fprintf('\n'); end end persen=(benar/N)*100;
disp(['Banyak Data =>' num2str(N)]); disp(['Jumlah Yang Benar =>' num2str(benar)]);
disp(['Persentase Kebenaran Generalisasi =>' num2str(persen) '%']);
% FUNGSI PRAPENGOLAHAN
function img_ekstraksi = img_preprocess(S) Igray = rgb2gray(S);
Ibw = im2bw(Igray,graythresh(Igray)); bw2 = edu_imgcrop(Ibw);
img_ekstraksi = img_ekstrak(bw2);
% FUNGSI MEMOTONG CITRA
function bw2 = edu_imgcrop(Ibw) [y2temp x2temp] = size(Ibw); x1=1;
y1=1; x2=x2temp; y2=y2temp;
% Menentukan batas kiri cntB=1;
while (sum(Ibw(:,cntB))==y2temp) x1=x1+1;
cntB=cntB+1; end
% Menentukan batas kanan cntB=1;
while (sum(Ibw(cntB,:))==x2temp) y1=y1+1;
cntB=cntB+1; end
% Menentukan batas atas cntB=x2temp;
while (sum(Ibw(:,cntB))==y2temp) x2=x2-1;
cntB=cntB-1; end
% Menentukan batas bawah cntB=y2temp;
while (sum(Ibw(cntB,:))==x2temp) y2=y2-1;
cntB=cntB-1; end
% Memotong citra sesuai batas
% FUNGSI MENGUBAH UKURAN CITRA BINER MENJADI 200X300 DAN % MENGUBAHNYA MENJADI MATRIKS 20X30 (EKSTRAKSI CIRI) function lett = img_ekstrak(bw2)
img_resize=imresize(bw2,[200,300]); for cnt=1:20 for cnt2=1:30 Atemp=sum(img_resize((cnt*10-9:cnt*10),(cnt2*10-9:cnt2*10))); if Atemp < 10 Atemp = 1; else Atemp = 0; end lett((cnt-1)*30+cnt2)=sum(Atemp); end end