-
Notifications
You must be signed in to change notification settings - Fork 5
/
huidugongsheng.m
90 lines (89 loc) · 2.95 KB
/
huidugongsheng.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
rgb=imread('D:\mytest\true1.jpg');
Gray = double(0.3*rgb(:,:,1)+0.59*rgb(:,:,2)+0.11*rgb(:,:,3));
M=128;
N=128;
%--------------------------------------------------------------------------
%2.????????????????????Gray???16?
%--------------------------------------------------------------------------
for i = 1:M
for j = 1:N
for n = 1:256/16
if (n-1)*16<=Gray(i,j)&Gray(i,j)<=(n-1)*16+15
Gray(i,j) = n-1;
end
end
end
end
[L,num]=bwlabel(Gray);
%--------------------------------------------------------------------------
%3.????????P,????1??????0,45,90,135
%--------------------------------------------------------------------------
P = zeros(16,16,4);
for m = 1:16
for n = 1:16
for i = 1:M
for j = 1:N
if j<N&Gray(i,j)==m-1&Gray(i,j+1)==n-1
P(m,n,1) = P(m,n,1)+1;
P(n,m,1) = P(m,n,1);
end
if i>1&j<N&Gray(i,j)==m-1&Gray(i-1,j+1)==n-1
P(m,n,2) = P(m,n,2)+1;
P(n,m,2) = P(m,n,2);
end
if i<M&Gray(i,j)==m-1&Gray(i+1,j)==n-1
P(m,n,3) = P(m,n,3)+1;
P(n,m,3) = P(m,n,3);
end
if i<M&j<N&Gray(i,j)==m-1&Gray(i+1,j+1)==n-1
P(m,n,4) = P(m,n,4)+1;
P(n,m,4) = P(m,n,4);
end
end
end
if m==n
P(m,n,:) = P(m,n,:)*2;
end
end
end
%%---------------------------------------------------------
% ????????
%%---------------------------------------------------------
for n = 1:4
P(:,:,n) = P(:,:,n)/sum(sum(P(:,:,n)));
end
%--------------------------------------------------------------------------
%4.??????????????????4?????
%--------------------------------------------------------------------------
H = zeros(1,4);
I = H;
Ux = H; Uy = H;
deltaX= H; deltaY = H;
C =H;
for n = 1:4
E(n) = sum(sum(P(:,:,n).^2)); %%??
for i = 1:16
for j = 1:16
if P(i,j,n)~=0
H(n) = -P(i,j,n)*log(P(i,j,n))+H(n); %%?
end
I(n) = (i-j)^2*P(i,j,n)+I(n); %%???
Ux(n) = i*P(i,j,n)+Ux(n); %?????x
Uy(n) = j*P(i,j,n)+Uy(n); %?????y
end
end
end
for n = 1:4
for i = 1:16
for j = 1:16
deltaX(n) = (i-Ux(n))^2*P(i,j,n)+deltaX(n); %?????x
deltaY(n) = (j-Uy(n))^2*P(i,j,n)+deltaY(n); %?????y
C(n) = i*j*P(i,j,n)+C(n);
end
end
C(n) = (C(n)-Ux(n)*Uy(n))/deltaX(n)/deltaY(n); %???
end
%--------------------------------------------------------------------------
%???????????????????????8?????
%--------------------------------------------------------------------------
T=[mean(E) sqrt(cov(E)) mean(H) sqrt(cov(H)) mean(I) sqrt(cov(I)) mean(C) sqrt(cov(C))]