Information conveyed by an event is negatively related to its probability.
H(E)=logP(E)1=−logP(E)
For an image, entropy is the probability-weighted sum of the information carried by each grey level.
Bave=−i=0∑L−1P(li)log2P(li)
Here:
- L: number of grey levels
- P(li): probability of grey level li
Bave is the minimum average number of bits per pixel required to represent the image.
Example:
An image has 100 pixels across 3 grey levels: white (rk=50, P=0.5), grey (rk=25, P=0.25), black (rk=25, P=0.25).
Btotal=−50log20.5−25log20.25−25log20.25=150 bits
Bave=1.5 bits per pixel
Worked Example
Entropy of the following 4x4 image with grey levels 0 to 3.
0 0 1 0
0 2 0 1
1 0 0 3
0 1 2 3
Count the pixels of each grey level, with N=16 and P(li)=ri/N:
Sum the last column.
Bave=0.5+0.5+0.375+0.375=1.75 bits per pixel
Btotal=1.75×16=28 bits
A fixed length code needs 2 bits per pixel, so 32 bits for the image. The gap of 2−1.75=0.25 bits per pixel is the maximum saving from any encoding.