-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
sabo99
committed
Mar 14, 2021
0 parents
commit bfa7cea
Showing
7 changed files
with
2,154 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
clear all; | ||
close all; | ||
clc; | ||
|
||
fiturTrain = []; % array menyimpan nilai fitur Train sementara | ||
folderTrain = ['D:\Project-Matlab\dataset\train'] folder data latih | ||
|
||
dirFolder = dir((folderTrain)); | ||
|
||
for i = 1:length(dirFolder) | ||
F_name = dirFolder(i).name; | ||
dirFile = dir([folderTrain, '\',F_name,'\*.png']); | ||
hm = length(dirFile); | ||
for j = 1:hm % looping get file inside folder | ||
data(j).file_name = dirFile(j).name; | ||
data(j).file_location = [folderTrain, '\',F_name,'\',data(j).file_name]; | ||
source = imread(data(j).file_location); % Read All Image PNG | ||
|
||
% Parameter GLCM Data Train | ||
layer = source(:,:,1) % layer warna RGB (1 = RED, 2 = GREEN, 3 = BLUE) | ||
layerWarna = edge(layer, 'canny'); % edge detection ('canny', 'sobel', 'prewitt') | ||
source2 = imresize(layer, [100 100]) % resize (128 to 100) | ||
glcm = graycomatrix(source2, 'Offset', [0 1]); | ||
% Jarak Sudut GLCM (D = Jarak tiap Pixel yang dicari) | ||
% 0' [0 D] | ||
% 45' [-D D] | ||
% 90' [-D 0] | ||
% 135' [-D -D] | ||
|
||
|
||
[haralick] = haralickTextureFeatures(glcm) % ekstraksi fitur GLCM Haralick (14 fitur) | ||
group = cell(1000, 1); % TOTAL 1000 data | ||
% label gestur angka pada tangan ==> group(Xawal, Xakhir) = {'X'}; | ||
group(1:250) = {'A'}; % Label Citra A | ||
group(251:500) = {'B'}; % Label Citra B | ||
group(501:750) = {'C'}; % Label Citra C | ||
group(751:1000) = {'D'}; % Label Citra D | ||
|
||
% Klasifikasi Data Train (Proses pengenalan ke komputer) | ||
if(j>= 1 && j <= 250) | ||
data(j).class = 'A'; % Label Citra A | ||
elseif(j>=251 && j <= 500) | ||
data(j).class = 'B'; % Label Citra B | ||
elseif(j>=501 && j <= 750) | ||
data(j).class = 'C'; % Label Citra C | ||
elseif(j>=751 && j <= 1000) | ||
data(j).class = 'D'; % Label Citra D | ||
end | ||
data(j).class = group; | ||
data(j).ciri = haralick; % Save Ekstraksi ciri GLCM Haralick | ||
fiturTrain = [fiturTrain; data(j).ciri]; % Save Hasil Ekstraksi Ciri tiap File Gambar | ||
end | ||
end | ||
|
||
x = struct2table(data); % export data menjadi Tabel | ||
writetable(x, 'EkstraksiCiri.xlsx'); % Export ke Excel | ||
save dbFitur.mat group fiturTrain; % Save Nilai Fitur Train ke dalam dbFitur.mat | ||
|
||
disp('Ekstraksi Berhasil') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
clc; | ||
load dbfitur.mat; % memanggil dbfitur.mat untuk di load | ||
|
||
%MENGAMBIL CIRI GLCM HARALICK PER DATA LATIH KELAS | ||
for i = 1:14 % pengulangan karena terdapat 14 fitur GLCM | ||
latih1_fitur1 = fiturTrain(1:250,i); % mengambil fitur ke-i data latih kelas 1 ada pada range 1 s/d 250 | ||
latih2_fitur1 = fiturTrain(251:500,i); | ||
latih3_fitur1 = fiturTrain(501:750,i); | ||
latih4_fitur1 = fiturTrain(751:1000,i); | ||
latih1_fitur1RataRata = mean(latih1_fitur1); % nilai rata-rata (Average) fitur kelas 1 | ||
latih2_fitur1RataRata = mean(latih2_fitur1); | ||
latih3_fitur1RataRata = mean(latih3_fitur1); | ||
latih4_fitur1RataRata = mean(latih4_fitur1); | ||
x = 1:4; % ada 4 kelas | ||
|
||
% menampilkan chart / grafik, perbedaan nilai fitur tiap kelas | ||
chart = bar(x, [latih1_fitur1RataRata, latih2_fitur1RataRata, latih3_fitur1RataRata, latih4_fitur1RataRata]); | ||
saveas(chart,sprintf('ChartEkstraksi_Fitur/fitur%d.jpg',i)); % menyimpan chart/grafik untuk proses perbandingan fitur terbaik sebagai data latih acuan klasifikasi | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
clc; | ||
akurasiDB=[]; % membuat array untuk menyimpan nilai akurasi | ||
load('SVM_Model/SVMModel.mat'); % memanggil data latih pada SVMModel | ||
fituruji=[]; % Membuat matriks kosong untuk menampung fitur uji | ||
folder_address = ['D:\Project-Matlab\dataset\test']; % menentukan folder yang berisi file data uji | ||
dir_folder = dir((folder_address)); | ||
for i_folder = 1:length(dir_folder); %perulangan untuk memanggil setiap file di dalam folder | ||
folder = dir_folder(i_folder).name; | ||
dir_file = dir([folder_address,'\',folder,'\*.jpg']); %semua file berformat jpg di panggil | ||
hm=length(dir_file); | ||
for i_file = 1:hm %perulangan untuk memanggil semua file berformat jpg | ||
data(i_file).file_name = dir_file(i_file).name; | ||
data(i_file).file_address = [folder_address,'\',folder,'\',data(i_file).file_name]; | ||
source = imread(data(i_file).file_address); | ||
|
||
% ATUR PARAMETER GLCM DATA UJI DISINI | ||
% pastikan parameter sama dengan GLCM data latih | ||
layerWarna1 = source(:,:,2); % atur layer warna RGB (bisa kalian rubah ke ruang warna yang lain) | ||
layerWarna = edge(layerWarna1,'canny'); % edge detection (gunakan canny, sobel dan prewitt untuk pendeteksi tepi) | ||
source2= imresize(layerWarna,[120 120]); % merubah dimensi file gambar menjadi 120x120 piksel | ||
glcm = graycomatrix(source2,'Offset',[0 1]); % atur jarak dan sudut GLCM (0 [0 D] | 45 [-D D] | 90 [-D 0] | 135 [-D -D]), D = jarak | ||
|
||
|
||
[haralick] = haralickTextureFeatures(glcm); % ekstraksi fitur GLCM Haralick (14 fitur) | ||
data(i_file).ciri=haralick; % menyimpan ekstraksi ciri GLCM Haralick ke-i | ||
fituruji=[fituruji; data(i_file).ciri]; % hasil ekstraksi ciri tiap file akan di simpan | ||
end | ||
end | ||
%MENGAMBIL CIRI GLCM HARALICK 14 FITUR DATA UJI | ||
fiturUjiX1 = fituruji(:,1); | ||
fiturUjiX2 = fituruji(:,2); | ||
fiturUjiX3 = fituruji(:,3); | ||
fiturUjiX4 = fituruji(:,4); | ||
fiturUjiX5 = fituruji(:,5); | ||
fiturUjiX6 = fituruji(:,6); | ||
fiturUjiX7 = fituruji(:,7); | ||
fiturUjiX8 = fituruji(:,8); | ||
fiturUjiX9 = fituruji(:,9); | ||
fiturUjiX10 = fituruji(:,10); | ||
fiturUjiX11 = fituruji(:,11); | ||
fiturUjiX12 = fituruji(:,12); | ||
fiturUjiX13 = fituruji(:,13); | ||
fiturUjiX14 = fituruji(:,14); | ||
|
||
% PELUANG KOMBINASI 5 FITUR GLCM HARALICK TERBAIK | ||
% pastikan parameter kombinasi fitur uji sama dengan kombinasi fitur latih (kombinasiFitur.m) | ||
fiturUjiKombinasi = [fiturUjiX2 fiturUjiX8 fiturUjiX9 fiturUjiX11 fiturUjiX12]; | ||
|
||
GroupResult = predict(SVMModel,fiturUjiKombinasi); % simpan hasil tebakan komputer | ||
% HITUNG PERSENTASE AKURASI | ||
groupTruth=cell(9,1); % banyak file data uji | ||
groupTruth(1:3)={'Daun Pepaya'}; % range file 1 s/d 3 adalah kelas Daun Pepaya | ||
groupTruth(4:6)={'Daun Jambu'}; | ||
groupTruth(7:9)={'Daun Tabebuya'}; | ||
cp = classperf(groupTruth,GroupResult); % membandingkan hasil tebakan komputer yang salah & benar | ||
hasilError = cp.ErrorRate; % menghitung nilai error / salah | ||
Akurasi = (1-hasilError)*100; % rumus akurasi | ||
akurasiDB = [Akurasi]; | ||
save akurasi.mat akurasiDB; % menyimpan hasil akurasi ke akurasi.mat |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
% TRAIN SVM | ||
clc; | ||
load dbFiturKombinasi.mat % memanggil dbFiturKombinasi.mat untuk di load (fitur kombinasi terbaik) | ||
fiturLatihValue = fiturlatihKombinasi; % memanggil nilai fiturlatihKombinasi di dbFiturKombinasi.mat | ||
TrainingSet= fiturLatihValue; | ||
GroupTrain=group; % menentukan kelas data latih terdapat 60 data latih | ||
u=unique(GroupTrain); % mengambil karakter unik untuk menentukan kelas-kelasnya | ||
numClasses=length(u); % berapa banyak kelas | ||
|
||
% ATUR PARAMETER MULTI-SVM DISINI | ||
% atur penggunaan kernel (gaussian, linear & polynomial) | ||
% atur penggunaan coding design (onevsall & onevsone) | ||
t = templateSVM('Standardize',true,'KernelFunction','gaussian'); | ||
SVMModel = fitcecoc(TrainingSet,GroupTrain,'Learners',t,'Coding','onevsall'); | ||
|
||
save('SVM_Model/SVMModel.mat'); %menyimpan file hasil latih SVM sebelum di klasifikasikan |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
1. Pastikan data latih dan data uji sudah ada. | ||
2. Pertama, jalankan file "GLCMEkstraksiciri.m" untuk mengekstraksi ciri data latih dan atur parameter GLCM data latih. | ||
3. Buka "Pisah_Hasil_EkstraksiFitur.m" untuk memisahkan nilai fitur antar kelasnya. | ||
4. Lihat grafik fitur antar kelas pada folder "ChartEkstraksi_Fitur". | ||
5. Buka "combineFeature.m" dan tentukan fitur terbaik yang akan digunakan. | ||
6. Buka "SVM_Model_Train.m" dan atur parameter Multi-SVM. | ||
7. Buka "SVM_Classification.m" dan atur parameter GLCM data uji serta kombinasi fitur. | ||
8. Lihat akurasi dan simpulkan. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
clc; | ||
load dbfitur.mat; % memanggil dbfitur.mat untuk di load | ||
|
||
%MENGAMBIL CIRI GLCM HARALICK 14 FITUR DATA LATIH | ||
fiturTrainX1 = fiturTrain(:,1); | ||
fiturTrainX2 = fiturTrain(:,2); | ||
fiturTrainX3 = fiturTrain(:,3); | ||
fiturTrainX4 = fiturTrain(:,4); | ||
fiturTrainX5 = fiturTrain(:,5); | ||
fiturTrainX6 = fiturTrain(:,6); | ||
fiturTrainX7 = fiturTrain(:,7); | ||
fiturTrainX8 = fiturTrain(:,8); | ||
fiturTrainX9 = fiturTrain(:,9); | ||
fiturTrainX10 = fiturTrain(:,10); | ||
fiturTrainX11 = fiturTrain(:,11); | ||
fiturTrainX12 = fiturTrain(:,12); | ||
fiturTrainX13 = fiturTrain(:,13); | ||
fiturTrainX14 = fiturTrain(:,14); | ||
|
||
% PELUANG KOMBINASI 5 FITUR GLCM HARALICK TERBAIK | ||
% lihat gambar grafik untuk menentukan fitur mana yang memiliki hasil rata-rata fitur yang berbeda antar kelasnya | ||
fiturlatihKombinasi = [fiturTrainX2 fiturTrainX7 fiturTrainX8 fiturTrainX9 fiturTrainX10 fiturTrainX11]; | ||
|
||
save dbFiturKombinasi.mat % kombinasi fitur terbaik simpan sebagai matriks |
Oops, something went wrong.