我正在研究一个使用互信息进行图像分类的项目。它要求我使用彩色图像的概率分布,要么我想计算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 或互信息的目的这样做,灰度图像将做。
其次,您需要计算每个图像的分布。为此,您需要展平图像(从 2D 数组转换为 1D 数组)。拼合图像后,您应该对值进行排序。排序后,您应该对它们进行标准化(您可以选择不这样做,但建议这样做)。之后,您可以导出图像的直方图。
要测量 Kullback Leibler 散度,您需要:
- 测量图像直方图上的熵。这将是一个数字。
- 只需减去第一步中的值,就会得到这两个图像的 Kullback Leibler 散度值。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)