相互信息,两个彩色图像之间的Kullback Leibler差异

时间:2019-03-30 17:03:48

标签: matlab image-processing entropy probability-density

我正在使用互助信息进行图像分类项目。它需要我使用彩色图像的概率分布,或者我想在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;

1 个答案:

答案 0 :(得分:0)

对于彩色图像的PDF计算:

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

第二,您需要计算每个图像的分布。为此,您将需要展平图像(从2D数组转换为1D数组)。展平图像后,应该对值进行排序。排序后,您应该对其进行标准化(可以选择不进行选择,但建议这样做)。之后,您可以得出图像的直方图。

要测量Kullback Liebler散度,您需要:

  1. 测量图像直方图上的熵。这将是一个数字。
  2. 只需从第一步中减去这些值,就会为您提供这两幅图像的Kullback Liebler散度值。
相关问题