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
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 件のコメント
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 Center および File 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!