-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathhlac_main.m
85 lines (74 loc) · 2.11 KB
/
hlac_main.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
%% 2値HLACテストコード
close all;
clc;
img_dog1 = uint8(imread('./img/dog1.png'));
img_dog2 = uint8(imread('./img/dog2.png'));
img_cat = uint8(imread('./img/cat.png'));
img_mer = uint8(imread('./img/merge.png'));
% 2値化する
dog1_bin = rgb2gray(img_dog1) > 127;
dog2_bin = rgb2gray(img_dog2) > 127;
cat_bin = rgb2gray(img_cat) > 127;
mer_bin = rgb2gray(img_mer) > 127;
% フィルタの準備(cell形式)
hlac_filters = { ...
[0 0 0; 0 1 0; 0 0 0], ...
[0 0 0; 0 1 1; 0 0 0], ...
[0 0 1; 0 1 0; 0 0 0], ...
[0 1 0; 0 1 0; 0 0 0], ...
[1 0 0; 0 1 0; 0 0 0], ...
[0 0 0; 1 1 1; 0 0 0], ...
[0 0 1; 0 1 0; 1 0 0], ...
[0 1 0; 0 1 0; 0 1 0], ...
[1 0 0; 0 1 0; 0 0 1], ...
[0 0 1; 1 1 0; 0 0 0], ...
[0 1 0; 0 1 0; 1 0 0], ...
[1 0 0; 0 1 0; 0 1 0], ...
[0 0 0; 1 1 0; 0 0 1], ...
[0 0 0; 0 1 1; 1 0 0], ...
[0 0 1; 0 1 0; 0 1 0], ...
[0 1 0; 0 1 0; 0 0 1], ...
[1 0 0; 0 1 1; 0 0 0], ...
[0 1 0; 1 1 0; 0 0 0], ...
[1 0 0; 0 1 0; 1 0 0], ...
[0 0 0; 1 1 0; 0 1 0], ...
[0 0 0; 0 1 0; 1 0 1], ...
[0 0 0; 0 1 1; 0 1 0], ...
[0 0 1; 0 1 0; 0 0 1], ...
[0 1 0; 0 1 1; 0 0 0], ...
[1 0 1; 0 1 0; 0 0 0] ...
};
%% HLAC特徴量を求める
dog1_hlac = extract_hlac(dog1_bin, hlac_filters);
dog2_hlac = extract_hlac(dog2_bin, hlac_filters);
cat_hlac = extract_hlac(cat_bin, hlac_filters);
dogcat_hlac = extract_hlac(mer_bin, hlac_filters);
% 加法性の確認
dogcat_minus_dog_hlac = dogcat_hlac - dog2_hlac; % 位置不変特徴量なのでdog1_hlacでもdog2_hlacでもよい
x = 1:size(dog1_hlac,2);
tiledlayout(2,4);
nexttile
imshow(img_dog1)
title('dog1');
nexttile
imshow(img_dog2)
title('dog2');
nexttile(5)
imshow(img_cat)
title('cat');
nexttile(6)
imshow(img_mer)
title('dogcat');
nexttile(3,[2 2])
plot( ...
x, dog1_hlac, ...
x, dog2_hlac, 'o',...
x, cat_hlac, ...
x, dogcat_hlac, ...
x, dogcat_minus_dog_hlac,'o' ...
);
legend('dog1 HLAC', ...
'dog2 HLAC', ...
'cat HLAC', ...
'dogcat HLAC', ...
'dogcat minus dog');