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

I.

Jaringan Syaraf Tiruan Hebb


a. Rancangan Desain GUI

Gambar 1.1. Rancangan design GUI jaringan syaraf tiruan Hebb.

b. Daftar Komponen

No Komponen Properti
1 Axes1 Tag axes1
XTick Kosong
YTick Kosong
2 Axes2 Tag axes2
XTick Kosong
YTick Kosong
3 Axes3 Tag axes3
XTick Kosong
YTick Kosong
4 Axes4 Tag axes4
XTick Kosong
YTick Kosong
5 Pushbutton1 String open image 1
Tag image1_pushbutton
6 Pushbutton2 String open image 2
Tag Image2_pushbutton
7 Pushbutton3 String Start Training
Tag start_training_pushbutton
8 Pushbutton4 String open testing image
Tag image_testing_pushbutton
9 Pushbutton5 String Start Testing
Tag start_testing_pushbutton
10 Listbox Tag show_listbox
11 Text1 String Hasil Testing
Tag text1
12 Text2 String Bobot (w) dan Bias (b) hasil
Tag text2
training

c. Kode Program
open image 1

function image1_pushbutton_Callback(hObject, eventdata, handles)


% hObject handle to image1_pushbutton (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
[filename,pathname]=uigetfile('*.jpg;*.bmp;*.png','Select an Image File');

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

open image 2

function image2_pushbutton_Callback(hObject, eventdata, handles)


% hObject handle to image2_pushbutton (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)

[filename,pathname]=uigetfile('*.jpg;*.bmp;*.png','Select an Image File');


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_original2=imread(handles.image_file); % read in the image
axes(handles.axes2); % will display on axes1
imshow(handles.im_original2);
else % if image doesn_t exist
imshow('file_not_found.jpg') % Display the _Error image
end
guidata(hObject,handles);

Start Training

function start_training_pushbutton_Callback(hObject, eventdata, handles)


% hObject handle to start_training_pushbutton (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
s1=rgb2gray(handles.im_original1);
s2=rgb2gray(handles.im_original2);

%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

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
%jml_pola= 2; % 2 citra
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 kolom
%akhir dalam array s
s(1,k+1)=t1;
k=0;
for i=1:1:jml_baris
for j=1:1:jml_kolom
k=k+1;
s(2,k)=s2_temp(i,j);
end
end
t2=-1; %target untuk citra 2

s(2,k+1) = t2;

%inisialisasi bobot (w) dan bias (b)


jml_pola=size(s,1);
jml_input = size(s,2)-1;

for i=1:1:jml_input
w(i)=0;
end
b=0;

for n=1:1:jml_pola
for i=1:1:jml_input
x(i) = s(n,i); %%x(i) = s(i)
end
t(n)=s(n,jml_input+1); %target
y(n)=t(n); %s(n,jml_input+1); %% y = target
%perbaiki bobot dan bias
for i=1:1:jml_input
w(i) = w(i) + x(i)*y(n); % w_baru =w_lama+x(i)* y
handles.w_final(i)=w(i);
end
b=b+y(n); %b_baru= b_lama + y
handles.b_final=b;
end
%%tampilkan bobot dan bias hasil pelatihan
for i=1:1:jml_input
disp(strcat('w',num2str(i),' = ',num2str(w(i))));
end
disp(strcat('b = ',num2str(b)));

%Tampilkan bobot dalam list box


for n=1:1:jml_input %index dari array bobot w
i(n)=n;
end
set(handles.show_listbox,'String',strcat('w',num2str(i'),' = ',num2str(w')));
bobot=strcat('b = ',num2str(b));
%tampilkan bobot sbg elemen terakhir listbox
list_box_old=cellstr(get(handles.show_listbox,'String'));
list_box_new= [list_box_old;{bobot}];
set(handles.show_listbox,'String',list_box_new) ;

guidata(hObject,handles);

open testing image

function image_testing_pushbutton_Callback(hObject, eventdata, handles)

% hObject handle to image_testing_pushbutton (see GCBO)

% eventdata reserved - to be defined in a future version of MATLAB

% handles structure with handles and user data (see GUIDATA)

[filename,pathname]=uigetfile('*.jpg;*.bmp;*.png','Select an Image File');

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_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);

Start Testing

function start_testing_pushbutton_Callback(hObject, eventdata, handles)

% hObject handle to start_testing_pushbutton (see GCBO)

% eventdata reserved - to be defined in a future version of MATLAB

% handles structure with handles and user data (see GUIDATA)

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;

net=0;

for i=1:1:jml_input

x(i)=s_vektor(i);

net=net+x(i)*handles.w_final(i);

end

net=net+handles.b_final

axes(handles.axes4);

if net>=0

f=1

imshow(handles.im_original1);

else

f=-1

imshow(handles.im_original2);

end

Show listbox
function show_listbox_Callback(hObject, eventdata, handles)
% hObject handle to show_listbox (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)

% Hints: contents = get(hObject,'String') returns show_listbox contents as


cell array
% contents{get(hObject,'Value')} returns selected item from show_listbox

% --- Executes during object creation, after setting all properties.


function show_listbox_CreateFcn(hObject, eventdata, handles)
% hObject handle to show_listbox (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called

% Hint: listbox controls usually have a white background on Windows.


% See ISPC and COMPUTER.
if ispc
set(hObject,'BackgroundColor','white');
else
set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));
end

d. Hasil Eksekusi (RUN)

Gambar 1.2. Hasil RUN program jaringan syaraf tiruan Hebb


Gambar 1.3 Hasil RUN open image 1

Gambar 1.4 Hasil RUN open image 2


Gambar 1.4 Hasil RUN Start Training menampilkan nilai w dan b

Gambar 1.5 Hasil RUN open testing image


Gambar 1.6 Hasil RUN Start Testing menampilkan hasil testing

TUGAS JARINGAN SYARAF TIRUAN


JARINGAN SYARAF TIRUAN HEBB
Dosen : I Gusti Agung Widagda, S.Si, M.Kom
Nama : I Komang Krisnawan Gapar
NIM : 1208205013

JURUSAN FISIKA
FAKULTAS MATEMATIKA DAN ILMU PENGETAHUAN ALAM
UNIVERSITAS UDAYANA
2014

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