How to calculate entropy of byram shannon bigrams

I read the image file into an array like this

A = imread(fileName);

and now I want to calculate the entropy of the shannons. The shannon entropy implementation found in maltab is a byte level entropy analysis that considers a file to be 256 byte levels.

wentropy(x,'shannon')

But I need to do an analysis of the entropy of bigram, which would have to view the file as consisting of 65536 levels. Can anyone suggest me a good method to achieve this.

+2
source share
2 answers

The entropy of a random variable can be calculated using the following formula: enter image description here

Where p(x)is it located Prob(X=x).

n (x1, x2, .... xn) P(X=x) x ( (0 and 65535), . hist

byteLevel = 65536
% count the observations

observationHist = hist(observations, byteLevel);
% convert to a probability
probXVal = observationHist ./ sum(observationHist);  

% compute the entropy
entropy = - sum( probXVal .* log2(probXVal) );

, .

: , wentropy 256- ? ? , Matlab 3 (R, G, B), 8 ( 256 ?).

, [0 256), P(R=r,G=g,B=b) P(X=x) :

data = imageData(:,:,1);
data = data + (imgData(:,:,2) * 256);
data = data + (imgData(:,:,3) * 256 * 256);

, data , .

+5

"65536" "256" .

0

Source: https://habr.com/ru/post/1529253/


All Articles