-
Notifications
You must be signed in to change notification settings - Fork 0
/
stattekstur.m
75 lines (61 loc) · 1.44 KB
/
stattekstur.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
function [Stat] = stattekstur(F)
% STATTEKSTUR Memperoleh statistik tekstur.
% Masukan: F = citra berskala keabuan.
% Keluaran: Stat = berisi statistik tekstur
%
% Didasarkan pada Gonzalez, Woods, dan Eddins, 2004
[m, n] = size(F);
% Hitung frekuensi aras keabuan
L = 256;
Frek = zeros(L,1);
F = double(F);
for i = 1 : m
for j = 1 : n
intensitas = F(i,j);
Frek(intensitas+1) = Frek(intensitas+1) + 1;
end
end
% Hitung probabilitas
jum_piksel = m * n;
for i=0 : L-1
Prob(i+1) = Frek(i+1) / jum_piksel;
end
% Hitung mu
mu = 0;
for i=0 : L-1
mu = mu + i * Prob(i+1);
end
% Hitung deviasi standar
varians = 0;
for i=0 : L-1
varians = varians + (i - mu)^2 * Prob(i+1);
end
deviasi = sqrt(varians);
varians_n = varians / (L-1)^2; % Normalisasi
% Hitung skewness
skewness = 0;
for i=0 : L-1
skewness = skewness + (i - mu)^3 * Prob(i+1);
end
skewness = skewness / (L-1)^2;
% Energi (Keseragaman)
energi = 0;
for i=0 : L-1
energi = energi + Prob(i+1)^2;
end
% Entropi
entropi = 0;
for i=0 : L-1
if Prob(i+1) ~= 0
entropi = entropi + Prob(i+1) * log(Prob(i+1));
end
end
entropi = -entropi;
% Hitung R atau Smoothness
smoothness = 1 - 1 / (1 + varians_n);
Stat.mu = mu;
Stat.deviasi = deviasi;
Stat.skewness = skewness;
Stat.energi = energi;
Stat.entropi = entropi;
Stat.smoothness = smoothness;