이미지 정보 엔트로피 matlab 코드
1397 단어 matlab
function [entr,ind] = entrCompute(InImg,groupNum)
% Output the entropy of InImg
% ========= INPUT ============
% InImg size: cell(numImg * 1); each cell: m * n
% groupNum the number of images in each group
% ========= OUTPUT ===========
% entr entropies of all images
% ind the sort of all entropies
entr = cell(numel(InImg)/groupNum,1); % groupNum entropy
for id = 1 : numel(entr)
for jd = 1 : groupNum
entr{id}(jd) = Imentropy(InImg{(id - 1) * groupNum + jd});
end
end
%
trash = cell(numel(entr),1);
ind = cell(numel(entr),1);
for id = 1 : numel(entr)
[trash{id} ind{id}] = sort(entr{id},'descend');
end
end
function entr = Imentropy(im)
I = roundn(im,-1) ; % n
[C,R] = size(I); %
Img_size = C * R; %
P_N = unique(I);
L = length(P_N);
H_img = 0;
nk = zeros(L,1);
for i = 1 : C
for j = 1 : R
for k = 1 : L
temp = P_N(k,1);
if I(i,j) == temp
nk(k,1) = nk(k,1) + 1;
end
end
end
end
for k = 1 : L
Ps(k) = nk(k)/Img_size; %
if Ps(k)~=0; % 0
H_img = -Ps(k)*log2(Ps(k))+H_img; %
end
end
entr = H_img;
end