-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathentropy_and_jointentropy.m
72 lines (62 loc) · 1020 Bytes
/
entropy_and_jointentropy.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
%????????
%??????
A=floor(rand(8,8).*255);
[M,N]=size(A);
temp=zeros(1,256);
%????????[0,255]????
for m=1:M;
for n=1:N;
if A(m,n)==0;
i=1;
else
i=A(m,n);
end
temp(i)=temp(i)+1;
end
end
temp=temp./(M*N);
%????????
result=0;
for i=1:length(temp)
if temp(i)==0;
result=result;
else
result=result-temp(i)*log2(temp(i));
end
end
result
%?????
%??????
A=floor(rand(18,18).*255);
B=floor(rand(18,18).*255);
[M,N]=size(A);
temp=zeros(256,256);
%?????????????
for m=1:M;
for n=1:N;
if A(m,n)==0;
i=1;
else
i=A(m,n);
end
if B(m,n)==0;
j=1;
else
j=B(m,n);
end
temp(i,j)=temp(i,j)+1;
end
end
temp=temp./(M*N);
%????????
result=0;
for i=1:size(temp,1)
for j=1:size(temp,2)
if temp(i,j)==0;
result=result;
else
result=result-temp(i,j)*log2(temp(i,j));
end
end
end
result