Get confused (twice) with entropy of grayscale image

3 次查看(过去 30 天)
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 个)

Jeff E
Jeff E 2013-9-9
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 个评论
pavel
pavel 2013-9-9
It means that the note in the help on "entropy" is wrong, doesn't it?
Jeff E
Jeff E 2013-9-9
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

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 3-D Volumetric Image Processing 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by