Run-length encoding of a row of coloured pixels

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

Run-length encoding of a row of coloured pixels

Name:
Date:
Class:

Quick Questions

Shade in the A or B circle for each question.

1. A row of pixels is WWWBB (W = white, B = black). Which is its run-length encoding?
A 3W2B
B W3B2
2. A black and white row is BBBBWWB. Which encoding is correct?
A 4B2W1B
B 5B2W
3. Using the table R = red, G = green, B = blue, how is the row RRRGGB encoded?
A 3R2G1B
B 3R2G
4. How many pixels are in a row encoded as 5W3B?
A 2 pixels, because there are two pairs
B 8 pixels, because 5 + 3 = 8
5. Which row does the encoding 2R4G1R decode to?
A RRRRGGR
B RRGGGGR

Match the Pairs

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

Left columnRight column
13W2B AThe final run of one red pixel is missing, so the row cannot be rebuilt correctly.
24R1G3R BThree white pixels followed by two black pixels along the row (W = white, B = black)
3A black and white row with 5 white pixels then 3 black pixels is stored as one count and colour code per run (W = white, B = black) C3R2G1Y
4Using the table R = red, G = green, Y = yellow, the row RRRGGY is encoded run by run, in order D5W3B
5WWWWBB encoded as 4B2W EThe colour codes are swapped. The four pixels are white, not black, and the two pixels are black, not white.
6RRGGGR encoded as 2R3G FFour red pixels, one green pixel, then three red pixels (R = red, G = green)

Definitions

RLE pixel row

Fill in the Blanks

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

1.
Row: WWWBB RLE: _W2B
2.
Table: R=red, G=green, B=blue Row: RRGGGB RLE: 2R3_1B
3.
Row 1: BBBW RLE: 3B1W Row 2: WWBB RLE: _W2B
4.
Row: BBBBWWB RLE: 4B2W_B
5.
Row: BBWWWWWB RLE: 2B5W1_

Spot the Error

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

Question 1
A Key: W=white, K=black
B Row: W W K K W W W W
C Runs: 3 W, 2 K, 4 W
D RLE: 3W2K4W
Question 2
A Key: R=red, G=green, B=blue
B Row: R R G G G G B
C Runs: 2 R, 3 G, 1 B
D RLE: 2R4G1B
Question 3
A Key: Y=yellow, K=black
B Row: Y Y Y K K Y
C Runs: 3 Y, 2 K, 1 Y
D RLE: Y3K2Y1
Question 4
A Row: R R R G G B
B Key: R=red, G=green, B=blue
C Runs: 4 R, 2 G, 1 B
D RLE: 4R2G1B
Question 5
A Key: W=white, K=black
B Row: K K K W W K
C RLE: 4K2W1K
D Total pixels: 4+2+1 = 7

Answer Key

Run-length encoding of a row of coloured pixels
Section A: Quick Questions
Q1
A — 3W2B
Q2
A — 4B2W1B
Q3
A — 3R2G1B
Q4
B — 8 pixels, because 5 + 3 = 8
Q5
B — RRGGGGR
Section B: Match the Pairs
Q1
3W2B → Three white pixels followed by two black pixels along the row (W = white, B = black)
Q2
4R1G3R → Four red pixels, one green pixel, then three red pixels (R = red, G = green)
Q3
A black and white row with 5 white pixels then 3 black pixels is stored as one count and colour code per run (W = white, B = black) → 5W3B
Q4
Using the table R = red, G = green, Y = yellow, the row RRRGGY is encoded run by run, in order → 3R2G1Y
Q5
WWWWBB encoded as 4B2W → The colour codes are swapped. The four pixels are white, not black, and the two pixels are black, not white.
Q6
RRGGGR encoded as 2R3G → The final run of one red pixel is missing, so the row cannot be rebuilt correctly.
Section C: Definitions
Q1
RLE pixel row — Run-length encoding of a pixel row stores each run of same-coloured pixels as a count then a colour code, in order along the row. E.g. WWWBB becomes 3W2B.
Section D: Fill in the Blanks
Q1
Row: WWWBB RLE: 3W2B
Q2
Table: R=red, G=green, B=blue Row: RRGGGB RLE: 2R3G1B
Q3
Row 1: BBBW RLE: 3B1W Row 2: WWBB RLE: 2W2B
Q4
Row: BBBBWWB RLE: 4B2W1B
Q5
Row: BBWWWWWB RLE: 2B5W1B
Section E: Spot the Error
Q1
B — The row should start with three white pixels (W W W), not two. The runs 3 W, 2 K, 4 W and the code 3W2K4W all match the row W W W K K W W W W.
Q2
C — The row has four green pixels in a row, so the green run count must be 4, not 3. It should read 'Runs: 2 R, 4 G, 1 B'.
Q3
D — Each run is written as the count first, then the colour code. The encoding should be 3Y2K1Y, not colour then count.
Q4
A — The row only has three red pixels here, but the runs and RLE say 4 R. The row should be R R R R G G B to match 4R2G1B.
Q5
B — The row should start with four black pixels and have seven pixels in total. K K K W W K has only 3 black pixels at the start and 6 pixels, so it does not match 4K2W1K.