Вы находитесь на странице: 1из 9

Modul Praktikum Jaringan Syaraf Tiruan

11
11 JST Hebb

1.1 Program Aplikasi Komputer JST Hebb


1.1.1.Rancangan Graphical User Interface (GUI)

Gambar 1.1 Rancangan GUI program aplikasi JST Hebb

1.1.2 Daftar Komponen


No Komponen Properti
1 Panel title Training
2 Axes Tag axes1
3 Axes Tag axes2
4 Axes Tag axes6
5 Axes Tag axes7
6 Axes Tag axes8
7 Push button String open image 1
Tag image1_pushbutton
8 Push button String open image 2
Tag image2_pushbutton
9 Push button String open image 3
Tag image3_pushbutton
10 Push button String open image 4
Tag image4_pushbutton
11 Push button String open image 5
Tag image5_pushbutton

igawidagda -lab.fisika komputasi unud 1


Modul Praktikum Jaringan Syaraf Tiruan

No Komponen Properti
12 Static text
String Bobot (w) dan Bias (b) hasil training 1.
13 List boxString kosong
1 Tag Show_listbox .3
. 14 Push button String start training
Tag start_training
15 Panel Title Testing
16 Axes Tag axes3
17 Axes Tag axes4
18 Push button String open testing image
Tag image_testing_pushbutton
19 Push button String Start testing
Tag start_testing_pushbutton
20 Static text String Hasil Testing
Kode Program (source code)
1.1.3.1 Function image1_pushbutton _Callback
function image1_pushbutton_Callback(hObject, eventdata, handles)
[filename,pathname]=uigetfile('*.jpg;*.bmp;*.png','pilih gambar anda');
handles.image_file = strcat(pathname,filename); %"handles.image_file" var image_file
%di set agar bisa diakses dari function
%yang lain
if exist(handles.image_file) % check if image exists
handles.im_original1=imread(handles.image_file); % read in the image
axes(handles.axes1); % will display on axes1
imshow(handles.im_original1);
else % if image doesn_t exist
imshow('file_not_found.jpg') % Display the _Error image_
end
guidata(hObject,handles);

1.1.3.2 Function image2_pushbutton _Callback


function image2_pushbutton_Callback(hObject, eventdata, handles)
[filename,pathname]=uigetfile('*.jpg;*.bmp;*.png','pilih gambar anda');
handles.image_file = strcat(pathname,filename); %"handles.image_file" var image_file
%di set agar bisa diakses dari function
%yang lain
if exist(handles.image_file) % check if image exists
handles.im_original1=imread(handles.image_file); % read in the image
axes(handles.axes2); % will display on axes2
imshow(handles.im_original1);
else % if image doesn_t exist
imshow('file_not_found.jpg') % Display the _Error image_
end
guidata(hObject,handles);

1.1.3.3 Function image3_pushbutton _Callback


function image3_pushbutton_Callback(hObject, eventdata, handles)
[filename,pathname]=uigetfile('*.jpg;*.bmp;*.png','pilih gambar anda');
handles.image_file = strcat(pathname,filename); %"handles.image_file" var image_file
%di set agar bisa diakses dari function
%yang lain
if exist(handles.image_file) % check if image exists
handles.im_original1=imread(handles.image_file); % read in the image

igawidagda -lab.fisika komputasi unud 2


Modul Praktikum Jaringan Syaraf Tiruan
axes(handles.axes6); % will display on axes6
imshow(handles.im_original1);
else % if image doesn_t exist
imshow('file_not_found.jpg') % Display the _Error image_
end
guidata(hObject,handles);

1.1.3.4 Function image4_pushbutton _Callback


function image4_pushbutton_Callback(hObject, eventdata, handles)
[filename,pathname]=uigetfile('*.jpg;*.bmp;*.png','pilih gambar anda');
handles.image_file = strcat(pathname,filename); %"handles.image_file" var image_file
%di set agar bisa diakses dari function
%yang lain
if exist(handles.image_file) % check if image exists
handles.im_original1=imread(handles.image_file); % read in the image
axes(handles.axes7); % will display on axes7
imshow(handles.im_original1);
else % if image doesn_t exist
imshow('file_not_found.jpg') % Display the _Error image_
end
guidata(hObject,handles);

1.1.3.3 Function image5_pushbutton _Callback


function image5_pushbutton_Callback(hObject, eventdata, handles)
[filename,pathname]=uigetfile('*.jpg;*.bmp;*.png','pilih gambar anda');
handles.image_file = strcat(pathname,filename); %"handles.image_file" var image_file
%di set agar bisa diakses dari function
%yang lain
if exist(handles.image_file) % check if image exists
handles.im_original1=imread(handles.image_file); % read in the image
axes(handles.axes8); % will display on axes8
imshow(handles.im_original1);
else % if image doesn_t exist
imshow('file_not_found.jpg') % Display the _Error image_
end
guidata(hObject,handles);

