You are on page 1of 25

LISTING PROGRAM

MENU UTAMA
function varargout = menuutama(varargin)
% MENUUTAMA MATLAB code for menuutama.fig
%
MENUUTAMA, by itself, creates a new MENUUTAMA or raises the
existing
%
singleton*.
%
%
H = MENUUTAMA returns the handle to a new MENUUTAMA or the
handle to
%
the existing singleton*.
%
%
MENUUTAMA('CALLBACK',hObject,eventData,handles,...) calls
the local
%
function named CALLBACK in MENUUTAMA.M with the given input
arguments.
%
%
MENUUTAMA('Property','Value',...) creates a new MENUUTAMA
or raises the
%
existing singleton*. Starting from the left, property
value pairs are
%
applied to the GUI before menuutama_OpeningFcn gets called.
An
%
unrecognized property name or invalid value makes property
application
%
stop. All inputs are passed to menuutama_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 menuutama
% Last Modified by GUIDE v2.5 03-Jul-2015 23:49:42
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name',
mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @menuutama_OpeningFcn, ...
'gui_OutputFcn', @menuutama_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 menuutama is made visible.


function menuutama_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 menuutama (see VARARGIN)
hback = axes('unit','normalized','position',[0 0 1 1]);
uistack(hback,'bottom');
% Load backgroound image and display it
[back map]=imread('Kontemporer.jpg');
image(back)
colormap(map)
% Choose default command line output for menuutama
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes menuutama wait for user response (see UIRESUME)
% uiwait(handles.figure1);

