The gray levels of an m-bit gray-scale image can be represented as an array a[m] of bits. Images can be stored as collections of binary images called bitplanes.
An alternative approach is to represent the image by an m-bit Gray code. The gray code g[m] can be computed from:
int n = m-1; g[n] = a[n]; while (n--) g[n] = a[n] ^ a[n+1];
The following table enumerates a 4-bit set of gray levels and the corresponding Gray codes. Both decimal (n, k) and base-2 representations are given. Gray codes have the unique feature that successive code words differ in only one bit position.
n binary gray k 0 0000 0000 0 1 0001 0001 1 2 0010 0011 3 3 0011 0010 2 4 0100 0110 6 5 0101 0111 7 6 0110 0101 5 7 0111 0100 4 8 1000 1100 12 9 1001 1101 13 10 1010 1111 15 11 1011 1110 14 12 1100 1010 10 13 1101 1011 11 14 1110 1001 9 15 1111 1000 8
Gray codes are often used in angular encoder wheels, because the one-bit change per transition applies even to the transition from 15 to 0 (wraparound).
Shown below are encoder wheels where bit-planes are encoded in annular rings, The maximum angular frequency of the Gray code is half that of the binary code.
4-bit binary code | 4-bit gray code |
---|---|
listing: 6bit.txt
6-bit binary code | 6-bit gray code |
---|---|
original image
binary-code bitplanes | Gray-code bitplanes | # |
---|---|---|
7 | ||
6 | ||
5 | ||
4 | ||
3 | ||
2 | ||
1 | ||
0 |
Maintained by John Loomis, last updated Feb 15, 1997