Information conveyed by an event is negatively related to its probability.
The probability of a grey level comes from the histogram.
For an image, entropy is the probability-weighted sum of the information carried by each grey level.
- number of grey levels
- number of pixels
- grey level
- number of pixels with grey level
- probability of grey level
is the minimum average number of bits per pixel required to represent the image.
Bounds
- iff a single grey level has
- iff every grey level has
- A grey level with adds nothing, since
Data Redundancy
Information is the meaning conveyed by a message. Data is the container used to store or transmit it.
- Information is not compressible, since its meaning doesn’t change with the medium
- Data is compressible, since data capacity can exceed the information it carries
Image compression exploits 3 types of redundancy.
- Coding redundancy
The coding scheme uses more space than the information requires, e.g. an 8bpp image stored in 16bpp format. - Interpixel redundancy
Pixel values are correlated locally, e.g. a monotonous background or a repeating texture. - Psychovisual redundancy
Image detail that isn’t visually perceivable.
Average Code Length
A code assigns grey level a codeword of bits. With the probability of grey level , the average codeword length and the size of the coded image are:
No code beats the entropy, and the gap is the coding redundancy per pixel.
- codeword length of grey level in bits
- average codeword length in bits per pixel
- size of the coded image in bits
- coding redundancy in bits per pixel
An 8bpp natural binary code has for every , so . Replacing it with a code of average length gives the compression ratio and the relative data redundancy :
The best possible compression ratio from removing coding redundancy alone is .
Worked Examples
3 Grey Levels
An image has 100 pixels across 3 grey levels: white (, ), grey (, ), black (, ). Find its entropy.
Solution Reveal Hide
4x4 Image
Entropy of the following 4x4 image with grey levels 0 to 3.
| Col 1 | Col 2 | Col 3 | Col 4 | |
|---|---|---|---|---|
| Row 1 | 0 | 0 | 1 | 0 |
| Row 2 | 0 | 2 | 0 | 1 |
| Row 3 | 1 | 0 | 0 | 3 |
| Row 4 | 0 | 1 | 2 | 3 |
Solution Reveal Hide
Count the pixels of each grey level, with and :
| Grey level | ||||
|---|---|---|---|---|
| 0 | 8 | 0.5 | 1 | 0.5 |
| 1 | 4 | 0.25 | 2 | 0.5 |
| 2 | 2 | 0.125 | 3 | 0.375 |
| 3 | 2 | 0.125 | 3 | 0.375 |
Sum the last column.
A fixed length code needs 2 bits per pixel, so 32 bits for the image. The gap of bits per pixel is the maximum saving from any encoding.