-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_data.m
56 lines (50 loc) · 1.99 KB
/
test_data.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
clc;clear;close all;
image_folder = 'TrainingMale';
filenames = dir(fullfile(image_folder, '*.jpg'));
total_images = numel(filenames);
for n = 1:total_images
full_name= fullfile(image_folder, filenames(n).name);
our_images = logical(imread(full_name));
our_images = bwconvhull(our_images,'objects');
stats = regionprops(our_images,'Area','Perimeter','Eccentricity');
area(n) = stats.Area;
perimeter(n) = stats.Perimeter;
metric(n) = 4*pi*area(n)/(perimeter(n).^2);
eccentricity(n) = stats.Eccentricity;
training = [metric;eccentricity]';
group = cell(60,1);
group(1:15,:) = {'tulang'};
group(16:30,:) = {'apel'};
group(31:45,:) = {'gajah'};
group(46:60,:) = {'garpu'};
end
figure,
gscatter(metric',eccentricity',group,'rgbk','.',15)
legend('Tulang pelatihan','Apel pelatihan','Gajah pelatihan','Garpu pelatihan',...
'Location','SouthWest')
grid on
image_folder_uji = 'data uji';
filenames_uji = dir(fullfile(image_folder_uji, '*.jpg'));
total_images_uji = numel(filenames_uji);
for n = 1:total_images_uji
full_name_uji = fullfile(image_folder_uji, filenames_uji(n).name);
our_images_uji = logical(imread(full_name_uji));
our_images_uji = bwconvhull(our_images_uji,'objects');
stats_uji = regionprops(our_images_uji,'Area','Perimeter','Eccentricity');
area_uji(n) = stats_uji.Area;
perimeter_uji(n) = stats_uji.Perimeter;
metric_uji(n) = (4*pi*area_uji(n))./(perimeter_uji(n).^2);
eccentricity_uji(n) = stats_uji.Eccentricity;
sample = [metric_uji;eccentricity_uji]';
end
c = fitcknn(training, group,'NumNeighbors',1,'Standardize',1);
Class = predict(c,sample);
figure,
gscatter(metric',eccentricity',group,'rgbk','.',15)
grid on
hold on
gscatter(metric_uji',eccentricity_uji',Class,[1 1 0; 1 0 1; 0 1 1; .5 .5 .5],'x',15);
legend('Tulang pelatihan','Apel pelatihan','Gajah pelatihan','Garpu pelatihan',...
'Tulang pengujian','Garpu pengujian','Apel pengujian','Gajah pengujian',...
'Location','SouthWest')
hold off