-
Notifications
You must be signed in to change notification settings - Fork 3
/
texture_extractor.m
44 lines (39 loc) · 1.01 KB
/
texture_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
function F = texture_extractor(I)
% @param I gray-level image, should be uint8
% @return F feature vector of I
level = graythresh(I);
bw = im2bw(I, level);
% bw = bwareaopen(bw, 50);
glcm = graycomatrix(bw);
glcm = glcm + glcm';
glcm = glcm ./ sum(glcm(:));
% Get row and colum subscripts of GLCM.
s = size(glcm);
[c, r] = meshgrid(1:s(1), 1:s(2));
c = c(:); r = r(:);
% calculate features
F = [];
F(end+1) = calculateHomogeneity(glcm, r, c);
F(end+1) = calculateEnergy(glcm);
F(end+1) = calculateEntropy(glcm);
end
function E = calculateEntropy(glcm)
glcm = glcm(:);
foo = -log(glcm);
foo(foo == Inf) = 0;
E = sum(glcm .* foo);
end
function E = calculateEnergy(glcm)
bar = glcm.^2;
E = sum(bar(:));
end
function H = calculateHomogeneity(glcm, r, c)
term1 = (1 + abs(r-c));
term = glcm(:) ./ term1;
H = sum(term);
end
%% thresholding
%% extract graycomatrix
%% ???憭批?嚗??????唬?銝????%% ?嗅??典???????
%% 憒??????渡??箏?嚗?停銝?????
%% 憒??????典之??????撠梯?蝏抒賒??% ???閬??銋??