对于 A,B 两个不同波段的高光谱图像,a,b 分别表示 A,B 中出现
的灰度级,p(a),p(b)分别代表 A,B 中出现灰度级 a,b 的概率,p(a,b)
代表波段 A,B 同一位置分别出现灰度级 a 和 b 的概率,那么这两个波
段的互信息熵定义为:
%因为原图是 1024*1024,处理起来很费时间,这里截取 100*100.
close all;
clc;
I22=imread('D:\2band.jpg');
I2=I22(1:100,1:100)
subplot(2,2,1)
imshow(I2);
title('Original Image 2band');
subplot(2,2,2);
imhist(I2);
title('Histogram 2band');
[counters2,x2]=imhist(I2);
Q2=[counters2,x2]
ans2=sum(counters2)
P2=counters2/ans2
I33=imread('D:\3band.jpg');
I3=I33(1:100,1:100)
subplot(2,2,3)
imshow(I3);
title('Original Image 3band');
subplot(2,2,4);
imhist(I3);
title('Histogram 3band');
[counters3,x3]=imhist(I3)
Q3=[counters3,x3]
ans3=sum(counters3)
P3=counters3/ans3
P=[P2,P3]
S=[sum(P2),sum(P3)]
A=zeros(256,256);
for m=0:255
for n=0:255
for i=1:size(I2,1)
for j=1:size(I2,2)
if I2(i,j)==m&&I3(i,j)==n
%波段 2 的灰度直方图
%图像 I2 中出现灰度级 a 的概率
%波段 2 的灰度直方图
%图像 I3 中出现灰度级 b 的概率
A(m+1,n+1)=A(m+1,n+1)+1;
end
end
end
end
end
k=size(I2,1)*size(I2,2);
P23=A/k
Q=sum(P23(:))
M=P23.*log2(P23./(P2*P3'));
M(isinf(M))=0;
M(isnan(M))=0;
M
I=sum(M(:))
两幅图像的灰度直方图如下:
%计算在两幅图像同一位置分别出现灰度级 a 和 b 的概率
Original Image 2band
Histogram 2band
Original Image 3band
100
80
60
40
20
0
120
100
80
60
40
20
0
0
50
100
150
200
250
Histogram 3band
0
50
100
150
200
250