|
a |
|
b/Image features calculation code/Working/haralick/cooccurfeatures.m |
|
|
1 |
function features = cooccurfeatures( I , mask) |
|
|
2 |
%COOCCURFEATURES Calculates Haralick features from co-occurrance matrices |
|
|
3 |
% |
|
|
4 |
% Mike Lam |
|
|
5 |
% 27 June 2006 |
|
|
6 |
% |
|
|
7 |
% Returns a feature vector of Haralick descriptors given a grayscale |
|
|
8 |
% image. This vector is formed by calculating the Haralick descriptors |
|
|
9 |
% for all four directions and several distances. These values are |
|
|
10 |
% then averaged by distance and then direction for the final vector. |
|
|
11 |
|
|
|
12 |
|
|
|
13 |
% parameters |
|
|
14 |
mindist = 1; |
|
|
15 |
maxdist = 1; |
|
|
16 |
%fuck you and your hard-coded size param |
|
|
17 |
ndescriptors = 13; |
|
|
18 |
|
|
|
19 |
% prepare image |
|
|
20 |
if isa(I,'double') ~= 1 |
|
|
21 |
I = double(I); |
|
|
22 |
end |
|
|
23 |
|
|
|
24 |
% calculate [direction x distance x descriptor] matrix |
|
|
25 |
allharalick = zeros(4,maxdist-mindist+1,ndescriptors); |
|
|
26 |
for dir = 0:3 |
|
|
27 |
for dist = mindist:maxdist |
|
|
28 |
ch = cooccur(I,mask,dir*45,dist); |
|
|
29 |
for i = 1:ndescriptors |
|
|
30 |
allharalick(dir+1,dist,i) = ch(i); |
|
|
31 |
end |
|
|
32 |
end |
|
|
33 |
end |
|
|
34 |
|
|
|
35 |
% average values by distance into [direction x descriptor] matrix |
|
|
36 |
average = zeros(4,6); |
|
|
37 |
for dir = 0:3 |
|
|
38 |
for i = 1:ndescriptors |
|
|
39 |
average(dir+1,i) = mean(allharalick(dir+1,:,i)); |
|
|
40 |
end |
|
|
41 |
end |
|
|
42 |
|
|
|
43 |
% take average values by direction for descriptor matrix |
|
|
44 |
features = zeros(1,ndescriptors); |
|
|
45 |
for i = 1:ndescriptors |
|
|
46 |
features(i) = mean(average(:,i)); |
|
|
47 |
end |