Get confused (twice) with entropy of grayscale image

조회 수: 1 (최근 30일)
pavel
pavel 2013년 9월 9일
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
pavel
pavel 2013년 9월 9일
No more confusion! The answers are in the "entropy" code!

댓글을 달려면 로그인하십시오.

답변 (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