% --- Outputs from this function are returned to the command line.
function varargout = menuutama_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)
selection=questdlg(['Apa Anda Yakin
? ' ],['
Keluar
' ],'Ya','Tidak','Ya');
if strcmp(selection,'Tidak')
return;
end

delete(handles.figure1)
% --- Executes on button press in btnidentifikasi.
function btnidentifikasi_Callback(hObject, eventdata, handles)
% hObject
handle to btnidentifikasi (see GCBO)
% eventdata reserved - to be defined in a future version of
MATLAB
% handles
structure with handles and user data (see GUIDATA)
delete(handles.figure1)
identifikasi;
% --- Executes on button press in btninfo.
function btninfo_Callback(hObject, eventdata, handles)
% hObject
handle to btninfo (see GCBO)
% eventdata reserved - to be defined in a future version of
MATLAB
% handles
structure with handles and user data (see GUIDATA)
delete(handles.figure1)
infobatik;
% --- Executes on button press in btnproses.
function btnproses_Callback(hObject, eventdata, handles)
% hObject
handle to btnproses (see GCBO)
% eventdata reserved - to be defined in a future version of
MATLAB
% handles
structure with handles and user data (see GUIDATA)
delete(handles.figure1)
pelatihan;

INFO BATIK
function varargout = infobatik(varargin)
% INFOBATIK MATLAB code for infobatik.fig
%
INFOBATIK, by itself, creates a new INFOBATIK or raises the
existing
%
singleton*.
%
%
H = INFOBATIK returns the handle to a new INFOBATIK or the
handle to
%
the existing singleton*.
%
%
INFOBATIK('CALLBACK',hObject,eventData,handles,...) calls
the local
%
function named CALLBACK in INFOBATIK.M with the given input
arguments.
%
%
INFOBATIK('Property','Value',...) creates a new INFOBATIK
or raises the
%
existing singleton*. Starting from the left, property
value pairs are
%
applied to the GUI before infobatik_OpeningFcn gets called.
An
%
unrecognized property name or invalid value makes property
application

%
stop. All inputs are passed to infobatik_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 infobatik
% Last Modified by GUIDE v2.5 28-Jul-2015 21:07:29
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name',
mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @infobatik_OpeningFcn, ...
'gui_OutputFcn', @infobatik_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 infobatik is made visible.


function infobatik_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 infobatik (see VARARGIN)
% Choose default command line output for infobatik
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes infobatik wait for user response (see UIRESUME)
% uiwait(handles.figure1);

% --- Outputs from this function are returned to the command line.

function varargout = infobatik_OutputFcn(hObject,


handles)
% varargout cell array for returning output args
% hObject
handle to figure
% eventdata reserved - to be defined in a future
MATLAB
% handles
structure with handles and user data

eventdata,
(see VARARGOUT);
version of
(see GUIDATA)

% Get default command line output from handles structure


varargout{1} = handles.output;
im=imread('batik1.jpg','jpg');
handles.im=im;
guidata(hObject,handles);
axes(handles.axes1)
imshow(im);
im=imread('batik2.jpg','jpg');
handles.im=im;
guidata(hObject,handles);
axes(handles.axes2)
imshow(im);
im=imread('batik3.jpg','jpg');
handles.im=im;
guidata(hObject,handles);
axes(handles.axes3)
imshow(im);
im=imread('batik4.jpg','jpg');
handles.im=im;
guidata(hObject,handles);
axes(handles.axes4)
imshow(im);
im=imread('batik5.jpg','jpg');
handles.im=im;
guidata(hObject,handles);
axes(handles.axes5)
imshow(im);
% --- Executes on button press in btnkembali.
function btnkembali_Callback(hObject, eventdata, handles)
% hObject
handle to btnkembali (see GCBO)
% eventdata reserved - to be defined in a future version of
MATLAB
% handles
structure with handles and user data (see GUIDATA)
delete(handles.figure1)
menuutama;

% --- Executes on button press in btnkembali.


function pushbutton4_Callback(hObject, eventdata, handles)
% hObject
handle to btnkembali (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 btnkeluar.


function btnkeluar_Callback(hObject, eventdata, handles)
% hObject
handle to btnkeluar (see GCBO)
% eventdata reserved - to be defined in a future version of
MATLAB
% handles
structure with handles and user data (see GUIDATA)
selection=questdlg(['Apa Anda Yakin
? ' ],['
Keluar
' ],'Ya','Tidak','Ya');
if strcmp(selection,'Tidak')
return;
end
delete(handles.figure1)

PELATIHAN
function varargout = pelatihan(varargin)
% PELATIHAN MATLAB code for pelatihan.fig
%
PELATIHAN, by itself, creates a new PELATIHAN or raises the
existing
%
singleton*.
%
%
H = PELATIHAN returns the handle to a new PELATIHAN or the
handle to
%
the existing singleton*.
%
%
PELATIHAN('CALLBACK',hObject,eventData,handles,...) calls
the local
%
function named CALLBACK in PELATIHAN.M with the given input
arguments.
%
%
PELATIHAN('Property','Value',...) creates a new PELATIHAN
or raises the
%
existing singleton*. Starting from the left, property
value pairs are
%
applied to the GUI before pelatihan_OpeningFcn gets called.
An
%
unrecognized property name or invalid value makes property
application
%
stop. All inputs are passed to pelatihan_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 pelatihan
% Last Modified by GUIDE v2.5 03-Jul-2015 22:53:55
% Begin initialization code - DO NOT EDIT

gui_Singleton = 1;
gui_State = struct('gui_Name',
mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @pelatihan_OpeningFcn, ...
'gui_OutputFcn', @pelatihan_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 pelatihan is made visible.


function pelatihan_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 pelatihan (see VARARGIN)
% Choose default command line output for pelatihan
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes pelatihan wait for user response (see UIRESUME)
% uiwait(handles.figure1);

% --- Outputs from this function are returned to the command line.
function varargout = pelatihan_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 selection change in cbfilter.


function cbfilter_Callback(hObject, eventdata, handles)
% hObject
handle to cbfilter (see GCBO)

% eventdata
MATLAB
% handles

reserved - to be defined in a future version of


structure with handles and user data (see GUIDATA)

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


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

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


properties.
function cbfilter_CreateFcn(hObject, eventdata, handles)
% hObject
handle to cbfilter (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 cblevel.


function cblevel_Callback(hObject, eventdata, handles)
% hObject
handle to cblevel (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 cblevel
contents as cell array
%
contents{get(hObject,'Value')} returns selected item from
cblevel

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


properties.
function cblevel_CreateFcn(hObject, eventdata, handles)
% hObject
handle to cblevel (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'))

end

set(hObject,'BackgroundColor','white');

function txtwaktu_Callback(hObject, eventdata, handles)


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

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


properties.
function txtwaktu_CreateFcn(hObject, eventdata, handles)
% hObject
handle to txtwaktu (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 cbmotif.


function cbmotif_Callback(hObject, eventdata, handles)
% hObject
handle to cbmotif (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 cbmotif
contents as cell array
%
contents{get(hObject,'Value')} returns selected item from
cbmotif

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


properties.
function cbmotif_CreateFcn(hObject, eventdata, handles)
% hObject
handle to cbmotif (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

function txtentropi_Callback(hObject, eventdata, handles)


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

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


properties.
function txtentropi_CreateFcn(hObject, eventdata, handles)
% hObject
handle to txtentropi (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 txtenergi_Callback(hObject, eventdata, handles)


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

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


properties.
function txtenergi_CreateFcn(hObject, eventdata, handles)
% hObject
handle to txtenergi (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 btnambilgambar.


function btnambilgambar_Callback(hObject, eventdata, handles)
% hObject
handle to btnambilgambar (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({'*.jpg';'*.bmp';'*.png';'*.tif';'*
.*'},'Buka Gambar')
if isequal(namafile,0)
return;
end
eval(['cd ''' direktori ''';']);
I=imread(namafile);
set(proyek.figure1,'CurrentAxes',proyek.axes1);
set(imshow(I));
imshow(I);
set(proyek.figure1,'Userdata',I);
set(proyek.axes1,'Userdata',I);
% --- Executes on button press in btnproses.
function btnproses_Callback(hObject, eventdata, handles)
% hObject
handle to btnproses (see GCBO)
% eventdata reserved - to be defined in a future version of
MATLAB
% handles
structure with handles and user data (see GUIDATA)
clc
set(handles.txtentropi, 'String', '')
set(handles.txtenergi, 'String', '')
set(handles.txtwaktu, 'String', '')
proyek = guidata(gcbo);
CitraRgb = get(proyek.axes1, 'Userdata');
CitraRgb = imresize(CitraRgb, [512, 512]);
filter = get(proyek.cbfilter, 'Value')
level = get(proyek.cblevel, 'Value')

%konversi citra menjadi citra terindex


[X,map] = rgb2ind(CitraRgb,32);
%inisialisasi proses filtering simetris
dwtmode('sym');
%jenis filtering
wname = '';
if filter == 1
wname = 'db1'
else
wname = 'db2'
end
%inisialisasi waktu proses
inittime = cputime
%Dekomposisi
[wc,s] = wavedec2(X,level,wname, 'shannon');
%jumlah warna dan ukuran jumlah warna
ncolors = size(map,1);
sz = size(X);
%Ekstrak koefisien level 1
a1 = appcoef2(wc,s,wname,1);
h1 = detcoef2('h',wc,s,1);
v1 = detcoef2('v',wc,s,1);
d1 = detcoef2('d',wc,s,1);
cod_a1
cod_h1
cod_v1
cod_d1

=
=
=
=

wcodemat(a1,ncolors);
wcodemat(h1,ncolors);
wcodemat(v1,ncolors);
wcodemat(d1,ncolors);

cod_a1
cod_h1
cod_v1
cod_d1

=
=
=
=

wkeep(cod_a1,
wkeep(cod_h1,
wkeep(cod_v1,
wkeep(cod_d1,

sz/2);
sz/2);
sz/2);
sz/2);

if level == 1
else
%Ekstrak koefisien level 2
a2 = appcoef2(wc,s,wname,2);
h2 = detcoef2('h',wc,s,2);
v2 = detcoef2('v',wc,s,2);
d2 = detcoef2('d',wc,s,2);
cod_a2
cod_h2
cod_v2
cod_d2

=
=
=
=

wcodemat(a2,ncolors);
wcodemat(h2,ncolors);
wcodemat(v2,ncolors);
wcodemat(d2,ncolors);

cod_a2
cod_h2
cod_v2
cod_d2

end
%Mendapatkan nilai entropi dan energi
entropi = wentropy(wc, 'shannon');
energi = wentropy(wc,'log energy');
strent = mat2str(entropi);
strene = mat2str(energi);
%Menampilkan nilai entropi dan energi
set(proyek.txtentropi, 'String', strent);

=
=
=
=

wkeep(cod_a2,
wkeep(cod_h2,
wkeep(cod_v2,
wkeep(cod_d2,

sz/4);
sz/4);
sz/4);
sz/4);

set(proyek.txtenergi, 'String', strene);


%Rekonstruksi cabang
if level == 2
ra2 = wrcoef2('a',wc,s,wname,2);
rh2 = wrcoef2('h',wc,s,wname,2);
rv2 = wrcoef2('v',wc,s,wname,2);
rd2 = wrcoef2('d',wc,s,wname,2);
cod_ra2
cod_rh2
cod_rv2
cod_rd2

=
=
=
=

wcodemat(ra2,ncolors);
wcodemat(rh2,ncolors);
wcodemat(rv2,ncolors);
wcodemat(rd2,ncolors);

else
ra1
rh1
rv1
rd1

=
=
=
=

wrcoef2('a',wc,s,wname,1);
wrcoef2('h',wc,s,wname,1);
wrcoef2('v',wc,s,wname,1);
wrcoef2('d',wc,s,wname,1);

cod_ra1
cod_rh1
cod_rv1
cod_rd1

=
=
=
=

wcodemat(ra1,ncolors);
wcodemat(rh1,ncolors);
wcodemat(rv1,ncolors);
wcodemat(rd1,ncolors);

end
%Rekonstruksi citra cara 2
XXhat = waverec2(wc,s,wname);
%sprintf('Kesalahan rekonstruksi (menggunakan waverec2) = %g',
max(max(abs(X-XXhat))))
%Implementasi threshold dengan nilai ambang = 20
thr = 20;
[X_comp,wc_comp,s_comp,perf0,perfL2] =
wdencmp('gbl',wc,s,wname,2,thr,'h',1);
%Thresholding spasial
thr_h = [21 17];
% horizontal threshold.
thr_d = [23 19];
% diagonal threshold.
thr_v = [21 17];
% vertical threshold.
thr = [thr_h; thr_d; thr_v];
[X_comp,wc_comp,s_comp,perf0,perfL2] =
wdencmp('lvd',X,wname,2,thr,'h');

%Mengembalikan setting awal


dwtmode('zpd');
set(proyek.txtwaktu, 'String', cputime-inittime);
% --- 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
clc

structure with handles and user data (see GUIDATA)

motif = get(handles.cbmotif, 'Value');


strmotif = get(handles.cbmotif, 'String');
if motif == 1
selection=questdlg(['Anda belum memilih motif'],
['Informasi' ],'Ya','Ya');
if strcmp(selection,'Ya')
return;
end
delete(handles.figure1)
else
if exist('trainingdata.mat', 'file')
cell = struct2cell(load('trainingdata', 'train',
'classtrain'));
train = cell{1};
classtrain = cell{2};
else
train = [];
classtrain = [];
end
entropi = str2num(get(handles.txtentropi, 'String'));
energi = str2num(get(handles.txtenergi, 'String'));
classtrain = [classtrain; motif]
train = [train; entropi energi]
save('trainingdata', 'train', 'classtrain');
end
% --- Executes on button press in btnbersih.
function btnbersih_Callback(hObject, eventdata, handles)
% hObject
handle to btnbersih (see GCBO)
% eventdata reserved - to be defined in a future version of
MATLAB
% handles
structure with handles and user data (see GUIDATA)
clc
set(handles.txtentropi, 'String', '0')
set(handles.txtenergi, 'String', '0')
set(handles.txtwaktu, 'String', '0')
guidata(hObject, handles);
% --- Executes on button press in btnkembali.
function btnkembali_Callback(hObject, eventdata, handles)
% hObject
handle to btnkembali (see GCBO)
% eventdata reserved - to be defined in a future version of
MATLAB
% handles
structure with handles and user data (see GUIDATA)
delete(handles.figure1)
menuutama;
% --- Executes on button press in btnkeluar.

function btnkeluar_Callback(hObject, eventdata, handles)


% hObject
handle to btnkeluar (see GCBO)
% eventdata reserved - to be defined in a future version of
MATLAB
% handles
structure with handles and user data (see GUIDATA)
selection=questdlg(['Apa Anda Yakin
? ' ],['
Keluar
' ],'Ya','Tidak','Ya');
if strcmp(selection,'Tidak')
return;
end
delete(handles.figure1)

PROSES IDENTIFIKASI
function varargout = identifikasi(varargin)
% IDENTIFIKASI MATLAB code for identifikasi.fig
%
IDENTIFIKASI, by itself, creates a new IDENTIFIKASI or
raises the existing
%
singleton*.
%
%
H = IDENTIFIKASI returns the handle to a new IDENTIFIKASI
or the handle to
%
the existing singleton*.
%
%
IDENTIFIKASI('CALLBACK',hObject,eventData,handles,...)
calls the local
%
function named CALLBACK in IDENTIFIKASI.M with the given
input arguments.
%
%
IDENTIFIKASI('Property','Value',...) creates a new
IDENTIFIKASI or raises the
%
existing singleton*. Starting from the left, property
value pairs are
%
applied to the GUI before identifikasi_OpeningFcn gets
called. An
%
unrecognized property name or invalid value makes property
application
%
stop. All inputs are passed to identifikasi_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 identifikasi
% Last Modified by GUIDE v2.5 03-Jul-2015 23:14:46
% Begin initialization code - DO NOT
gui_Singleton = 1;
gui_State = struct('gui_Name',
'gui_Singleton',
'gui_OpeningFcn',

EDIT
mfilename, ...
gui_Singleton, ...
@identifikasi_OpeningFcn, ...

'gui_OutputFcn', @identifikasi_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 identifikasi is made visible.


function identifikasi_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 identifikasi (see VARARGIN)
% Choose default command line output for identifikasi
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes identifikasi wait for user response (see UIRESUME)
% uiwait(handles.figure1);

% --- Outputs from this function are returned to the command line.
function varargout = identifikasi_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 selection change in cbFilter.


function cbFilter_Callback(hObject, eventdata, handles)
% hObject
handle to cbFilter (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


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

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


properties.
function cbFilter_CreateFcn(hObject, eventdata, handles)
% hObject
handle to cbFilter (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 cbLevel.


function cbLevel_Callback(hObject, eventdata, handles)
% hObject
handle to cbLevel (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 cbLevel
contents as cell array
%
contents{get(hObject,'Value')} returns selected item from
cbLevel

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


properties.
function cbLevel_CreateFcn(hObject, eventdata, handles)
% hObject
handle to cbLevel (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
function C = doSom(data, proto, protoClass, UNIT)
% addpath('somtoolbox');

if nargin < 4
classLabel = unique(protoClass);
nClass
= length(classLabel);
UNIT = nClass; % # of SOM units
end
if size(data,2) ~= size(proto,2)
error('Dimension of data vectors and prototype vectors do not
match.');
end
if size(proto,1) ~= size(protoClass,1)
error('Row # of prototypes and prototype class vector do not
match.');
end
%%%% Training
%sMap = som_randinit(proto);
% init randomly
%sMap = som_seqtrain(sMap, proto); % sequential train
sMap = som_make(proto, 'munits', UNIT); % equals to randinit and
seqtrain
% labeling proto class to SOM units (make SOM supervised)
protoSom = som_data_struct(proto,'labels',num2str(protoClass));
sMap = som_autolabel(sMap, protoSom);
% plot SOM space
%som_grid(sMap, 'Label', sMap.labels, 'LabelSize', 30);
%%%%% Testing
[Bmus, Qerrors] = som_bmus(sMap, data) % find best matching units
% labeling
%sMap.labels
dataClassified = sMap.labels(Bmus);
for i=1:length(dataClassified)
if isempty(dataClassified{i}), dataClassified{i} = '1', end;
end
C = cellfun(@str2num, dataClassified);

function txtwaktu_Callback(hObject, eventdata, handles)


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

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


properties.
function txtwaktu_CreateFcn(hObject, eventdata, handles)
% hObject
handle to txtwaktu (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 txtkelas_Callback(hObject, eventdata, handles)


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

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


properties.
function txtkelas_CreateFcn(hObject, eventdata, handles)
% hObject
handle to txtkelas (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 txtentropi_Callback(hObject, eventdata, handles)


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

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


properties.
function txtentropi_CreateFcn(hObject, eventdata, handles)
% hObject
handle to txtentropi (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 txtenergi_Callback(hObject, eventdata, handles)


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

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


properties.
function txtenergi_CreateFcn(hObject, eventdata, handles)
% hObject
handle to txtenergi (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 btnproses.


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

set(handles.txtentropi, 'String', '')


set(handles.txtenergi, 'String', '')
set(handles.txtwaktu, 'String', '')
set(handles.txtkelas, 'String', '')
train = [];
classtrain = [];
if exist('trainingdata.mat', 'file')
cell = struct2cell(load('trainingdata', 'train',
'classtrain'));
train = cell{1};
classtrain = cell{2};
[row, col] = size(train);
if row == 0 && col == 0
selection=questdlg(['Data Training masih kosong' ],[' Data
Training ' ],'OK','OK');
return
delete(handles.figure1)
end
end
proyek = guidata(gcbo);
CitraRgb = get(proyek.axes1, 'Userdata');
CitraRgb = imresize(CitraRgb, [512, 512]);
filter = get(proyek.cbFilter, 'Value');
level = get(proyek.cbLevel, 'Value');
%konversi citra menjadi citra terindex
[X,map] = rgb2ind(CitraRgb,32);
%inisialisasi proses filtering simetris
dwtmode('sym');
%jenis filtering
wname = '';
if filter == 1
wname = 'db1'
else
wname = 'db2'
end
%inisialisasi waktu proses
inittime = cputime
t = wtree(X,level,wname);
plot(t)
hold on
%Dekomposisi
[wc,s] = wavedec2(X,level,wname, 'shannon');
%jumlah warna dan ukuran jumlah warna
ncolors = size(map,1);

sz = size(X);
%figure(2)
%Ekstrak koefisien level 1
a1 = appcoef2(wc,s,wname,1);
h1 = detcoef2('h',wc,s,1);
v1 = detcoef2('v',wc,s,1);
d1 = detcoef2('d',wc,s,1);
cod_a1
cod_h1
cod_v1
cod_d1

=
=
=
=

wcodemat(a1,ncolors);
wcodemat(h1,ncolors);
wcodemat(v1,ncolors);
wcodemat(d1,ncolors);

cod_a1
cod_h1
cod_v1
cod_d1

=
=
=
=

wkeep(cod_a1,
wkeep(cod_h1,
wkeep(cod_v1,
wkeep(cod_d1,

sz/2);
sz/2);
sz/2);
sz/2);

if level == 1

else

%Ekstrak koefisien level 2


a2 = appcoef2(wc,s,wname,2);
h2 = detcoef2('h',wc,s,2);
v2 = detcoef2('v',wc,s,2);
d2 = detcoef2('d',wc,s,2);
cod_a2
cod_h2
cod_v2
cod_d2

=
=
=
=

wcodemat(a2,ncolors);
wcodemat(h2,ncolors);
wcodemat(v2,ncolors);
wcodemat(d2,ncolors);

cod_a2
cod_h2
cod_v2
cod_d2

end
%Mendapatkan nilai entropi dan energi
entropi = wentropy(wc, 'shannon');
energi = wentropy(wc,'log energy');
strent = mat2str(entropi);
strene = mat2str(energi);
%Menampilkan nilai entropi dan energi
set(proyek.txtentropi, 'String', strent);
set(proyek.txtenergi, 'String', strene);
%Rekonstruksi cabang
if level == 2
ra2 = wrcoef2('a',wc,s,wname,2);
rh2 = wrcoef2('h',wc,s,wname,2);
rv2 = wrcoef2('v',wc,s,wname,2);
rd2 = wrcoef2('d',wc,s,wname,2);
cod_ra2
cod_rh2
cod_rv2
cod_rd2
else

=
=
=
=

wcodemat(ra2,ncolors);
wcodemat(rh2,ncolors);
wcodemat(rv2,ncolors);
wcodemat(rd2,ncolors);

=
=
=
=

wkeep(cod_a2,
wkeep(cod_h2,
wkeep(cod_v2,
wkeep(cod_d2,

sz/4);
sz/4);
sz/4);
sz/4);

ra1
rh1
rv1
rd1

=
=
=
=

wrcoef2('a',wc,s,wname,1);
wrcoef2('h',wc,s,wname,1);
wrcoef2('v',wc,s,wname,1);
wrcoef2('d',wc,s,wname,1);

cod_ra1
cod_rh1
cod_rv1
cod_rd1

=
=
=
=

wcodemat(ra1,ncolors);
wcodemat(rh1,ncolors);
wcodemat(rv1,ncolors);
wcodemat(rd1,ncolors);

end
%Rekonstruksi citra cara 2
XXhat = waverec2(wc,s,wname);
%sprintf('Kesalahan rekonstruksi (menggunakan waverec2) = %g',
max(max(abs(X-XXhat))))
%Implementasi threshold dengan nilai ambang = 20
thr = 20;
[X_comp,wc_comp,s_comp,perf0,perfL2] =
wdencmp('gbl',wc,s,wname,2,thr,'h',1);
%Thresholding spasial
thr_h = [21 17];
% horizontal threshold.
thr_d = [23 19];
% diagonal threshold.
thr_v = [21 17];
% vertical threshold.
thr = [thr_h; thr_d; thr_v];
[X_comp,wc_comp,s_comp,perf0,perfL2] =
wdencmp('lvd',X,wname,2,thr,'h');
%Mengembalikan setting awal
dwtmode('zpd');
set(proyek.txtwaktu, 'String', cputime-inittime);
entropi = str2num(get(handles.txtentropi, 'String'));
energi = str2num(get(handles.txtenergi, 'String'));
proto = train
data = [entropi energi];
protoClass = classtrain
% main
dataClass = doSom(data, proto, protoClass, 8)
kelas = {'Tidak diketahui'; 'Ron Mbako'; 'Godong Cilik'; 'Sekar
Mentari'; 'Mbako Sakbayat'; 'Mbako Sakwit';}
set(handles.txtkelas, 'String', kelas{dataClass})
% plot proto
classLabel = unique(protoClass);
nClass
= length(classLabel);
plotLabel = {'r*', 'g*', 'b*'};
for i=1:nClass
A = proto(protoClass == classLabel(i), :);
plot(A(:, 1), A(:, 2), plotLabel{i});

hold on;
end
% plot data
plotLabel = {'ro', 'go', 'bo'};
for i=1:nClass
A = data(dataClass == classLabel(i), :);
plot(A(:, 1), A(:, 2), plotLabel{i});
hold on;
end
legend('1: proto','2: proto', '3: proto', '1: data', '2: data',
'3: data');
title('Self-organizing Map');

% --- Executes on button press in btnbersih.


function btnbersih_Callback(hObject, eventdata, handles)
% hObject
handle to btnbersih (see GCBO)
% eventdata reserved - to be defined in a future version of
MATLAB
% handles
structure with handles and user data (see GUIDATA)
clc
set(handles.txtentropi, 'String', '0')
set(handles.txtenergi, 'String', '0')
set(handles.txtwaktu, 'String', '0')
guidata(hObject, handles);
% --- Executes on button press in btnkembali.
function btnkembali_Callback(hObject, eventdata, handles)
% hObject
handle to btnkembali (see GCBO)
% eventdata reserved - to be defined in a future version of
MATLAB
% handles
structure with handles and user data (see GUIDATA)
delete(handles.figure1)
menuutama;
% --- Executes on button press in btnkeluar.
function btnkeluar_Callback(hObject, eventdata, handles)
% hObject
handle to btnkeluar (see GCBO)
% eventdata reserved - to be defined in a future version of
MATLAB
% handles
structure with handles and user data (see GUIDATA)
selection=questdlg(['Apa Anda Yakin
? ' ],['
Keluar
' ],'Ya','Tidak','Ya');
if strcmp(selection,'Tidak')
return;
end
delete(handles.figure1)
% --- Executes on button press in btnambilgambar.
function btnambilgambar_Callback(hObject, eventdata, handles)
% hObject
handle to btnambilgambar (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({'*.jpg';'*.bmp';'*.png';'*.tif';'*
.*'},'Buka Gambar')
if isequal(namafile,0)
return;
end
eval(['cd ''' direktori ''';']);
I=imread(namafile);
set(proyek.figure1,'CurrentAxes',proyek.axes1);
set(imshow(I));
imshow(I);
set(proyek.figure1,'Userdata',I);
set(proyek.axes1,'Userdata',I);

You might also like