Get confused (twice) with entropy of grayscale image

3 visualizaciones (últimos 30 días)
pavel
pavel el 9 de Sept. de 2013
First, the quote from help says: "entropy converts any class other than logical to uint8 for the histogram count calculation"
I did following 2 tests:
1) A = 0:255; % here A is double and
entropy(A) gives 0.0369
2) A = uint8(0:255);
entropy(A) gives 8
It looks like it doesn't convert to uint8.
Second, I tried formula -sum(p.*log2(p))
[p,x] = imhist(A);
And then
-sum(p.*log2(p)) gives 0, which is obvious because histogram of the given A makes 256 bins with 1 in every bin, and log2(1) = 0.
What was wrong in my tests?
Thanks, Pavel
  1 comentario
pavel
pavel el 9 de Sept. de 2013
No more confusion! The answers are in the "entropy" code!

Iniciar sesión para comentar.

Respuestas (1)

Jeff E
Jeff E el 9 de Sept. de 2013
This boils down to the way IMHIST calculates the bins for an image of type double. For some (all?) functions, Matlab assumes pixel values of this type fall within a range of zero to one. IMTOOL, for example, scales its display to this range as a default. IMHIST does the same, as can be seen if you call it directly on your vector A:
A_counts = imhist(A);
you will see that all the pixels fall in the highest bin.
  2 comentarios
pavel
pavel el 9 de Sept. de 2013
It means that the note in the help on "entropy" is wrong, doesn't it?
Jeff E
Jeff E el 9 de Sept. de 2013
I wouldn't say it's wrong, but the conversion they are performing isn't the one you are expecting. For example, look at the result of :
im2double(uint8(0:255));
Again, Matlab assumes an image of type double will fall in the range of zero to one. In this case, given a uint8 image, it essentially performs the conversion:
B_conv = double(B) ./ 255 ;
This remaps the uint8 values of 0-255, into the double range of 0-1.
>> entropy(0:255)
ans =
0.0369
>> entropy(uint8(0:255))
ans =
8
>> entropy(im2double(uint8(0:255)))
ans =
8

Iniciar sesión para comentar.

Categorías

Más información sobre 3-D Volumetric Image Processing en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by