-
Notifications
You must be signed in to change notification settings - Fork 3
/
feature_extractor.m
97 lines (87 loc) · 1.74 KB
/
feature_extractor.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
function F = feature_extractor(I)
% This function extracts features from inpute image
% @param I inpute image
% @return F a cell matrix specifying feature vetors for each pixel
F = cell(size(I));
F = append_F(F, double(I));
F = append_F(F, get_pos_X(I));
F = append_F(F, get_pos_Y(I));
%F = append_F(F, get_Partial_X(I));
%F = append_F(F, get_Partial_Y(I));
%F = append_F(F, get_Variance(I));
F = append_F(F, get_Mean(I));
%F = append_F(F, texture_analyser(I));
F = normalize_features(F);
if isempty(F)
warning('No Feature is Extracted');
end
end
function F_ = append_F(F, S)
p = size(F,1);
q = size(F,2);
if iscell(S) == 1
d = max(size(S{1}));
for i = 1:p*q
for j = 1:d
F{i}(end+1) = S{i}(j);
end
end
else
for i = 1:p*q
F{i}(end+1) = S(i);
end
end
F_ = F;
end
function S = get_pos_X(I)
[p q] = size(I);
S = ones(size(I));
for i = 1:p
S(i, :) = i;
end
end
function S = get_pos_Y(I)
[p q] = size(I);
S = ones(size(I));
for i = 1:q
S(:, i) = i;
end
end
function S = get_Partial_Y(I)
[p q] = size(I);
S = zeros(size(I));
for i = 1:p-1
S(i, :) = I(i+1, :) - I(i, :);
end
end
function S = get_Partial_X(I)
[p q] = size(I);
S = zeros(size(I));
for i = 1:q-1
S(:, i) = I(:, i+1) - I(:, i);
end
end
function S = get_Mean(I)
[p q] = size(I);
S = zeros(size(I));
for i = 1:p
for j = 1:q
try
patch = I(i-1:i+1, j-1:j+1);
S(i,j) = mean(patch(:));
catch Error_Msg
S(i,j) = I(i, j); % TODO Find a better way?
end
end
end
end
function S = get_Variance(I)
[p q] = size(I);
S = zeros(size(I));
for i = 2:p-1
for j = 2:q-1
patch = I(i-1:i+1, j-1:j+1);
S(i, j) = var(double(patch(:)));
end
end
end