Identifikasi Jenis Bunga Menggunakan Ekstraksi Ciri Orde Satu Dan Algoritma Multisvm


Ekstraksi ciri orde satu merupakan metode pengambilan ciri yang didasarkan pada karakteristik histogram citra. Beberapa parameter ciri orde satu antara lain adalah mean, skewness, variance, kurtosis, dan entropy. Parameter ciri tersebut dapat digunakan sebagai masukan dalam algoritma identifikasi untuk mengenali objek dalam citra. Berikut ini merupakan contoh pemrograman matlab untuk mengidentifikasi jenis bunga menggunakan ekstraksi ciri orde satu dan algoritma multisvm. Citra yang digunakan terdiri dari lima jenis bunga yaitu calendula, iris, leucanthemum maximum, peony, dan rose. Pada data latih digunakan 6 citra pada masing-masing jenis bunga sehingga jumlah total data latih adalah 30 citra. Sedangkan pada data uji digunakan 2 citra pada masing-masing jenis bunga sehingga jumlah total data uji adalah 10 citra (sumber dataset citra: https://www.kaggle.com/olgabelitskaya/flower-color-images).

Beberapa citra pada data latih ditunjukkan pada gambar berikut ini:

Langkah-langkah pemrogramannya adalah:

1. Pelatihan sistem menggunakan ekstraksi ciri orde satu dan identifikasi dengan algoritma multi SVM

clc; clear; close all;

% membaca file citra dalam folder
image_folder = 'data latih';
filenames = dir(fullfile(image_folder, '*.png'));
jumlah_data = numel(filenames);

% menginisialisasi variabel data_latih
data_latih = zeros(jumlah_data,5);

% proses ekstraksi ciri orde satu
for k = 1:jumlah_data
    full_name= fullfile(image_folder, filenames(k).name);
    Img = imread(full_name);
    Img = rgb2gray(Img);
    H = imhist(Img)';
    H = H/sum(H);
    I = [0:255];
    CiriMEAN = I*H';
    CiriENT = -H*log2(H+eps)';
    CiriVAR = (I-CiriMEAN).^2*H';
    CiriSKEW = (I-CiriMEAN).^3*H'/CiriVAR^1.5;
    CiriKURT = (I-CiriMEAN).^4*H'/CiriVAR^2-3;
    data_latih(k,:) = [CiriMEAN,CiriENT,CiriVAR,CiriSKEW,CiriKURT];
end

% penentuan nilai target untuk masing2 jenis bunga
target_latih = zeros(1,jumlah_data);
target_latih(1:6) = 1;    % calendula
target_latih(7:12) = 2;   % iris
target_latih(13:18) = 3;  % leucanthemum maximum
target_latih(19:24) = 4;  % peony
target_latih(25:30) = 5;  % rose

% pelatihan menggunakan algoritma multisvm
output = multisvm(data_latih,target_latih,data_latih);

% menghitung nilai akurasi pelatihan
[n,~] = find(target_latih==output');
jumlah_benar = sum(n);
akurasi = jumlah_benar/jumlah_data*100

% menyimpan variabel data_latih dan target_latih
save data_latih data_latih
save target_latih target_latih

Dari proses pelatihan di atas diperoleh akurasi sebesar 90%

2. Pengujian sistem menggunakan ekstraksi ciri orde satu dan identifikasi dengan algoritma multi SVM

clc; clear; close all;

% membaca file citra dalam folder
image_folder = 'data uji';
filenames = dir(fullfile(image_folder, '*.png'));
jumlah_data = numel(filenames);

% menginisialisasi variabel data_latih
data_uji = zeros(jumlah_data,5);

% proses ekstraksi ciri orde satu
for k = 1:jumlah_data
    full_name= fullfile(image_folder, filenames(k).name);
    Img = imread(full_name);
    Img = rgb2gray(Img);
    H = imhist(Img)';
    H = H/sum(H);
    I = [0:255];
    CiriMEAN = I*H';
    CiriENT = -H*log2(H+eps)';
    CiriVAR = (I-CiriMEAN).^2*H';
    CiriSKEW = (I-CiriMEAN).^3*H'/CiriVAR^1.5;
    CiriKURT = (I-CiriMEAN).^4*H'/CiriVAR^2-3;
    data_uji(k,:) = [CiriMEAN,CiriENT,CiriVAR,CiriSKEW,CiriKURT];
end

% penentuan nilai target untuk masing2 jenis bunga
target_uji = zeros(1,jumlah_data);
target_uji(1:2) = 1;	% calendula
target_uji(3:4) = 2;	% iris
target_uji(5:6) = 3;	% leucanthemum maximum
target_uji(7:8) = 4;	% peony
target_uji(9:10) = 5;	% rose

% load data_latih dan target_latih hasil pelatihan
load data_latih
load target_latih

% pengujian menggunakan algoritma multisvm
output = multisvm(data_latih,target_latih,data_uji);

% menghitung nilai akurasi pengujian
[n,~] = find(target_uji==output');
jumlah_benar = sum(n);
akurasi = jumlah_benar/jumlah_data*100

Dari proses pengujian di atas diperoleh akurasi sebesar 80%

3. Pembuatan Graphical User Interface (GUI)

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

% Last Modified by GUIDE v2.5 30-Oct-2018 08:57:18

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

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

% Update handles structure
guidata(hObject, handles);
movegui(hObject,'center');

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


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

% menampilkan menu browse file
[file, path] = uigetfile('*.png');

% jika ada file yang dipilih maka menjalankan perintah di bawahnya
if ~isequal(file,0)
    % membaca file citra yang dipilih
    Img = imread(fullfile(path, file));
    % menampilkan citra pada axes
    axes(handles.axes1)
    imshow(Img)
    title('Citra RGB')
    % menyimpan variabel Img pada lokasi handles (lokasi penyimpanan MATLAB
    % agar dapat dipanggil pada pushbutton yang lain)
    handles.Img = Img;
    guidata(hObject, handles)
    
    % mereset button2
    set(handles.pushbutton2,'Enable','on')
    set(handles.pushbutton3,'Enable','off')
    set(handles.edit1,'String',[])
    set(handles.text2,'String',[])
    set(handles.uitable1,'Data',[])
    axes(handles.axes2)
    cla reset
    set(gca,'XTick',[])
    set(gca,'YTick',[])
else
    return
end

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

% memanggil variabel Img yang ada pada lokasi handles
Img = handles.Img;
% mengkonversi citra rgb menjadi grayscale
Img = rgb2gray(Img);
% menampilkan citra grayscale pada axes
axes(handles.axes2)
imshow(Img)
title('Citra Grayscale')
% melakukan ekstraksi ciri orde satu pada citra grayscale
H = imhist(Img)';
H = H/sum(H);
I = [0:255];
CiriMEAN = I*H';
CiriENT = -H*log2(H+eps)';
CiriVAR = (I-CiriMEAN).^2*H';
CiriSKEW = (I-CiriMEAN).^3*H'/CiriVAR^1.5;
CiriKURT = (I-CiriMEAN).^4*H'/CiriVAR^2-3;
data_uji = [CiriMEAN,CiriENT,CiriVAR,CiriSKEW,CiriKURT];
% menampilkan hasil ekstraksi ciri orde satupada tabel
data_tabel = cell(5,2);
data_tabel{1,1} = 'Mean';
data_tabel{2,1} = 'Entropy';
data_tabel{3,1} = 'Variance';
data_tabel{4,1} = 'Skewness';
data_tabel{5,1} = 'Kurtosis';
data_tabel{1,2} = num2str(CiriMEAN);
data_tabel{2,2} = num2str(CiriENT);
data_tabel{3,2} = num2str(CiriVAR);
data_tabel{4,2} = num2str(CiriSKEW);
data_tabel{5,2} = num2str(CiriKURT);
set(handles.text2,'String','Hasil Ekstraksi Ciri')
set(handles.uitable1,'Data',data_tabel,'RowName',1:5)

% mereset button2
set(handles.pushbutton3,'Enable','on')
set(handles.edit1,'String',[])
% menyimpan variabel data_uji pada lokasi handles
handles.data_uji = data_uji;
guidata(hObject, handles)

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

% memanggil variabel data_uji yang ada pada lokasi handles
data_uji = handles.data_uji;

% load data_latih dan target_latih hasil pelatihan
load data_latih
load target_latih

% pengujian menggunakan algoritma multisvm
output = multisvm(data_latih,target_latih,data_uji);

% mengubah nilai keluaran menjadi kelas keluaran
switch output
    case 1
        jenis_bunga = 'calendula';
    case 2
        jenis_bunga = 'iris';
    case 3
        jenis_bunga = 'leucanthemum maximum';
    case 4
        jenis_bunga = 'peony';
    case 5
        jenis_bunga = 'rose';
    otherwise
        jenis_bunga = 'tidak dikenali';
end

% menampilkan hasil identifikasi jenis bunga pada edit text
set(handles.edit1,'String',jenis_bunga)

% --- Executes on button press in pushbutton4.
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)

% mereset button2
set(handles.pushbutton2,'Enable','off')
set(handles.pushbutton3,'Enable','off')
set(handles.edit1,'String',[])
set(handles.text2,'String',[])
set(handles.uitable1,'Data',[])
axes(handles.axes1)
cla reset
set(gca,'XTick',[])
set(gca,'YTick',[])
axes(handles.axes2)
cla reset
set(gca,'XTick',[])
set(gca,'YTick',[])


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

Tampilan GUI

1. Hasil identifikasi bunga jenis calendula

2. Hasil identifikasi bunga jenis iris

3. Hasil identifikasi bunga jenis leucanthemum maximum

4. Hasil identifikasi bunga jenis peony

5. Hasil identifikasi bunga jenis rose

Citra dan source code pada pemrograman matlab di atas dapat diperoleh pada halaman berikut ini: Source Code

Posted on October 30, 2018, in Pengenalan Pola, Pengolahan Citra and tagged , , , , , , , , , , , , , , , . Bookmark the permalink. Leave a comment.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: