estimation/measure of entropy

How to calculate entropy of an image without using the inbuilt functions? Entropy is the measure of loss of information.
-summation(P.*log2 P)
P is the count of histogram..but not getting the proper result!Anyone plz help.

 Respuesta aceptada

Thorsten
Thorsten el 28 de Nov. de 2014
Editada: Thorsten el 28 de Nov. de 2014

2 votos

Make sure you run log2 only on values > 0. Otherwise you would get NaN.
I = im2double(rgb2gray(imread('peppers.png')));
P = hist(I(:), linspace(0, 1, 256)); P = P(:); P = P(P(:)>0);
E = -sum(P.*log2(P))

4 comentarios

Youssef  Khmou
Youssef Khmou el 28 de Nov. de 2014
a minus sign as remark to the code, this method can be sensitive to the number of bins used in function Hist.
Thorsten
Thorsten el 28 de Nov. de 2014
Editada: Thorsten el 28 de Nov. de 2014
I've added the minus. And, yes, this method is sensitive to the number of bins:
for b = 1:512
P = hist(I(:), linspace(0, 1, b)); P = P(:); P = P(P(:)>0);
E(b) = -sum(P.*log2(P));
end
plot(E)
So use the minimum number of bins where the entropy does not change anymore
Nbins = min(find(diff(E) == 0))
Nbins =
256
I've changed the number of bins in the code above accordingly.
Youssef  Khmou
Youssef Khmou el 29 de Nov. de 2014
that is an efficient technique for controlling the histogram.
Durga
Durga el 13 de En. de 2015
Thanks a lot for helping me to understand.

Iniciar sesión para comentar.

Más respuestas (1)

Behrang Mehrparvar
Behrang Mehrparvar el 10 de Mayo de 2015

0 votos

this link might be useful in setting the bin size [ link ]

Etiquetas

Preguntada:

el 28 de Nov. de 2014

Respondida:

el 10 de Mayo de 2015

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by