1.1.3.4 Function start_training_pushbutton _Callback


function start_training_pushbutton_Callback(hObject, eventdata, handles)
s1=rgb2gray(handles.im_original1);
s2=rgb2gray(handles.im_original2);
s3=rgb2gray(handles.im_original3);
s4=rgb2gray(handles.im_original4);
s5=rgb2gray(handles.im_original5);

%ubah data menjadi bipolar[1,-1]


jml_baris=size(s1,1);
jml_kolom=size(s1,2);
for i=1:1:jml_baris
for j=1:1:jml_kolom
if s1(i,j)>=200 %putih
s1_temp(i,j)=-1;
else %hitam
s1_temp(i,j)=1;
end
end
end

igawidagda -lab.fisika komputasi unud 3


Modul Praktikum Jaringan Syaraf Tiruan

for i=1:1:jml_baris
for j=1:1:jml_kolom
if s2(i,j)>=200 %putih
s2_temp(i,j)=-1;
else %hitam
s2_temp(i,j)=1;
end
end
end
for i=1:1:jml_baris
for j=1:1:jml_kolom
if s3(i,j)>=200 %putih
s3_temp(i,j)=-1;
else %hitam
s3_temp(i,j)=1;
end
end
end

for i=1:1:jml_baris
for j=1:1:jml_kolom
if s4(i,j)>=200 %putih
s4_temp(i,j)=-1;
else %hitam
s4_temp(i,j)=1;
end
end
end

for i=1:1:jml_baris
for j=1:1:jml_kolom
if s5(i,j)>=200 %putih
s5_temp(i,j)=-1;
else %hitam
s5_temp(i,j)=1;
end
end
end

%jml_pola= 5; % 5 citra
%ubah matrik jadi jadi matrik kovektor
k=0;
for i=1:1:jml_baris
for j=1:1:jml_kolom
k=k+1;
s(1,k)=s1_temp(i,j);
end
end
t1=1; %target untuk citra 1 simpan sbg 3 kolom
%akhir dalam array s
t2=1;
t3=1;
s(1,k+1)=t1;
s(1,k+2)=t2;
s(1,k+3)=t3;

k=0;
for i=1:1:jml_baris
for j=1:1:jml_kolom
k=k+1;
s(2,k)=s2_temp(i,j);
igawidagda -lab.fisika komputasi unud 4
Modul Praktikum Jaringan Syaraf Tiruan
end
end
t1=1;
t2=1; %target untuk citra 2
t3=-1;
s(2,k+1) = t1;
s(2,k+2)= t2;
s(2,k+3)=t3;

k=0;
for i=1:1:jml_baris
for j=1:1:jml_kolom
k=k+1;
s(3,k)=s3_temp(i,j);
end
end
t1=1; %target untuk citra 3
t2=-1;
t3=1;
s(3,k+1) = t1;
s(3,k+2) = t2;
s(3,k+3)= t3;

k=0;
for i=1:1:jml_baris
for j=1:1:jml_kolom
k=k+1;
s(4,k)=s4_temp(i,j);
end
end
t1=1; %target untuk citra 4
t2=-1;
t3=-1
s(4,k+1) = t1;
s(4,k+2) = t2;
s(4,k+3)= t3;

k=0;
for i=1:1:jml_baris
for j=1:1:jml_kolom
k=k+1;
s(5,k)=s5_temp(i,j);
end
end
t1=-1; %target untuk citra 5
t2= 1;
t3= 1;
s(5,k+1) = t1;
s(5,k+2) = t2;
s(5,k+3) = t3;

%inisialisasi bobot (w) dan bias (b)


jml_pola=size(s,1);
jml_input = size(s,2)-3; %-3 krn output/target ada 3
jml_output=3;
%inisialisasi botot w dan bias b
for j=1:1:jml_output
for i=1:1:jml_input
w(i,j)=0;
end
end
for j=1:1:jml_output
igawidagda -lab.fisika komputasi unud 5
Modul Praktikum Jaringan Syaraf Tiruan
b(j)=0;
end

for n=1:1:jml_pola
for i=1:1:jml_input
x(i) = s(n,i); %%x(i) = s(i)
end
for j=1:1:jml_output
t(n,j)=s(n,jml_input+j); %target t
% t(n,2)=s(n,jml_input+2); %target t
y(n,j)=t(n,j); % y1
% y(n,2)=t(n,2); % y2
end

%perbaiki bobot dan bias


for j=1:1:jml_output
for i=1:1:jml_input
w(i,j) = w(i,j) + x(i)*y(n,j); % w_baru =w_lama+x(i)* y
handles.w_final(i,j)=w(i,j);
end
b(j)=b(j)+y(n,j); %b_baru= b_lama + y
handles.b_final(j)=b(j);
end
end

%%tampilkan bobot dan bias hasil pelatihan di command window


