Run-length encoding of a pixel image

Tip: Choose Save as PDF in the print dialog to download. Use A4 paper size.

Run-length encoding of a pixel image

Name:
Date:
Class:

Quick Questions

Shade in the A or B circle for each question.

1. A row reads 0000011100 (0 = white, 1 = black). Which run-length code starts with white?
A 3,5,2
B 5,3,2
2. A row reads 1100000. The code always starts with white. Which code is correct?
A 0,2,5
B 2,5
3. Using white first (0 = white, 1 = black), what row do the counts 4,2,1 rebuild?
A 0000110
B 1111001
4. How are the counts in a run-length code for a pixel row arranged?
A They all count the black pixels only
B They alternate between white runs and black runs
5. An all-black row of 4 pixels (1111) is encoded, starting with white. What is the code?
A 0,4
B 4

Match the Pairs

Draw a line connecting each item on the left to its match on the right.

Left columnRight column
15,3,2 AThe last run of 2 white pixels is missing. Every run must be counted, so it should be 3,2,2.
20,4,2 BThe row starts with black, but the first count always means white pixels. A 0 is needed first, so it should be 0,2,2.
3Encoding a row of 4 white pixels followed by 6 black pixels C001000
4Rebuilding a row from the counts 2,1,3 (white first, then alternating, 0 = white, 1 = black) D4,6
5Row 1100 encoded as 2,2 E5 white pixels, then 3 black, then 2 white: the row 0000011100
6Row 0001100 encoded as 3,2 FThe row starts with black: 0 white pixels, then 4 black, then 2 white (111100)

Definitions

run-length encoding

Fill in the Blanks

Complete each line of code by filling in the missing parts.

1.
Row: 0000011100 Runs: _,3,2
2.
Row: 1110000 Runs: _,3,4
3.
Runs: 2,3,1 Row: 00___0
4.
Row: 00110000 Runs: 2,2,4 Width: _
5.
Runs alternate: white, _____, white

Spot the Error

Shade in the letter of the line that contains an error.

Question 1
A Pixels: 0 = white, 1 = black
B Row: 0000011100
C Runs: 5,2,3
Question 2
A Row: 1110000
B Runs: 3,4
C Rebuild: 1110000
Question 3
A Image row 1: 00111
B Runs: 3,2
C Total pixels: 5
Question 4
A Row: 000110
B Runs: 3,2,2
C Total: 3+2+2 = 7 pixels
Question 5
A Rule: first run is black
B Row: 1100
C Runs: 0,2,2

Answer Key

Run-length encoding of a pixel image
Section A: Quick Questions
Q1
B — 5,3,2
Q2
A — 0,2,5
Q3
A — 0000110
Q4
B — They alternate between white runs and black runs
Q5
A — 0,4
Section B: Match the Pairs
Q1
5,3,2 → 5 white pixels, then 3 black, then 2 white: the row 0000011100
Q2
0,4,2 → The row starts with black: 0 white pixels, then 4 black, then 2 white (111100)
Q3
Encoding a row of 4 white pixels followed by 6 black pixels → 4,6
Q4
Rebuilding a row from the counts 2,1,3 (white first, then alternating, 0 = white, 1 = black) → 001000
Q5
Row 1100 encoded as 2,2 → The row starts with black, but the first count always means white pixels. A 0 is needed first, so it should be 0,2,2.
Q6
Row 0001100 encoded as 3,2 → The last run of 2 white pixels is missing. Every run must be counted, so it should be 3,2,2.
Section C: Definitions
Q1
run-length encoding — Compress a black-and-white image by writing each row as counts of same-coloured pixels in a run, starting with white. Row 00000 111 00 becomes 5,3,2. Counts can rebuild the grid.
Section D: Fill in the Blanks
Q1
Row: 0000011100 Runs: 5,3,2
Q2
Row: 1110000 Runs: 0,3,4
Q3
Runs: 2,3,1 Row: 001110
Q4
Row: 00110000 Runs: 2,2,4 Width: 8
Q5
Runs alternate: white, black, white
Section E: Spot the Error
Q1
C — The row 0000011100 has 5 white, then 3 black, then 2 white pixels. The runs should be 5,3,2, not 5,2,3.
Q2
B — The row starts with black pixels, but the first count always means white. It needs a 0 at the start, so the runs are 0,3,4.
Q3
B — The row has 2 white pixels first, then 3 black pixels. The runs should be 2,3. The counts are in the wrong order.
Q4
A — The runs 3,2,2 add up to 7 pixels, so the row must have 7 pixels. The row should be 0001100. 000110 has only 6 pixels.
Q5
A — The convention is that the first count is always the white run. That is why a row starting with black begins with 0, as in 0,2,2. The rule should say white.