Sub topic 3
Bit depth: how many values a sample can take
Assume you know basic Python, arrays, bytes, and common image formats. This chapter uses “sample” for one stored channel value at one pixel.
Bit depth is the number of bits used to store each sample. With \(b\) bits, a sample can represent \(2^b\) distinct values. For an unsigned integer sample, these values usually start at zero and end at \(2^b - 1\).
| Bit depth | Possible values | Common use |
|---|---|---|
| 1 bit | 2 | Black-and-white masks |
| 8 bit | 256 | Standard image channels |
| 16 bit | 65,536 | Medical, scientific, and high-dynamic-range data |
| 32-bit float | Many values, including fractions | Processing and neural-network pipelines |
A bit depth applies separately to each channel. An 8-bit RGB image does not have only 256 possible colours. Each pixel has three 8-bit samples, so it has up to \(256^3 = 16,777,216\) channel combinations, before colour-space limits or transparency are considered.
Quantisation and precision
Quantisation maps a continuous or high-precision measurement to one of a finite set of values. Increasing bit depth creates smaller steps between representable values.
For an integer channel with maximum value \(M\), a stored value \(v\) is often normalised as:
v_\text{normalised} = \frac{v}{M}For 8-bit data, black is 0, white is 255, and the step size is \(1/255\). For 16-bit data, the maximum is 65,535 and the steps are much smaller.
More bit depth improves precision, but it does not automatically increase the captured scene brightness range. Dynamic range depends on the sensor, exposure, encoding, and processing pipeline. A 16-bit image can still contain clipped highlights if the camera recorded them as maximum white.
import numpy as np
for bits in (1, 8, 10, 12, 16):
levels = 2 ** bits
maximum = levels - 1
step = 1 / maximum if maximum else 1
print(f"{bits:2} bits: {levels:6} levels, max={maximum:5}, step={step:.6f}")Why quantisation can cause banding
If a smooth gradient has too few levels, neighbouring pixels must share the same stored value. The gradient then appears as visible bands. Dithering adds controlled noise to make those transitions less noticeable, but it does not create new information.
Exercise
How many distinct values can one 10-bit unsigned channel represent, and what is its maximum stored value?
Show answer
It represents 2^10 = 1,024 values, from 0 through 1,023.