【问题标题】:Mutual Information, Kullback Leibler Divergence between two color images互信息,两个彩色图像之间的 Kullback Leibler 分歧
【发布时间】:2019-08-21 08:35:18
【问题描述】:

我正在开展一个使用互信息进行图像分类的项目。它需要我使用彩色图像的概率分布,我想在 Matlab 中计算互信息或 Kullback Leibler Divergence。谁能帮我解决这个问题? 我将彩色图像的熵计算为:

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;

【问题讨论】:

  • 发布一些代码并向我们展示您的尝试。欢迎来到堆栈溢出
  • 我已经完成了图像熵的计算,但我很困惑如何计算互信息和 KL 散度,因为它需要图像的 pdf。如何定义彩色图像的概率分布?
  • 熵 = Sum(pi * log2(pi))。但是您似乎将其计算为 Sum(log2(pi))
  • 如何使用 scipy 在 python 中生成具有最小 KL 散度的概率分布生成器?

标签: matlab image-processing entropy probability-density


【解决方案1】:

对于彩色图像的 PDF 计算:

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

其次,您需要计算每个图像的分布。为此,您需要展平图像(从二维数组转换为一维数组)。展平图像后,您应该对值进行排序。排序后,您应该将它们标准化(您可以选择不这样做,但会推荐)。之后就可以推导出图像的直方图了。

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

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-10-24
    • 2016-05-30
    • 1970-01-01
    • 1970-01-01
    • 2011-06-19
    • 2017-12-18
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多