Entropy

Work in progress. This note is still being written and incomplete.

Information conveyed by an event is negatively related to its probability.

H(E)=log⁡1P(E)=−log⁡P(E)H(E) = \log \frac{1}{P(E)} = -\log P(E)

For an image, entropy is the probability-weighted sum of the information carried by each grey level.

Bave=−∑i=0L−1P(li)log⁡2P(li)B_{ave} = -\sum_{i=0}^{L-1} P(l_i) \log_2 P(l_i)

Here:

  • LL: number of grey levels
  • P(li)P(l_i): probability of grey level lil_i

BaveB_{ave} 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=50r_k = 50, P=0.5P = 0.5), grey (rk=25r_k = 25, P=0.25P = 0.25), black (rk=25r_k = 25, P=0.25P = 0.25).

Btotal=−50log⁡20.5−25log⁡20.25−25log⁡20.25=150 bitsB_{total} = -50\log_2 0.5 - 25\log_2 0.25 - 25\log_2 0.25 = 150 \text{ bits} Bave=1.5 bits per pixelB_{ave} = 1.5 \text{ 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=16N = 16 and P(li)=ri/NP(l_i) = r_i / N:

Grey level lil_irir_iP(li)P(l_i)−log⁡2P(li)-\log_2 P(l_i)−P(li)log⁡2P(li)-P(l_i) \log_2 P(l_i)
080.510.5
140.2520.5
220.12530.375
320.12530.375

Sum the last column.

Bave=0.5+0.5+0.375+0.375=1.75 bits per pixelB_{ave} = 0.5 + 0.5 + 0.375 + 0.375 = 1.75 \text{ bits per pixel} Btotal=1.75×16=28 bitsB_{total} = 1.75 \times 16 = 28 \text{ bits}

A fixed length code needs 2 bits per pixel, so 32 bits for the image. The gap of 2−1.75=0.252 - 1.75 = 0.25 bits per pixel is the maximum saving from any encoding.

Written by September 30, 2026 2 min read
Was this helpful?