Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Usage of entropy function

I was trying to find the entropy of a certain probability distribution in MATLAB. For p, I tried doing

E = -sum(p .* log2(p))

and Echeck = entropy(p)

Shouldn't E and Echeck be same?

The matlab help on entropy does say Entropy is defined as -sum(p.*log2(p)) where p contains the histogram counts returned from imhist.But also that entropy converts any class other than logical to uint8 for the histogram count calculation since it is actually trying to calculate the entropy of a grayscale image and hence wants the pixel values to be discrete. So I guess it's incorrect to use this function for my purpose? Is there a good alternative?

like image 382
atlantis Avatar asked Mar 01 '26 20:03

atlantis


1 Answers

I used open entropy to check the code, and there is a line:

if ~islogical(I)
  I = im2uint8(I);
end
p = imhist(I(:));

which mean that the input is converted to uint8, and then the function computes the entropy of the histogram of the input, and not of the input itself.

That explains the difference.

like image 174
Oli Avatar answered Mar 03 '26 08:03

Oli



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!