互信息,库尔巴克·莱布勒 两个彩色图像之间的分歧



我正在从事一个使用互信息进行图像分类的项目。它要求我使用彩色图像的概率分布,要么我想计算互信息,要么在 Matlab 中计算 Kullback Leibler 散度。谁能帮我解决这个问题? 我计算出彩色图像的熵为:

I = imread('s1.png');
% rgb_columns = reshape(rgb, [], 3);
% %Change RGB matrices to a single matrix of color indices.
% %Removes the third dimension from the pixel intensity matrix.
Color_ind=double(I(:,:,1)).*256^2+double(I(:,:,2).*256)+double(I(:,:,3));      
disp(size(Color_ind));     
% Finding unique elements in the matrix and find their length
unique_ind=unique(Color_ind);
unique_len=length(unique_ind);
%Pre-allocate space for the vector that will hold the number of entries
%for each unique color
color_count_prob=zeros(unique_len,1);
%Count the number of each occurrence of each unique color index in the 
%original matrix.
for i = 1:unique_len
color_count_prob(i)=(length(find(unique_ind(i)==Color_ind)))/(2073600);
end
en_sum=0;
for i = 1:unique_len
en_sum = en_sum + log2(color_count_prob(i));
end
en = -en_sum;

对于彩色图像的 PDF 计算:

首先,您需要将图像转换为灰度。如果您坚持保持RGB模式(或任何其他彩色模式),则必须生成3个PDF(每个颜色通道一个) - 我不建议出于Kullback Liebler或Mutual Information的目的这样做,灰度图像就可以了。

其次,您需要计算每个图像的分布。为此,您需要拼合图像(从 2D 数组转换为 1D 数组)。拼合图像后,应对值进行排序。排序后,您应该规范化它们(您可以选择不这样做,但会推荐)。之后,您可以导出图像的直方图。

要测量 Kullback Liebler 背离度,您需要:

  1. 测量图像直方图上的熵。这将是一个数字。
  2. 只需减去第一步中的值,它就会给你这两个图像的 Kullback Liebler 散度值。

最新更新