Worked example 1
A simple 8x4 pixel monochrome (1-bit colour depth) image is represented by the following binary data, where 1 is black and 0 is white. The data is read row by row.
00000000 01111110 01111110 00000000
Apply Run-Length Encoding to this data. Assume the format is (count, value).
Show solution outline
- Analyse the data stream: First, we read the pixels as a single stream: 00000000011111100111111000000000
- Identify the runs:
- The first run is nine 0s.
- The next run is six 1s.
- The next run is two 0s.
- The next run is six 1s.
- The final run is nine 0s.
- Apply RLE: We represent each run with its count and value.
- (9, 0)
- (6, 1)
- (2, 0)
- (6, 1)
- (9, 0)
- Final Encoded Data: The RLE representation is (9,0)(6,1)(2,0)(6,1)(9,0). The original data required 32 bits (8x4x1). The RLE representation uses 5 pairs of numbers. The exact size would depend on how many bits are used for the count and value, but the number of data items has been reduced from 32 to 10.