for i=1:1:jml_input
for j=1:1:jml_output
disp(strcat('w',num2str(i),num2str(j),' = ',num2str(w(i,j))));
end
end
for j=1:1:jml_output
disp(strcat('b',num2str(j),' = ',num2str(b(j))));
end

%Tampilkan bobot dalam list box


n=1;
for i=1:1:jml_input %index dari array bobot w
for j=1:1:jml_output
k(n)=str2num(strcat(num2str(i),num2str(j)));
w_vek(n)=w(i,j); %ubah w jadi vektor w_vek
n=n+1;
end
end

%tampilkan bobot bj, sbg elemen terakhir listbox

set(handles.show_listbox,'String',strcat('w',num2str(k'),' = ',num2str(w_vek')));
for j=1:1:jml_output
bobot=strcat('b',num2str(j),' = ',num2str(b(j)));
list_box_old=cellstr(get(handles.show_listbox,'String'));
list_box_new= [list_box_old;{bobot}];
set(handles.show_listbox,'String',list_box_new) ;
end

guidata(hObject,handles);

1.1.3.5 Function image_testing_pushbutton _Callback


function image_testing_pushbutton_Callback(hObject, eventdata, handles)
[filename,pathname]=uigetfile('*.jpg;*.bmp;*.png','Select an Image File');
handles.image_file = strcat(pathname,filename); %"handles.image_file" var image_file
igawidagda -lab.fisika komputasi unud 6
Modul Praktikum Jaringan Syaraf Tiruan
%di set agar bisa diakses dari function
%yang lain
if exist(handles.image_file) % check if image exists
handles.im_testing=imread(handles.image_file); % read in the image
axes(handles.axes3); % will display on axes1
imshow(handles.im_testing);
else % if image doesn_t exist
imshow('file_not_found.jpg') % Display the _Error image_
end
guidata(hObject,handles);

1.1.3.6 Function start_testing_pushbutton _Callback


function start_testing_pushbutton_Callback(hObject, eventdata, handles)
s=rgb2gray(handles.im_testing);

%ubah data menjadi bipolar[1,-1]


jml_baris=size(s,1);
jml_kolom=size(s,2);
for i=1:1:jml_baris
for j=1:1:jml_kolom
if s(i,j)>=200 %putih
s_temp(i,j)=-1;
else %hitam
s_temp(i,j)=1;
end
end
end

%ubah matrik citra 2 dimensi s_temp jadi vektor 1 dimensi s


k=0;
for i=1:1:jml_baris
for j=1:1:jml_kolom
k=k+1;
s_vektor(k)=s_temp(i,j);
end
end
jml_input = k;
jml_output =3;
net(1)=0;
net(2)=0;
net(3)=0;
for j=1:1:jml_output
for i=1:1:jml_input
x(i)=s_vektor(i);
net(j)=net(j)+x(i)*handles.w_final(i,j);
end
net(j)=net(j)+handles.b_final(j);
end

axes(handles.axes4);
if net(1)>=0 && net(2)>=0 && net(3)>=0
imshow(handles.im_original1);
else
if net(1)>=0 && net(2)>=0 && net(3)<0
imshow(handles.im_original2);
else
if net(1)>=0 && net(2)<0 && net(3) >=0
imshow(handles.im_original3);
else
if net(1)>=0 && net(2)<0 && net(3) <0

igawidagda -lab.fisika komputasi unud 7


Modul Praktikum Jaringan Syaraf Tiruan
imshow(handles.im_original4);
else
if net(1)<0 && net(2)>=0 && net(3) >=0
imshow(handles.im_original5);
else
imshow(handles.im_original5);

end
end
end
end
end

1.1.4 Hasil Eksekusi (RUN) program


Hasil eksekusi program JST Hebb dapat dilihat dalam Gambar 1.2.

Gambar 1.2 Hasil Eksekusi program JST Hebb

Cara kerja program :


- Buka file citra atau gambar dengan menekan tombol open image 1 sampai
open image 5
- Klik tombol Start Training, setelah menunggu beberapa saat sistem akan
menampilkan bobot (w) dan bias (b) hasil pelatihan list box
- Buka file citra atau gambar dengan menekan tombol open testing image
- Klik tombol Start Testing, selanjutnya akan ditampilkan citra hasil testing yang
cocok dengan citra yang diuji.

1.2 Latihan
1. Buatlah percobaan dengan menggunakan program aplikasi JST Hebb ini dengan
5 buah citra pola huruf untuk proses pelatihan. Selanjutnya ujilah atau testing
sistem dengan citra huruf yang cacat atau mengandung noise.

igawidagda -lab.fisika komputasi unud 8


Modul Praktikum Jaringan Syaraf Tiruan

2. Buatlah percobaan dengan memakai program aplikasi JST Hebb dengan 5 buah
citra wajah untuk proses pelatihan atau training. Kemudian testing system
dengan citra wajah cacat atau mengandung noise

igawidagda -lab.fisika komputasi unud 9

Вам также может понравиться