Matlab 互信息,两幅彩色图像之间的Kullback-Leibler散度
我正在做一个利用互信息进行图像分类的项目。它要求我使用彩色图像的概率分布,或者我想计算互信息,或者在Matlab中计算Kullback-Leibler散度。有人能帮我吗? 我计算了彩色图像的熵,如下所示:Matlab 互信息,两幅彩色图像之间的Kullback-Leibler散度,matlab,image-processing,entropy,probability-density,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 dimens
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或互信息的目的这样做,灰度图像就可以了 其次,您需要计算每个图像的分布。为此,需要展平图像(从二维阵列转换为一维阵列)。展平图像后,应对值进行排序。排序后,您应该对它们进行规范化(您可以选择不进行规范化,但建议您这样做)。然后,可以导出图像的直方图 要测量Kullback-Liebler散度,需要:
发布一些代码并向我们展示您的尝试。欢迎使用stack Overflow我已经计算了图像的熵,但是我不知道如何计算互信息和KL散度,因为它需要图像的pdf格式。如何定义彩色图像的概率分布?熵=和(pi*log2(pi))。但您似乎将其计算为Sum(log2(pi)),我如何使用scipy获得python中具有最小KL散度的概率分布的生成器?