【发布时间】: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