-
Notifications
You must be signed in to change notification settings - Fork 0
/
Main_program.m
152 lines (120 loc) · 5.65 KB
/
Main_program.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
clear all
close all
clc
load('GLCM_Features.mat')
load('Wavelet_Features.mat')
addpath('./Feature Extraction/');
%% Test
test_data = readtable("Outex-TC-00010/000/test.txt");
num_correct_combo = 0; num_correct_GLCM = 0; num_correct_Wavelet = 0; num_correct_Wavelet2 = 0; num_correct_Wavelet3 = 0; num_correct_combo3 = 0;
correct_per_class = zeros(4, 24);
% Test image names
data_text = test_data.Var1;
% Test image class labels
data_class = test_data.Var2;
% Predicted labels of test images
outputs = data_class;
for q = 1 : numel(data_text)
if mod(q, 384) == 0
disp([num2str(q / 38.4) '%'])
end
% Original test image
name = strcat('Outex-TC-00010/images/',cell2mat(data_text(q)));
I = imread(name);
% GLCM features based on test image
T_test_avg = GLCM_image_features(I);
% Classification based on GLCM features
weights_per_class = zeros(24, 1);
for i = 1 : 24
if(T_test_avg(1) >= Tc_boundary(i, 1) && T_test_avg(1) <= Tc_boundary(i, 2))
weights_per_class(i) = weights_per_class(i) + 1;
end
if(T_test_avg(2) >= Th_boundary(i, 1) && T_test_avg(2) <= Th_boundary(i, 2))
weights_per_class(i) = weights_per_class(i) + 1;
end
if(T_test_avg(3) >= Tm_boundary(i, 1) && T_test_avg(3) <= Tm_boundary(i, 2))
weights_per_class(i) = weights_per_class(i) + 1;
end
if(T_test_avg(4) >= Tv_boundary(i, 1) && T_test_avg(4) <= Tv_boundary(i, 2))
weights_per_class(i) = weights_per_class(i) + 1;
end
end
% Test image is assigned to the class with maximum weight
[maximum, class_GLCM] = max(weights_per_class);
class_GLCM = class_GLCM - 1;
if class_GLCM == data_class(q) && maximum > 0
num_correct_GLCM = num_correct_GLCM + 1;
correct_per_class(1, class_GLCM + 1) = correct_per_class(1, class_GLCM+1) + 1;
end
% Classification based on Wavelet features
T_test = Wavelet_image_features(I);
% Distance between wavelet features of the test image and wavelet features calculated on train set
distance = zeros(24,1);
for i = 1 : 24
distance(i) = sum(abs(T_train(i,:) - T_test));
end
% Test image is assigned to the class with minimum distance between wavelet features of the test image and wavelet features calculated on train set
[~, class_Wavelet] = min(distance);
class_Wavelet = class_Wavelet - 1;
outputs(q) = class_Wavelet;
if class_Wavelet == data_class(q)
num_correct_Wavelet = num_correct_Wavelet + 1;
correct_per_class(2, class_Wavelet + 1) = correct_per_class(2, class_Wavelet + 1) + 1;
end
% Sort distance in ascending order
[~, idx] = sort(distance);
% Wavelet top 2 classes
class_Wavelet2 = idx(2) - 1;
% Wavelet top 3 classes
class_Wavelet3 = idx(3) - 1;
if class_Wavelet == data_class(q) || class_Wavelet2 == data_class(q)
num_correct_Wavelet2 = num_correct_Wavelet2 + 1;
end
if class_Wavelet == data_class(q) || class_Wavelet2 == data_class(q) || class_Wavelet3 == data_class(q)
num_correct_Wavelet3 = num_correct_Wavelet3 + 1;
end
% Classification based on combination of GLCM and Wavelet top 2 classes
pom_weight = [weights_per_class(class_Wavelet + 1) weights_per_class(class_Wavelet2 + 1)];
[~, ind] = max(pom_weight);
if ind == 1
class_combo = class_Wavelet;
else
class_combo = class_Wavelet2;
end
if class_combo == data_class(q)
num_correct_combo = num_correct_combo+1;
correct_per_class(3, class_combo+1) = correct_per_class(3, class_combo + 1) + 1;
end
% Classification based on combination of GLCM and Wavelet top 3 classes
pom_weight = [weights_per_class(class_Wavelet + 1) weights_per_class(class_Wavelet2 + 1) weights_per_class(class_Wavelet3 + 1)];
[~, ind] = max(pom_weight);
if ind == 1
class_combo3 = class_Wavelet;
elseif ind == 2
class_combo3 = class_Wavelet2;
else
class_combo3 = class_Wavelet3;
end
if class_combo3 == data_class(q)
num_correct_combo3 = num_correct_combo3 + 1;
correct_per_class(4, class_combo3 + 1) = correct_per_class(4, class_combo3 + 1) + 1;
end
end
correct_per_class = correct_per_class./160.*100; correct_per_class=correct_per_class';
%% Results
percentage_wavelet = num_correct_Wavelet / numel(data_class) * 100;
disp(['Accuracy of the Wavelet algorithm: ' num2str(percentage_wavelet) '%'])
percentage_GLCM = num_correct_GLCM/numel(data_class) * 100;
disp(['Accuracy of the GLCM algorithm: ' num2str(percentage_GLCM) '%'])
percentage = num_correct_Wavelet2 / numel(data_class);
disp(['Accuracy of the Wavelet algorithm for the first two: ' num2str(percentage * 100) '%'])
percentage_combo = num_correct_combo / numel(data_class) * 100;
disp(['Accuracy of the combination of the algorithms (Wavelet 2): ' num2str(percentage_combo) '%'])
percentage = num_correct_Wavelet3 / numel(data_class);
disp(['Accuracy of the Wavelet algorithm for the first three: ' num2str(percentage * 100) '%'])
percentage = num_correct_combo3 / numel(data_class);
disp(['Accuracy of the combination of the algorithms (Wavelet 3): ' num2str(percentage * 100) '%'])
num_correct_GLCM_wavelet_combo = correct_per_class(:, 1 : 3);
Table_GLCM = [Tc_boundary Th_boundary Tm_boundary Tv_boundary];
save('Results.mat','T_train','Table_GLCM','num_correct_GLCM_wavelet_combo',...
'percentage_GLCM','percentage_wavelet','percentage_combo')